Merge Implicit and ImplicitMissing.

This commit is contained in:
Camille GILLOT 2021-11-26 23:07:21 +01:00
parent 72dc29c260
commit aa2450f41b
6 changed files with 19 additions and 36 deletions

View file

@ -1786,7 +1786,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
GenericArg::Lifetime(hir::Lifetime { GenericArg::Lifetime(hir::Lifetime {
hir_id: self.next_id(), hir_id: self.next_id(),
span: self.lower_span(span), span: self.lower_span(span),
name: hir::LifetimeName::Implicit, name: hir::LifetimeName::Implicit(false),
}))); })));
let generic_args = self.arena.alloc_from_iter(generic_args); let generic_args = self.arena.alloc_from_iter(generic_args);
@ -1927,8 +1927,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}); });
let param_name = match lt.name { let param_name = match lt.name {
hir::LifetimeName::Param(param_name) => param_name, hir::LifetimeName::Param(param_name) => param_name,
hir::LifetimeName::Implicit hir::LifetimeName::Implicit(_)
| hir::LifetimeName::ImplicitMissing
| hir::LifetimeName::Underscore | hir::LifetimeName::Underscore
| hir::LifetimeName::Static => hir::ParamName::Plain(lt.name.ident()), | hir::LifetimeName::Static => hir::ParamName::Plain(lt.name.ident()),
hir::LifetimeName::ImplicitObjectLifetimeDefault => { hir::LifetimeName::ImplicitObjectLifetimeDefault => {
@ -2291,7 +2290,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
AnonymousLifetimeMode::ReportError => self.new_error_lifetime(None, span), AnonymousLifetimeMode::ReportError => self.new_error_lifetime(None, span),
AnonymousLifetimeMode::PassThrough => self.new_implicit_lifetime(span), AnonymousLifetimeMode::PassThrough => self.new_implicit_lifetime(span, false),
} }
} }
@ -2344,12 +2343,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// lifetime. Instead, we simply create an implicit lifetime, which will be checked // lifetime. Instead, we simply create an implicit lifetime, which will be checked
// later, at which point a suitable error will be emitted. // later, at which point a suitable error will be emitted.
AnonymousLifetimeMode::PassThrough | AnonymousLifetimeMode::ReportError => { AnonymousLifetimeMode::PassThrough | AnonymousLifetimeMode::ReportError => {
if param_mode == ParamMode::Explicit { self.new_implicit_lifetime(span, param_mode == ParamMode::Explicit)
let id = self.resolver.next_node_id();
self.new_named_lifetime(id, span, hir::LifetimeName::ImplicitMissing)
} else {
self.new_implicit_lifetime(span)
}
} }
} }
} }
@ -2392,11 +2386,11 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
r r
} }
fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime { fn new_implicit_lifetime(&mut self, span: Span, missing: bool) -> hir::Lifetime {
hir::Lifetime { hir::Lifetime {
hir_id: self.next_id(), hir_id: self.next_id(),
span: self.lower_span(span), span: self.lower_span(span),
name: hir::LifetimeName::Implicit, name: hir::LifetimeName::Implicit(missing),
} }
} }
@ -2543,9 +2537,7 @@ fn lifetimes_from_impl_trait_bounds(
fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) { fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) {
let name = match lifetime.name { let name = match lifetime.name {
hir::LifetimeName::Implicit hir::LifetimeName::Implicit(_) | hir::LifetimeName::Underscore => {
| hir::LifetimeName::ImplicitMissing
| hir::LifetimeName::Underscore => {
if self.collect_elided_lifetimes { if self.collect_elided_lifetimes {
// Use `'_` for both implicit and underscore lifetimes in // Use `'_` for both implicit and underscore lifetimes in
// `type Foo<'_> = impl SomeTrait<'_>;`. // `type Foo<'_> = impl SomeTrait<'_>;`.

View file

@ -584,9 +584,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
Some(RegionNameHighlight::MatchedAdtAndSegment(lifetime_span)) Some(RegionNameHighlight::MatchedAdtAndSegment(lifetime_span))
} }
hir::LifetimeName::ImplicitObjectLifetimeDefault hir::LifetimeName::ImplicitObjectLifetimeDefault | hir::LifetimeName::Implicit(_) => {
| hir::LifetimeName::Implicit
| hir::LifetimeName::ImplicitMissing => {
// In this case, the user left off the lifetime; so // In this case, the user left off the lifetime; so
// they wrote something like: // they wrote something like:
// //

View file

@ -92,10 +92,9 @@ pub enum LifetimeName {
Param(ParamName), Param(ParamName),
/// User wrote nothing (e.g., the lifetime in `&u32`). /// User wrote nothing (e.g., the lifetime in `&u32`).
Implicit, ///
/// The bool indicates whether the user should have written something.
/// User wrote nothing, but should have provided something. Implicit(bool),
ImplicitMissing,
/// Implicit lifetime in a context like `dyn Foo`. This is /// Implicit lifetime in a context like `dyn Foo`. This is
/// distinguished from implicit lifetimes elsewhere because the /// distinguished from implicit lifetimes elsewhere because the
@ -125,8 +124,7 @@ impl LifetimeName {
pub fn ident(&self) -> Ident { pub fn ident(&self) -> Ident {
match *self { match *self {
LifetimeName::ImplicitObjectLifetimeDefault LifetimeName::ImplicitObjectLifetimeDefault
| LifetimeName::Implicit | LifetimeName::Implicit(_)
| LifetimeName::ImplicitMissing
| LifetimeName::Error => Ident::empty(), | LifetimeName::Error => Ident::empty(),
LifetimeName::Underscore => Ident::with_dummy_span(kw::UnderscoreLifetime), LifetimeName::Underscore => Ident::with_dummy_span(kw::UnderscoreLifetime),
LifetimeName::Static => Ident::with_dummy_span(kw::StaticLifetime), LifetimeName::Static => Ident::with_dummy_span(kw::StaticLifetime),
@ -137,8 +135,7 @@ impl LifetimeName {
pub fn is_elided(&self) -> bool { pub fn is_elided(&self) -> bool {
match self { match self {
LifetimeName::ImplicitObjectLifetimeDefault LifetimeName::ImplicitObjectLifetimeDefault
| LifetimeName::Implicit | LifetimeName::Implicit(_)
| LifetimeName::ImplicitMissing
| LifetimeName::Underscore => true, | LifetimeName::Underscore => true,
// It might seem surprising that `Fresh(_)` counts as // It might seem surprising that `Fresh(_)` counts as
@ -3303,7 +3300,7 @@ mod size_asserts {
rustc_data_structures::static_assert_size!(super::Expr<'static>, 64); rustc_data_structures::static_assert_size!(super::Expr<'static>, 64);
rustc_data_structures::static_assert_size!(super::Pat<'static>, 88); rustc_data_structures::static_assert_size!(super::Pat<'static>, 88);
rustc_data_structures::static_assert_size!(super::QPath<'static>, 24); rustc_data_structures::static_assert_size!(super::QPath<'static>, 24);
rustc_data_structures::static_assert_size!(super::Ty<'static>, 72); rustc_data_structures::static_assert_size!(super::Ty<'static>, 80);
rustc_data_structures::static_assert_size!(super::Item<'static>, 184); rustc_data_structures::static_assert_size!(super::Item<'static>, 184);
rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 128); rustc_data_structures::static_assert_size!(super::TraitItem<'static>, 128);

View file

@ -545,8 +545,7 @@ pub fn walk_lifetime<'v, V: Visitor<'v>>(visitor: &mut V, lifetime: &'v Lifetime
| LifetimeName::Param(ParamName::Error) | LifetimeName::Param(ParamName::Error)
| LifetimeName::Static | LifetimeName::Static
| LifetimeName::Error | LifetimeName::Error
| LifetimeName::Implicit | LifetimeName::Implicit(_)
| LifetimeName::ImplicitMissing
| LifetimeName::ImplicitObjectLifetimeDefault | LifetimeName::ImplicitObjectLifetimeDefault
| LifetimeName::Underscore => {} | LifetimeName::Underscore => {}
} }

View file

@ -1952,7 +1952,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
crate fn report_elided_lifetime_in_ty(&self, lifetime_refs: &[&hir::Lifetime]) { crate fn report_elided_lifetime_in_ty(&self, lifetime_refs: &[&hir::Lifetime]) {
let Some(missing_lifetime) = lifetime_refs.iter().find(|lt| { let Some(missing_lifetime) = lifetime_refs.iter().find(|lt| {
lt.name == hir::LifetimeName::ImplicitMissing lt.name == hir::LifetimeName::Implicit(true)
}) else { return }; }) else { return };
let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect(); let mut spans: Vec<_> = lifetime_refs.iter().map(|lt| lt.span).collect();
@ -2408,8 +2408,7 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
); );
let is_allowed_lifetime = matches!( let is_allowed_lifetime = matches!(
lifetime_ref.name, lifetime_ref.name,
hir::LifetimeName::Implicit hir::LifetimeName::Implicit(_)
| hir::LifetimeName::ImplicitMissing
| hir::LifetimeName::Static | hir::LifetimeName::Static
| hir::LifetimeName::Underscore | hir::LifetimeName::Underscore
); );

View file

@ -923,7 +923,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
} }
}); });
match lifetime.name { match lifetime.name {
LifetimeName::Implicit | hir::LifetimeName::ImplicitMissing => { LifetimeName::Implicit(_) => {
// For types like `dyn Foo`, we should // For types like `dyn Foo`, we should
// generate a special form of elided. // generate a special form of elided.
span_bug!(ty.span, "object-lifetime-default expected, not implicit",); span_bug!(ty.span, "object-lifetime-default expected, not implicit",);
@ -3282,9 +3282,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
)) ))
.emit(); .emit();
} }
hir::LifetimeName::Param(_) hir::LifetimeName::Param(_) | hir::LifetimeName::Implicit(_) => {
| hir::LifetimeName::Implicit
| hir::LifetimeName::ImplicitMissing => {
self.resolve_lifetime_ref(lt); self.resolve_lifetime_ref(lt);
} }
hir::LifetimeName::ImplicitObjectLifetimeDefault => { hir::LifetimeName::ImplicitObjectLifetimeDefault => {