@@ -699,6 +699,11 @@ 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_not_fake_or`].
706
+ crate_node_id : NodeId ,
702
707
}
703
708
704
709
/// Walks the whole crate in DFS order, visiting each item, resolving names as it goes.
@@ -1317,7 +1322,10 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
1317
1322
}
1318
1323
1319
1324
impl < ' a : ' ast , ' b , ' ast , ' tcx > LateResolutionVisitor < ' a , ' b , ' ast , ' tcx > {
1320
- fn new ( resolver : & ' b mut Resolver < ' a , ' 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 > {
1321
1329
// During late resolution we only track the module component of the parent scope,
1322
1330
// although it may be useful to track other components as well for diagnostics.
1323
1331
let graph_root = resolver. graph_root ;
@@ -1340,6 +1348,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
1340
1348
// errors at module scope should always be reported
1341
1349
in_func_body : false ,
1342
1350
lifetime_uses : Default :: default ( ) ,
1351
+ crate_node_id : krate. id ,
1343
1352
}
1344
1353
}
1345
1354
@@ -2045,23 +2054,22 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
2045
2054
debug_assert_eq ! ( id, missing. id) ;
2046
2055
match res {
2047
2056
LifetimeRes :: Static => {
2048
- // FIXME: ICEs otherwise
2049
- if missing. kind != MissingLifetimeKind :: Ampersand {
2050
- self . r . lint_buffer . buffer_lint (
2051
- lint:: builtin:: ELIDED_NAMED_LIFETIMES ,
2052
- missing. id ,
2053
- missing. span ,
2054
- BuiltinLintDiag :: ElidedIsStatic { elided : missing. span } ,
2055
- ) ;
2056
- }
2057
+ self . r . lint_buffer . buffer_lint (
2058
+ lint:: builtin:: ELIDED_NAMED_LIFETIMES ,
2059
+ missing. id_if_not_fake_or ( self . crate_node_id ) ,
2060
+ missing. span ,
2061
+ BuiltinLintDiag :: ElidedIsStatic { elided : missing. span } ,
2062
+ ) ;
2057
2063
}
2058
2064
LifetimeRes :: Param { param, binder } => {
2059
2065
self . r . lint_buffer . buffer_lint (
2060
2066
lint:: builtin:: ELIDED_NAMED_LIFETIMES ,
2061
- // HACK: we can't use `missing.id` instead of `binder` here,
2062
- // because for `missing.kind == Ampersand` it is a "fake" node that gets overlooked and its lints do not end up emitted.
2063
- // Alternatively, it might be possible to convert `param` to `NodeId` and use that instead.
2064
- binder,
2067
+ // It should be possible to use `self.crate_node_id`
2068
+ // or `param`'s `NodeId` here as a fallback instead of the `binder`,
2069
+ // but `binder` sounds like a more appropriate place than the crate,
2070
+ // and to convert `param` from `LocalDefId` to `NodeId`,
2071
+ // we would have to do some additional work.
2072
+ missing. id_if_not_fake_or ( binder) ,
2065
2073
missing. span ,
2066
2074
BuiltinLintDiag :: ElidedIsParam {
2067
2075
elided : missing. span ,
@@ -4971,7 +4979,7 @@ impl<'ast> Visitor<'ast> for ItemInfoCollector<'_, '_, '_> {
4971
4979
impl < ' a , ' tcx > Resolver < ' a , ' tcx > {
4972
4980
pub ( crate ) fn late_resolve_crate ( & mut self , krate : & Crate ) {
4973
4981
visit:: walk_crate ( & mut ItemInfoCollector { r : self } , krate) ;
4974
- let mut late_resolution_visitor = LateResolutionVisitor :: new ( self ) ;
4982
+ let mut late_resolution_visitor = LateResolutionVisitor :: new ( self , krate ) ;
4975
4983
late_resolution_visitor. resolve_doc_links ( & krate. attrs , MaybeExported :: Ok ( CRATE_NODE_ID ) ) ;
4976
4984
visit:: walk_crate ( & mut late_resolution_visitor, krate) ;
4977
4985
for ( id, span) in late_resolution_visitor. diag_metadata . unused_labels . iter ( ) {
0 commit comments