Do not collect lifetimes with Infer resolution

This commit is contained in:
Santiago Pastorino 2022-08-04 12:40:00 -03:00
parent 45991f9175
commit ece52451f6
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
2 changed files with 21 additions and 14 deletions

View File

@ -5,6 +5,7 @@ use rustc_ast::{
TyKind,
};
use rustc_hir::def::LifetimeRes;
use rustc_middle::span_bug;
use rustc_middle::ty::ResolverAstLowering;
use rustc_span::symbol::{kw, Ident};
use rustc_span::Span;
@ -21,11 +22,26 @@ impl<'ast> LifetimeCollectVisitor<'ast> {
}
fn record_lifetime_use(&mut self, lifetime: Lifetime) {
let res = self.resolver.get_lifetime_res(lifetime.id).unwrap_or(LifetimeRes::Error);
if res.binder().map_or(true, |b| !self.current_binders.contains(&b)) {
if !self.collected_lifetimes.contains(&lifetime) {
self.collected_lifetimes.push(lifetime);
match self.resolver.get_lifetime_res(lifetime.id).unwrap_or(LifetimeRes::Error) {
LifetimeRes::Param { binder, .. } | LifetimeRes::Fresh { binder, .. } => {
if !self.current_binders.contains(&binder) {
if !self.collected_lifetimes.contains(&lifetime) {
self.collected_lifetimes.push(lifetime);
}
}
}
LifetimeRes::Static | LifetimeRes::Error => {
if !self.collected_lifetimes.contains(&lifetime) {
self.collected_lifetimes.push(lifetime);
}
}
LifetimeRes::Infer => {}
res => {
let bug_msg = format!(
"Unexpected lifetime resolution {:?} for {:?} at {:?}",
res, lifetime.ident, lifetime.ident.span
);
span_bug!(lifetime.ident.span, "{}", bug_msg);
}
}
}

View File

@ -747,12 +747,3 @@ pub enum LifetimeRes {
/// HACK: This is used to recover the NodeId of an elided lifetime.
ElidedAnchor { start: NodeId, end: NodeId },
}
impl LifetimeRes {
pub fn binder(&self) -> Option<NodeId> {
match self {
LifetimeRes::Param { binder, .. } | LifetimeRes::Fresh { binder, .. } => Some(*binder),
_ => None,
}
}
}