@@ -610,71 +610,108 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
610
610
}
611
611
612
612
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
+ ) ,
649
620
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
+ ) {
651
633
// FIXME(precise_capturing): Structured suggestion for this would be useful
652
634
tcx. dcx ( ) . emit_err ( errors:: SelfTyNotCaptured {
653
635
trait_span : tcx. def_span ( param. def_id ) ,
654
636
opaque_span : tcx. def_span ( opaque_def_id) ,
655
637
} ) ;
656
638
} else {
657
639
// FIXME(precise_capturing): Structured suggestion for this would be useful
658
- tcx. dcx ( ) . emit_err ( errors:: ParamNotCaptured {
640
+ tcx. dcx ( ) . emit_err ( errors:: ParamNotCapturedForced {
659
641
param_span : tcx. def_span ( param. def_id ) ,
660
642
opaque_span : tcx. def_span ( opaque_def_id) ,
661
643
kind : "type" ,
662
644
} ) ;
663
645
}
664
646
}
665
647
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
+ }
672
664
}
673
665
}
674
666
}
675
667
}
676
668
}
677
669
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
+
678
715
fn is_enum_of_nonnullable_ptr < ' tcx > (
679
716
tcx : TyCtxt < ' tcx > ,
680
717
adt_def : AdtDef < ' tcx > ,
0 commit comments