@@ -189,7 +189,7 @@ impl<'a, R> Rib<'a, R> {
189
189
#[ derive( Copy , Clone , Debug ) ]
190
190
enum LifetimeRibKind {
191
191
/// This rib declares generic parameters.
192
- Generics { parent : NodeId , kind : LifetimeBinderKind } ,
192
+ Generics { parent : NodeId , span : Span , kind : LifetimeBinderKind } ,
193
193
194
194
/// We passed through a `macro_rules!` statement
195
195
MacroDefinition ( DefId ) ,
@@ -228,6 +228,18 @@ enum LifetimeBinderKind {
228
228
}
229
229
230
230
impl LifetimeBinderKind {
231
+ fn descr ( self ) -> & ' static str {
232
+ use LifetimeBinderKind :: * ;
233
+ match self {
234
+ BareFnType => "type" ,
235
+ PolyTrait => "bound" ,
236
+ WhereBound => "bound" ,
237
+ Item => "item" ,
238
+ ImplBlock => "impl block" ,
239
+ Function => "function" ,
240
+ }
241
+ }
242
+
231
243
fn allow_in_band ( self ) -> bool {
232
244
use LifetimeBinderKind :: * ;
233
245
match self {
@@ -570,12 +582,18 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
570
582
self . diagnostic_metadata . current_trait_object = Some ( & bounds[ ..] ) ;
571
583
}
572
584
TyKind :: BareFn ( ref bare_fn) => {
585
+ let span = if let Some ( param) = bare_fn. generic_params . first ( ) {
586
+ param. ident . span
587
+ } else {
588
+ ty. span . shrink_to_lo ( )
589
+ } ;
573
590
self . with_generic_param_rib (
574
591
& bare_fn. generic_params ,
575
592
NormalRibKind ,
576
593
LifetimeRibKind :: Generics {
577
594
parent : ty. id ,
578
595
kind : LifetimeBinderKind :: BareFnType ,
596
+ span,
579
597
} ,
580
598
|this| {
581
599
this. with_lifetime_rib (
@@ -596,12 +614,15 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
596
614
self . diagnostic_metadata . current_trait_object = prev;
597
615
}
598
616
fn visit_poly_trait_ref ( & mut self , tref : & ' ast PolyTraitRef , _: & ' ast TraitBoundModifier ) {
617
+ let span =
618
+ if tref. bound_generic_params . is_empty ( ) { tref. span . shrink_to_lo ( ) } else { tref. span } ;
599
619
self . with_generic_param_rib (
600
620
& tref. bound_generic_params ,
601
621
NormalRibKind ,
602
622
LifetimeRibKind :: Generics {
603
623
parent : tref. trait_ref . ref_id ,
604
624
kind : LifetimeBinderKind :: PolyTrait ,
625
+ span,
605
626
} ,
606
627
|this| {
607
628
this. visit_generic_param_vec ( & tref. bound_generic_params , false ) ;
@@ -625,6 +646,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
625
646
LifetimeRibKind :: Generics {
626
647
parent : foreign_item. id ,
627
648
kind : LifetimeBinderKind :: Item ,
649
+ span : generics. span ,
628
650
} ,
629
651
|this| {
630
652
visit:: walk_foreign_item ( this, foreign_item) ;
@@ -640,6 +662,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
640
662
LifetimeRibKind :: Generics {
641
663
parent : foreign_item. id ,
642
664
kind : LifetimeBinderKind :: Function ,
665
+ span : generics. span ,
643
666
} ,
644
667
|this| {
645
668
visit:: walk_foreign_item ( this, foreign_item) ;
@@ -822,15 +845,26 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> {
822
845
ref bounded_ty,
823
846
ref bounds,
824
847
ref bound_generic_params,
848
+ span : predicate_span,
825
849
..
826
850
} ) = p
827
851
{
852
+ let span = if let Some ( span) =
853
+ bound_generic_params. iter ( ) . rev ( ) . find_map ( |param| match param. kind {
854
+ GenericParamKind :: Lifetime => Some ( param. ident . span ) ,
855
+ _ => None ,
856
+ } ) {
857
+ span. shrink_to_hi ( )
858
+ } else {
859
+ predicate_span. shrink_to_lo ( )
860
+ } ;
828
861
this. with_generic_param_rib (
829
862
& bound_generic_params,
830
863
NormalRibKind ,
831
864
LifetimeRibKind :: Generics {
832
865
parent : bounded_ty. id ,
833
866
kind : LifetimeBinderKind :: WhereBound ,
867
+ span,
834
868
} ,
835
869
|this| {
836
870
this. visit_generic_param_vec ( & bound_generic_params, false ) ;
@@ -1145,6 +1179,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1145
1179
}
1146
1180
}
1147
1181
1182
+ self . emit_undeclared_lifetime_error ( lifetime) ;
1148
1183
self . r . lifetimes_res_map . insert ( lifetime. id , LifetimeRes :: Error ) ;
1149
1184
}
1150
1185
@@ -1385,7 +1420,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1385
1420
this. with_generic_param_rib (
1386
1421
& generics. params ,
1387
1422
ItemRibKind ( HasGenericParams :: Yes ) ,
1388
- LifetimeRibKind :: Generics { parent : item. id , kind : LifetimeBinderKind :: Item } ,
1423
+ LifetimeRibKind :: Generics {
1424
+ parent : item. id ,
1425
+ kind : LifetimeBinderKind :: Item ,
1426
+ span : generics. span ,
1427
+ } ,
1389
1428
|this| {
1390
1429
let item_def_id = this. r . local_def_id ( item. id ) . to_def_id ( ) ;
1391
1430
this. with_self_rib ( Res :: SelfTy ( None , Some ( ( item_def_id, false ) ) ) , |this| {
@@ -1451,7 +1490,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1451
1490
self . with_generic_param_rib (
1452
1491
& generics. params ,
1453
1492
ItemRibKind ( HasGenericParams :: Yes ) ,
1454
- LifetimeRibKind :: Generics { parent : item. id , kind : LifetimeBinderKind :: Item } ,
1493
+ LifetimeRibKind :: Generics {
1494
+ parent : item. id ,
1495
+ kind : LifetimeBinderKind :: Item ,
1496
+ span : generics. span ,
1497
+ } ,
1455
1498
|this| visit:: walk_item ( this, item) ,
1456
1499
) ;
1457
1500
}
@@ -1463,6 +1506,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1463
1506
LifetimeRibKind :: Generics {
1464
1507
parent : item. id ,
1465
1508
kind : LifetimeBinderKind :: Function ,
1509
+ span : generics. span ,
1466
1510
} ,
1467
1511
|this| visit:: walk_item ( this, item) ,
1468
1512
) ;
@@ -1487,7 +1531,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1487
1531
self . with_generic_param_rib (
1488
1532
& generics. params ,
1489
1533
ItemRibKind ( HasGenericParams :: Yes ) ,
1490
- LifetimeRibKind :: Generics { parent : item. id , kind : LifetimeBinderKind :: Item } ,
1534
+ LifetimeRibKind :: Generics {
1535
+ parent : item. id ,
1536
+ kind : LifetimeBinderKind :: Item ,
1537
+ span : generics. span ,
1538
+ } ,
1491
1539
|this| {
1492
1540
let local_def_id = this. r . local_def_id ( item. id ) . to_def_id ( ) ;
1493
1541
this. with_self_rib ( Res :: SelfTy ( Some ( local_def_id) , None ) , |this| {
@@ -1502,7 +1550,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1502
1550
this. with_generic_param_rib (
1503
1551
& generics. params ,
1504
1552
AssocItemRibKind ,
1505
- LifetimeRibKind :: Generics { parent : item. id , kind } ,
1553
+ LifetimeRibKind :: Generics {
1554
+ parent : item. id ,
1555
+ span : generics. span ,
1556
+ kind,
1557
+ } ,
1506
1558
|this| visit:: walk_assoc_item ( this, item, AssocCtxt :: Trait ) ,
1507
1559
) ;
1508
1560
} ;
@@ -1562,7 +1614,11 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1562
1614
self . with_generic_param_rib (
1563
1615
& generics. params ,
1564
1616
ItemRibKind ( HasGenericParams :: Yes ) ,
1565
- LifetimeRibKind :: Generics { parent : item. id , kind : LifetimeBinderKind :: Item } ,
1617
+ LifetimeRibKind :: Generics {
1618
+ parent : item. id ,
1619
+ kind : LifetimeBinderKind :: Item ,
1620
+ span : generics. span ,
1621
+ } ,
1566
1622
|this| {
1567
1623
let local_def_id = this. r . local_def_id ( item. id ) . to_def_id ( ) ;
1568
1624
this. with_self_rib ( Res :: SelfTy ( Some ( local_def_id) , None ) , |this| {
@@ -1878,7 +1934,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1878
1934
// method, it will not be considered an in-band
1879
1935
// lifetime to be added, but rather a reference to a
1880
1936
// parent lifetime.
1881
- self . with_generic_param_rib ( & generics. params , ItemRibKind ( HasGenericParams :: Yes ) , LifetimeRibKind :: Generics { parent : item_id, kind : LifetimeBinderKind :: ImplBlock } , |this| {
1937
+ self . with_generic_param_rib ( & generics. params , ItemRibKind ( HasGenericParams :: Yes ) , LifetimeRibKind :: Generics { span : generics . span , parent : item_id, kind : LifetimeBinderKind :: ImplBlock } , |this| {
1882
1938
// Dummy self type for better errors if `Self` is used in the trait path.
1883
1939
this. with_self_rib ( Res :: SelfTy ( None , None ) , |this| {
1884
1940
// Resolve the trait reference, if necessary.
@@ -1950,7 +2006,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1950
2006
this. with_generic_param_rib (
1951
2007
& generics. params ,
1952
2008
AssocItemRibKind ,
1953
- LifetimeRibKind :: Generics { parent : item. id , kind : LifetimeBinderKind :: Function } ,
2009
+ LifetimeRibKind :: Generics { parent : item. id , span : generics . span , kind : LifetimeBinderKind :: Function } ,
1954
2010
|this| {
1955
2011
// If this is a trait impl, ensure the method
1956
2012
// exists in trait
@@ -1978,7 +2034,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
1978
2034
this. with_generic_param_rib (
1979
2035
& generics. params ,
1980
2036
AssocItemRibKind ,
1981
- LifetimeRibKind :: Generics { parent : item. id , kind : LifetimeBinderKind :: Item } ,
2037
+ LifetimeRibKind :: Generics { parent : item. id , span : generics . span , kind : LifetimeBinderKind :: Item } ,
1982
2038
|this| {
1983
2039
// If this is a trait impl, ensure the type
1984
2040
// exists in trait
0 commit comments