@@ -580,27 +580,34 @@ fn check_opaque_precise_captures<'tcx>(tcx: TyCtxt<'tcx>, opaque_def_id: LocalDe
580
580
581
581
match param. kind {
582
582
ty:: GenericParamDefKind :: Lifetime => {
583
+ let use_span = tcx. def_span ( param. def_id ) ;
584
+ let opaque_span = tcx. def_span ( opaque_def_id) ;
583
585
// Check if the lifetime param was captured but isn't named in the precise captures list.
584
586
if variances[ param. index as usize ] == ty:: Invariant {
585
- let param_span = if let DefKind :: OpaqueTy =
586
- tcx. def_kind ( tcx. parent ( param. def_id ) )
587
+ if let DefKind :: OpaqueTy = tcx. def_kind ( tcx. parent ( param. def_id ) )
587
588
&& let ty:: ReEarlyParam ( ty:: EarlyParamRegion { def_id, .. } )
588
589
| ty:: ReLateParam ( ty:: LateParamRegion {
589
590
bound_region : ty:: BoundRegionKind :: BrNamed ( def_id, _) ,
590
591
..
591
592
} ) = * tcx
592
593
. map_opaque_lifetime_to_parent_lifetime ( param. def_id . expect_local ( ) )
593
594
{
594
- Some ( tcx. def_span ( def_id) )
595
+ tcx. dcx ( ) . emit_err ( errors:: LifetimeNotCaptured {
596
+ opaque_span,
597
+ use_span,
598
+ param_span : tcx. def_span ( def_id) ,
599
+ } ) ;
595
600
} else {
596
- None
597
- } ;
598
- // FIXME(precise_capturing): Structured suggestion for this would be useful
599
- tcx. dcx ( ) . emit_err ( errors:: LifetimeNotCaptured {
600
- use_span : tcx. def_span ( param. def_id ) ,
601
- param_span,
602
- opaque_span : tcx. def_span ( opaque_def_id) ,
603
- } ) ;
601
+ // If the `use_span` is actually just the param itself, then we must
602
+ // have not duplicated the lifetime but captured the original.
603
+ // The "effective" `use_span` will be the span of the opaque itself,
604
+ // and the param span will be the def span of the param.
605
+ tcx. dcx ( ) . emit_err ( errors:: LifetimeNotCaptured {
606
+ opaque_span,
607
+ use_span : opaque_span,
608
+ param_span : use_span,
609
+ } ) ;
610
+ }
604
611
continue ;
605
612
}
606
613
}
0 commit comments