@@ -699,11 +699,6 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
699
699
700
700
/// Count the number of places a lifetime is used.
701
701
lifetime_uses : FxHashMap < LocalDefId , LifetimeUseSet > ,
702
-
703
- /// We need some "real" `NodeId` to emit
704
- /// [`elided_named_lifetimes`](lint::builtin::ELIDED_NAMED_LIFETIMES).
705
- /// See comments in [`MissingLifetime::id_if_exists_in_source_or`].
706
- crate_node_id : NodeId ,
707
702
}
708
703
709
704
/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
@@ -1322,10 +1317,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
1322
1317
}
1323
1318
1324
1319
impl < ' a : ' ast , ' b , ' ast , ' tcx > LateResolutionVisitor < ' a , ' b , ' ast , ' tcx > {
1325
- fn new (
1326
- resolver : & ' b mut Resolver < ' a , ' tcx > ,
1327
- krate : & Crate ,
1328
- ) -> LateResolutionVisitor < ' a , ' b , ' ast , ' tcx > {
1320
+ fn new ( resolver : & ' b mut Resolver < ' a , ' tcx > ) -> LateResolutionVisitor < ' a , ' b , ' ast , ' tcx > {
1329
1321
// During late resolution we only track the module component of the parent scope,
1330
1322
// although it may be useful to track other components as well for diagnostics.
1331
1323
let graph_root = resolver. graph_root ;
@@ -1348,7 +1340,6 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1348
1340
// errors at module scope should always be reported
1349
1341
in_func_body : false ,
1350
1342
lifetime_uses : Default :: default ( ) ,
1351
- crate_node_id : krate. id ,
1352
1343
}
1353
1344
}
1354
1345
@@ -1573,7 +1564,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1573
1564
}
1574
1565
1575
1566
if ident. name == kw:: UnderscoreLifetime {
1576
- return self . resolve_anonymous_lifetime ( lifetime, false ) ;
1567
+ return self . resolve_anonymous_lifetime ( lifetime, lifetime . id , false ) ;
1577
1568
}
1578
1569
1579
1570
let mut lifetime_rib_iter = self . lifetime_ribs . iter ( ) . rev ( ) ;
@@ -1676,13 +1667,23 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1676
1667
}
1677
1668
1678
1669
#[ instrument( level = "debug" , skip( self ) ) ]
1679
- fn resolve_anonymous_lifetime ( & mut self , lifetime : & Lifetime , elided : bool ) {
1670
+ fn resolve_anonymous_lifetime (
1671
+ & mut self ,
1672
+ lifetime : & Lifetime ,
1673
+ id_for_lint : NodeId ,
1674
+ elided : bool ,
1675
+ ) {
1680
1676
debug_assert_eq ! ( lifetime. ident. name, kw:: UnderscoreLifetime ) ;
1681
1677
1682
1678
let kind =
1683
1679
if elided { MissingLifetimeKind :: Ampersand } else { MissingLifetimeKind :: Underscore } ;
1684
- let missing_lifetime =
1685
- MissingLifetime { id : lifetime. id , span : lifetime. ident . span , kind, count : 1 } ;
1680
+ let missing_lifetime = MissingLifetime {
1681
+ id : lifetime. id ,
1682
+ span : lifetime. ident . span ,
1683
+ kind,
1684
+ count : 1 ,
1685
+ id_for_lint,
1686
+ } ;
1686
1687
let elision_candidate = LifetimeElisionCandidate :: Missing ( missing_lifetime) ;
1687
1688
for ( i, rib) in self . lifetime_ribs . iter ( ) . enumerate ( ) . rev ( ) {
1688
1689
debug ! ( ?rib. kind) ;
@@ -1810,7 +1811,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1810
1811
LifetimeRes :: ElidedAnchor { start : id, end : NodeId :: from_u32 ( id. as_u32 ( ) + 1 ) } ,
1811
1812
LifetimeElisionCandidate :: Ignore ,
1812
1813
) ;
1813
- self . resolve_anonymous_lifetime ( & lt, true ) ;
1814
+ self . resolve_anonymous_lifetime ( & lt, anchor_id , true ) ;
1814
1815
}
1815
1816
1816
1817
#[ instrument( level = "debug" , skip( self ) ) ]
@@ -1926,6 +1927,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1926
1927
} ;
1927
1928
let missing_lifetime = MissingLifetime {
1928
1929
id : node_ids. start ,
1930
+ id_for_lint : segment_id,
1929
1931
span : elided_lifetime_span,
1930
1932
kind,
1931
1933
count : expected_lifetimes,
@@ -2051,32 +2053,27 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2051
2053
}
2052
2054
2053
2055
match candidate {
2054
- LifetimeElisionCandidate :: Missing ( missing @ MissingLifetime { span : elided , .. } ) => {
2056
+ LifetimeElisionCandidate :: Missing ( missing @ MissingLifetime { .. } ) => {
2055
2057
debug_assert_eq ! ( id, missing. id) ;
2056
2058
match res {
2057
2059
LifetimeRes :: Static { suppress_elision_warning } => {
2058
2060
if !suppress_elision_warning {
2059
2061
self . r . lint_buffer . buffer_lint (
2060
2062
lint:: builtin:: ELIDED_NAMED_LIFETIMES ,
2061
- missing. id_if_exists_in_source_or ( self . crate_node_id ) ,
2063
+ missing. id_for_lint ,
2062
2064
missing. span ,
2063
- BuiltinLintDiag :: ElidedIsStatic { elided } ,
2065
+ BuiltinLintDiag :: ElidedIsStatic { elided : missing . span } ,
2064
2066
) ;
2065
2067
}
2066
2068
}
2067
- LifetimeRes :: Param { param, binder } => {
2069
+ LifetimeRes :: Param { param, binder : _ } => {
2068
2070
let tcx = self . r . tcx ( ) ;
2069
2071
self . r . lint_buffer . buffer_lint (
2070
2072
lint:: builtin:: ELIDED_NAMED_LIFETIMES ,
2071
- // It should be possible to use `self.crate_node_id`
2072
- // or `param`'s `NodeId` here as a fallback instead of the `binder`,
2073
- // but `binder` sounds like a more appropriate place than the crate,
2074
- // and to convert `param` from `LocalDefId` to `NodeId`,
2075
- // we would have to do some additional work.
2076
- missing. id_if_exists_in_source_or ( binder) ,
2073
+ missing. id_for_lint ,
2077
2074
missing. span ,
2078
2075
BuiltinLintDiag :: ElidedIsParam {
2079
- elided,
2076
+ elided : missing . span ,
2080
2077
param : ( tcx. item_name ( param. into ( ) ) , tcx. source_span ( param) ) ,
2081
2078
} ,
2082
2079
) ;
@@ -4990,7 +4987,7 @@ impl<'ast> Visitor<'ast> for ItemInfoCollector<'_, '_, '_> {
4990
4987
impl < ' a , ' tcx > Resolver < ' a , ' tcx > {
4991
4988
pub ( crate ) fn late_resolve_crate ( & mut self , krate : & Crate ) {
4992
4989
visit:: walk_crate ( & mut ItemInfoCollector { r : self } , krate) ;
4993
- let mut late_resolution_visitor = LateResolutionVisitor :: new ( self , krate ) ;
4990
+ let mut late_resolution_visitor = LateResolutionVisitor :: new ( self ) ;
4994
4991
late_resolution_visitor. resolve_doc_links ( & krate. attrs , MaybeExported :: Ok ( CRATE_NODE_ID ) ) ;
4995
4992
visit:: walk_crate ( & mut late_resolution_visitor, krate) ;
4996
4993
for ( id, span) in late_resolution_visitor. diag_metadata . unused_labels . iter ( ) {
0 commit comments