diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2022-04-18 17:51:39 +0200 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2022-07-20 22:12:12 +0200 |
| commit | bfd0435fd75cb185676ecc9f685e6e61d07c5bf9 (patch) | |
| tree | f5791cf7a21d9dda50e728d3617bf7c2bf15552b /compiler/rustc_resolve/src | |
| parent | a7468c60f8dbf5feb23ad840b174d7e57113a846 (diff) | |
| download | rust-bfd0435fd75cb185676ecc9f685e6e61d07c5bf9.tar.gz rust-bfd0435fd75cb185676ecc9f685e6e61d07c5bf9.zip | |
Introduce AnonymousLifetimeRib::Elided and use it for implied 'static.
Diffstat (limited to 'compiler/rustc_resolve/src')
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 49761023ec3..3ee155483cc 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -259,6 +259,9 @@ enum LifetimeRibKind { /// Pass responsibility to `resolve_lifetime` code for all cases. AnonymousPassThrough(NodeId, /* in_fn_return */ bool), + + /// Replace all anonymous lifetimes by provided lifetime. + Elided(LifetimeRes), } #[derive(Copy, Clone, Debug)] @@ -580,7 +583,9 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { fn visit_anon_const(&mut self, constant: &'ast AnonConst) { // We deal with repeat expressions explicitly in `resolve_expr`. self.with_lifetime_rib(LifetimeRibKind::AnonConst, |this| { - this.resolve_anon_const(constant, IsRepeatExpr::No); + this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| { + this.resolve_anon_const(constant, IsRepeatExpr::No); + }) }) } fn visit_expr(&mut self, expr: &'ast Expr) { @@ -1052,6 +1057,7 @@ impl<'a: 'ast, 'ast> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast> { LifetimeRibKind::AnonymousPassThrough(..) | LifetimeRibKind::AnonymousCreateParameter { .. } | LifetimeRibKind::AnonymousReportError + | LifetimeRibKind::Elided(_) | LifetimeRibKind::AnonConst | LifetimeRibKind::ConstGeneric => {} } @@ -1408,6 +1414,13 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { | LifetimeRibKind::AnonymousCreateParameter { .. } => { Some(LifetimeUseSet::One { use_span: ident.span, use_ctxt }) } + // Only report if eliding the lifetime would have the same + // semantics. + LifetimeRibKind::Elided(r) => Some(if res == r { + LifetimeUseSet::One { use_span: ident.span, use_ctxt } + } else { + LifetimeUseSet::Many + }), LifetimeRibKind::Generics { .. } | LifetimeRibKind::ConstGeneric | LifetimeRibKind::AnonConst => None, @@ -1496,6 +1509,10 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { ); return; } + LifetimeRibKind::Elided(res) => { + self.record_lifetime_res(lifetime.id, res); + return; + } LifetimeRibKind::Item => break, LifetimeRibKind::Generics { .. } | LifetimeRibKind::ConstGeneric @@ -1632,6 +1649,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { break; } LifetimeRibKind::AnonymousCreateParameter { .. } + | LifetimeRibKind::Elided(_) | LifetimeRibKind::Generics { .. } | LifetimeRibKind::ConstGeneric | LifetimeRibKind::AnonConst => {} @@ -1690,6 +1708,12 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { } break; } + LifetimeRibKind::Elided(res) => { + for id in node_ids { + self.record_lifetime_res(id, res); + } + break; + } // `LifetimeRes::Error`, which would usually be used in the case of // `ReportError`, is unsuitable here, as we don't emit an error yet. Instead, // we simply resolve to an implicit lifetime, which will be checked later, at @@ -3581,7 +3605,9 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> { ExprKind::Repeat(ref elem, ref ct) => { self.visit_expr(elem); self.with_lifetime_rib(LifetimeRibKind::AnonConst, |this| { - this.resolve_anon_const(ct, IsRepeatExpr::Yes) + this.with_lifetime_rib(LifetimeRibKind::Elided(LifetimeRes::Static), |this| { + this.resolve_anon_const(ct, IsRepeatExpr::Yes) + }) }); } ExprKind::ConstBlock(ref ct) => { |
