Skip to content

Commit ece5245

Browse files
committed
Do not collect lifetimes with Infer resolution
1 parent 45991f9 commit ece5245

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed

compiler/rustc_ast_lowering/src/lifetime_collector.rs

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_ast::{
55
TyKind,
66
};
77
use rustc_hir::def::LifetimeRes;
8+
use rustc_middle::span_bug;
89
use rustc_middle::ty::ResolverAstLowering;
910
use rustc_span::symbol::{kw, Ident};
1011
use rustc_span::Span;
@@ -21,11 +22,26 @@ impl<'ast> LifetimeCollectVisitor<'ast> {
2122
}
2223

2324
fn record_lifetime_use(&mut self, lifetime: Lifetime) {
24-
let res = self.resolver.get_lifetime_res(lifetime.id).unwrap_or(LifetimeRes::Error);
25-
26-
if res.binder().map_or(true, |b| !self.current_binders.contains(&b)) {
27-
if !self.collected_lifetimes.contains(&lifetime) {
28-
self.collected_lifetimes.push(lifetime);
25+
match self.resolver.get_lifetime_res(lifetime.id).unwrap_or(LifetimeRes::Error) {
26+
LifetimeRes::Param { binder, .. } | LifetimeRes::Fresh { binder, .. } => {
27+
if !self.current_binders.contains(&binder) {
28+
if !self.collected_lifetimes.contains(&lifetime) {
29+
self.collected_lifetimes.push(lifetime);
30+
}
31+
}
32+
}
33+
LifetimeRes::Static | LifetimeRes::Error => {
34+
if !self.collected_lifetimes.contains(&lifetime) {
35+
self.collected_lifetimes.push(lifetime);
36+
}
37+
}
38+
LifetimeRes::Infer => {}
39+
res => {
40+
let bug_msg = format!(
41+
"Unexpected lifetime resolution {:?} for {:?} at {:?}",
42+
res, lifetime.ident, lifetime.ident.span
43+
);
44+
span_bug!(lifetime.ident.span, "{}", bug_msg);
2945
}
3046
}
3147
}

compiler/rustc_hir/src/def.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -747,12 +747,3 @@ pub enum LifetimeRes {
747747
/// HACK: This is used to recover the NodeId of an elided lifetime.
748748
ElidedAnchor { start: NodeId, end: NodeId },
749749
}
750-
751-
impl LifetimeRes {
752-
pub fn binder(&self) -> Option<NodeId> {
753-
match self {
754-
LifetimeRes::Param { binder, .. } | LifetimeRes::Fresh { binder, .. } => Some(*binder),
755-
_ => None,
756-
}
757-
}
758-
}

0 commit comments

Comments
 (0)