@@ -699,11 +699,6 @@ struct LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
699699
700700 /// Count the number of places a lifetime is used.
701701 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 ,
707702}
708703
709704/// 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,
13221317}
13231318
13241319impl < ' 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 > {
13291321 // During late resolution we only track the module component of the parent scope,
13301322 // although it may be useful to track other components as well for diagnostics.
13311323 let graph_root = resolver. graph_root ;
@@ -1348,7 +1340,6 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
13481340 // errors at module scope should always be reported
13491341 in_func_body : false ,
13501342 lifetime_uses : Default :: default ( ) ,
1351- crate_node_id : krate. id ,
13521343 }
13531344 }
13541345
@@ -1573,7 +1564,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
15731564 }
15741565
15751566 if ident. name == kw:: UnderscoreLifetime {
1576- return self . resolve_anonymous_lifetime ( lifetime, false ) ;
1567+ return self . resolve_anonymous_lifetime ( lifetime, lifetime . id , false ) ;
15771568 }
15781569
15791570 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> {
16761667 }
16771668
16781669 #[ 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+ ) {
16801676 debug_assert_eq ! ( lifetime. ident. name, kw:: UnderscoreLifetime ) ;
16811677
16821678 let kind =
16831679 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+ } ;
16861687 let elision_candidate = LifetimeElisionCandidate :: Missing ( missing_lifetime) ;
16871688 for ( i, rib) in self . lifetime_ribs . iter ( ) . enumerate ( ) . rev ( ) {
16881689 debug ! ( ?rib. kind) ;
@@ -1810,7 +1811,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
18101811 LifetimeRes :: ElidedAnchor { start : id, end : NodeId :: from_u32 ( id. as_u32 ( ) + 1 ) } ,
18111812 LifetimeElisionCandidate :: Ignore ,
18121813 ) ;
1813- self . resolve_anonymous_lifetime ( & lt, true ) ;
1814+ self . resolve_anonymous_lifetime ( & lt, anchor_id , true ) ;
18141815 }
18151816
18161817 #[ instrument( level = "debug" , skip( self ) ) ]
@@ -1926,6 +1927,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
19261927 } ;
19271928 let missing_lifetime = MissingLifetime {
19281929 id : node_ids. start ,
1930+ id_for_lint : segment_id,
19291931 span : elided_lifetime_span,
19301932 kind,
19311933 count : expected_lifetimes,
@@ -2051,32 +2053,27 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
20512053 }
20522054
20532055 match candidate {
2054- LifetimeElisionCandidate :: Missing ( missing @ MissingLifetime { span : elided , .. } ) => {
2056+ LifetimeElisionCandidate :: Missing ( missing @ MissingLifetime { .. } ) => {
20552057 debug_assert_eq ! ( id, missing. id) ;
20562058 match res {
20572059 LifetimeRes :: Static { suppress_elision_warning } => {
20582060 if !suppress_elision_warning {
20592061 self . r . lint_buffer . buffer_lint (
20602062 lint:: builtin:: ELIDED_NAMED_LIFETIMES ,
2061- missing. id_if_exists_in_source_or ( self . crate_node_id ) ,
2063+ missing. id_for_lint ,
20622064 missing. span ,
2063- BuiltinLintDiag :: ElidedIsStatic { elided } ,
2065+ BuiltinLintDiag :: ElidedIsStatic { elided : missing . span } ,
20642066 ) ;
20652067 }
20662068 }
2067- LifetimeRes :: Param { param, binder } => {
2069+ LifetimeRes :: Param { param, binder : _ } => {
20682070 let tcx = self . r . tcx ( ) ;
20692071 self . r . lint_buffer . buffer_lint (
20702072 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 ,
20772074 missing. span ,
20782075 BuiltinLintDiag :: ElidedIsParam {
2079- elided,
2076+ elided : missing . span ,
20802077 param : ( tcx. item_name ( param. into ( ) ) , tcx. source_span ( param) ) ,
20812078 } ,
20822079 ) ;
@@ -4990,7 +4987,7 @@ impl<'ast> Visitor<'ast> for ItemInfoCollector<'_, '_, '_> {
49904987impl < ' a , ' tcx > Resolver < ' a , ' tcx > {
49914988 pub ( crate ) fn late_resolve_crate ( & mut self , krate : & Crate ) {
49924989 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 ) ;
49944991 late_resolution_visitor. resolve_doc_links ( & krate. attrs , MaybeExported :: Ok ( CRATE_NODE_ID ) ) ;
49954992 visit:: walk_crate ( & mut late_resolution_visitor, krate) ;
49964993 for ( id, span) in late_resolution_visitor. diag_metadata . unused_labels . iter ( ) {
0 commit comments