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