@@ -610,71 +610,108 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
610610 }
611611
612612 match param. kind {
613- ty:: GenericParamDefKind :: Lifetime => {
614- let use_span = tcx. def_span ( param. def_id ) ;
615- let opaque_span = tcx. def_span ( opaque_def_id) ;
616- // Check if the lifetime param was captured but isn't named in the precise captures list.
617- if variances[ param. index as usize ] == ty:: Invariant {
618- if let DefKind :: OpaqueTy = tcx. def_kind ( tcx. parent ( param. def_id ) )
619- && let Some ( def_id) = tcx
620- . map_opaque_lifetime_to_parent_lifetime ( param. def_id . expect_local ( ) )
621- . opt_param_def_id ( tcx, tcx. parent ( opaque_def_id. to_def_id ( ) ) )
622- {
623- tcx. dcx ( ) . emit_err ( errors:: LifetimeNotCaptured {
624- opaque_span,
625- use_span,
626- param_span : tcx. def_span ( def_id) ,
627- } ) ;
628- } else {
629- if tcx. def_kind ( tcx. parent ( param. def_id ) ) == DefKind :: Trait {
630- tcx. dcx ( ) . emit_err ( errors:: LifetimeImplicitlyCaptured {
631- opaque_span,
632- param_span : tcx. def_span ( param. def_id ) ,
633- } ) ;
634- } else {
635- // If the `use_span` is actually just the param itself, then we must
636- // have not duplicated the lifetime but captured the original.
637- // The "effective" `use_span` will be the span of the opaque itself,
638- // and the param span will be the def span of the param.
639- tcx. dcx ( ) . emit_err ( errors:: LifetimeNotCaptured {
640- opaque_span,
641- use_span : opaque_span,
642- param_span : use_span,
643- } ) ;
644- }
645- }
646- continue ;
647- }
648- }
613+ ty:: GenericParamDefKind :: Lifetime => check_captured_arg_is_mentioned (
614+ tcx,
615+ opaque_def_id,
616+ variances,
617+ param,
618+ "lifetime" ,
619+ ) ,
649620 ty:: GenericParamDefKind :: Type { .. } => {
650- if matches ! ( tcx. def_kind( param. def_id) , DefKind :: Trait | DefKind :: TraitAlias ) {
621+ if tcx. features ( ) . precise_capturing_of_types ( ) {
622+ check_captured_arg_is_mentioned (
623+ tcx,
624+ opaque_def_id,
625+ variances,
626+ param,
627+ "type" ,
628+ )
629+ } else if matches ! (
630+ tcx. def_kind( param. def_id) ,
631+ DefKind :: Trait | DefKind :: TraitAlias
632+ ) {
651633 // FIXME(precise_capturing): Structured suggestion for this would be useful
652634 tcx. dcx ( ) . emit_err ( errors:: SelfTyNotCaptured {
653635 trait_span : tcx. def_span ( param. def_id ) ,
654636 opaque_span : tcx. def_span ( opaque_def_id) ,
655637 } ) ;
656638 } else {
657639 // FIXME(precise_capturing): Structured suggestion for this would be useful
658- tcx. dcx ( ) . emit_err ( errors:: ParamNotCaptured {
640+ tcx. dcx ( ) . emit_err ( errors:: ParamNotCapturedForced {
659641 param_span : tcx. def_span ( param. def_id ) ,
660642 opaque_span : tcx. def_span ( opaque_def_id) ,
661643 kind : "type" ,
662644 } ) ;
663645 }
664646 }
665647 ty:: GenericParamDefKind :: Const { .. } => {
666- // FIXME(precise_capturing): Structured suggestion for this would be useful
667- tcx. dcx ( ) . emit_err ( errors:: ParamNotCaptured {
668- param_span : tcx. def_span ( param. def_id ) ,
669- opaque_span : tcx. def_span ( opaque_def_id) ,
670- kind : "const" ,
671- } ) ;
648+ if tcx. features ( ) . precise_capturing_of_types ( ) {
649+ check_captured_arg_is_mentioned (
650+ tcx,
651+ opaque_def_id,
652+ variances,
653+ param,
654+ "const" ,
655+ )
656+ } else {
657+ // FIXME(precise_capturing): Structured suggestion for this would be useful
658+ tcx. dcx ( ) . emit_err ( errors:: ParamNotCapturedForced {
659+ param_span : tcx. def_span ( param. def_id ) ,
660+ opaque_span : tcx. def_span ( opaque_def_id) ,
661+ kind : "const" ,
662+ } ) ;
663+ }
672664 }
673665 }
674666 }
675667 }
676668}
677669
670+ fn check_captured_arg_is_mentioned < ' tcx > (
671+ tcx : TyCtxt < ' tcx > ,
672+ opaque_def_id : LocalDefId ,
673+ variances : & [ ty:: Variance ] ,
674+ param : & ty:: GenericParamDef ,
675+ kind : & ' static str ,
676+ ) {
677+ let use_span = tcx. def_span ( param. def_id ) ;
678+ let opaque_span = tcx. def_span ( opaque_def_id) ;
679+ // Check if the lifetime param was captured but isn't named in the precise captures list.
680+ if variances[ param. index as usize ] == ty:: Invariant {
681+ if let DefKind :: OpaqueTy = tcx. def_kind ( tcx. parent ( param. def_id ) )
682+ && let Some ( def_id) = tcx
683+ . map_opaque_lifetime_to_parent_lifetime ( param. def_id . expect_local ( ) )
684+ . opt_param_def_id ( tcx, tcx. parent ( opaque_def_id. to_def_id ( ) ) )
685+ {
686+ tcx. dcx ( ) . emit_err ( errors:: ParamNotCaptured {
687+ opaque_span,
688+ use_span,
689+ param_span : tcx. def_span ( def_id) ,
690+ kind,
691+ } ) ;
692+ } else {
693+ if tcx. def_kind ( tcx. parent ( param. def_id ) ) == DefKind :: Trait {
694+ tcx. dcx ( ) . emit_err ( errors:: ParamImplicitlyCaptured {
695+ opaque_span,
696+ param_span : tcx. def_span ( param. def_id ) ,
697+ kind,
698+ } ) ;
699+ } else {
700+ // If the `use_span` is actually just the param itself, then we must
701+ // have not duplicated the lifetime but captured the original.
702+ // The "effective" `use_span` will be the span of the opaque itself,
703+ // and the param span will be the def span of the param.
704+ tcx. dcx ( ) . emit_err ( errors:: ParamNotCaptured {
705+ opaque_span,
706+ use_span : opaque_span,
707+ param_span : use_span,
708+ kind,
709+ } ) ;
710+ }
711+ }
712+ }
713+ }
714+
678715fn is_enum_of_nonnullable_ptr < ' tcx > (
679716 tcx : TyCtxt < ' tcx > ,
680717 adt_def : AdtDef < ' tcx > ,
0 commit comments