about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorMichael Goulet <michael@errs.io>2022-02-09 18:42:32 -0800
committerMichael Goulet <michael@errs.io>2022-02-24 18:50:33 -0800
commitbb548a918adc8a4cf63320d3f8b9f1d2ff2622ea (patch)
treebbba240088f42c91fdd598b607655e2f2dc7db54 /compiler
parent4e82f35492ea5c78e19609bf4468f0a686d9a756 (diff)
downloadrust-bb548a918adc8a4cf63320d3f8b9f1d2ff2622ea.tar.gz
rust-bb548a918adc8a4cf63320d3f8b9f1d2ff2622ea.zip
Remove in-band lifetimes
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_ast_lowering/src/lib.rs57
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0687.md4
-rw-r--r--compiler/rustc_error_codes/src/error_codes/E0688.md4
-rw-r--r--compiler/rustc_feature/src/active.rs2
-rw-r--r--compiler/rustc_feature/src/removed.rs3
-rw-r--r--compiler/rustc_hir/src/hir.rs5
-rw-r--r--compiler/rustc_middle/src/middle/resolve_lifetime.rs3
-rw-r--r--compiler/rustc_resolve/src/late/diagnostics.rs11
-rw-r--r--compiler/rustc_resolve/src/late/lifetimes.rs70
9 files changed, 23 insertions, 136 deletions
diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs
index 0156c5016ac..abe086affda 100644
--- a/compiler/rustc_ast_lowering/src/lib.rs
+++ b/compiler/rustc_ast_lowering/src/lib.rs
@@ -142,13 +142,9 @@ struct LoweringContext<'a, 'hir: 'a> {
     /// indicate whether or not we're in a place where new lifetimes will result
     /// in in-band lifetime definitions, such a function or an impl header,
     /// including implicit lifetimes from `impl_header_lifetime_elision`.
-    is_collecting_in_band_lifetimes: bool,
+    is_collecting_anonymous_lifetimes: bool,
 
     /// Currently in-scope lifetimes defined in impl headers, fn headers, or HRTB.
-    /// When `is_collecting_in_band_lifetimes` is true, each lifetime is checked
-    /// against this list to see if it is already in-scope, or if a definition
-    /// needs to be created for it.
-    ///
     /// We always store a `normalize_to_macros_2_0()` version of the param-name in this
     /// vector.
     in_scope_lifetimes: Vec<ParamName>,
@@ -379,7 +375,7 @@ pub fn lower_crate<'a, 'hir>(
         task_context: None,
         current_item: None,
         lifetimes_to_define: Vec::new(),
-        is_collecting_in_band_lifetimes: false,
+        is_collecting_anonymous_lifetimes: false,
         in_scope_lifetimes: Vec::new(),
         allow_try_trait: Some([sym::try_trait_v2][..].into()),
         allow_gen_future: Some([sym::gen_future][..].into()),
@@ -726,13 +722,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
         &mut self,
         f: impl FnOnce(&mut Self) -> T,
     ) -> (Vec<(Span, ParamName)>, T) {
-        let was_collecting = std::mem::replace(&mut self.is_collecting_in_band_lifetimes, true);
+        let was_collecting = std::mem::replace(&mut self.is_collecting_anonymous_lifetimes, true);
         let len = self.lifetimes_to_define.len();
 
         let res = f(self);
 
         let lifetimes_to_define = self.lifetimes_to_define.split_off(len);
-        self.is_collecting_in_band_lifetimes = was_collecting;
+        self.is_collecting_anonymous_lifetimes = was_collecting;
         (lifetimes_to_define, res)
     }
 
@@ -749,7 +745,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
         // that collisions are ok here and this shouldn't
         // really show up for end-user.
         let (str_name, kind) = match hir_name {
-            ParamName::Plain(ident) => (ident.name, hir::LifetimeParamKind::InBand),
+            ParamName::Plain(ident) => (ident.name, hir::LifetimeParamKind::Explicit),
             ParamName::Fresh(_) => (kw::UnderscoreLifetime, hir::LifetimeParamKind::Elided),
             ParamName::Error => (kw::UnderscoreLifetime, hir::LifetimeParamKind::Error),
         };
@@ -773,38 +769,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
         }
     }
 
-    /// When there is a reference to some lifetime `'a`, and in-band
-    /// lifetimes are enabled, then we want to push that lifetime into
-    /// the vector of names to define later. In that case, it will get
-    /// added to the appropriate generics.
-    fn maybe_collect_in_band_lifetime(&mut self, ident: Ident) {
-        if !self.is_collecting_in_band_lifetimes {
-            return;
-        }
-
-        if !self.sess.features_untracked().in_band_lifetimes {
-            return;
-        }
-
-        if self.in_scope_lifetimes.contains(&ParamName::Plain(ident.normalize_to_macros_2_0())) {
-            return;
-        }
-
-        let hir_name = ParamName::Plain(ident);
-
-        if self.lifetimes_to_define.iter().any(|(_, lt_name)| {
-            lt_name.normalize_to_macros_2_0() == hir_name.normalize_to_macros_2_0()
-        }) {
-            return;
-        }
-
-        self.lifetimes_to_define.push((ident.span, hir_name));
-    }
-
     /// When we have either an elided or `'_` lifetime in an impl
     /// header, we convert it to an in-band lifetime.
-    fn collect_fresh_in_band_lifetime(&mut self, span: Span) -> ParamName {
-        assert!(self.is_collecting_in_band_lifetimes);
+    fn collect_fresh_anonymous_lifetime(&mut self, span: Span) -> ParamName {
+        assert!(self.is_collecting_anonymous_lifetimes);
         let index = self.lifetimes_to_define.len() + self.in_scope_lifetimes.len();
         let hir_name = ParamName::Fresh(index);
         self.lifetimes_to_define.push((span, hir_name));
@@ -1946,7 +1914,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
             }
             ident if ident.name == kw::UnderscoreLifetime => match self.anonymous_lifetime_mode {
                 AnonymousLifetimeMode::CreateParameter => {
-                    let fresh_name = self.collect_fresh_in_band_lifetime(span);
+                    let fresh_name = self.collect_fresh_anonymous_lifetime(span);
                     self.new_named_lifetime(l.id, span, hir::LifetimeName::Param(fresh_name))
                 }
 
@@ -1957,7 +1925,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                 AnonymousLifetimeMode::ReportError => self.new_error_lifetime(Some(l.id), span),
             },
             ident => {
-                self.maybe_collect_in_band_lifetime(ident);
                 let param_name = ParamName::Plain(self.lower_ident(ident));
                 self.new_named_lifetime(l.id, span, hir::LifetimeName::Param(param_name))
             }
@@ -2001,8 +1968,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
 
         let (name, kind) = match param.kind {
             GenericParamKind::Lifetime => {
-                let was_collecting_in_band = self.is_collecting_in_band_lifetimes;
-                self.is_collecting_in_band_lifetimes = false;
+                let was_collecting_in_band = self.is_collecting_anonymous_lifetimes;
+                self.is_collecting_anonymous_lifetimes = false;
 
                 let lt = self
                     .with_anonymous_lifetime_mode(AnonymousLifetimeMode::ReportError, |this| {
@@ -2025,7 +1992,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
                 let kind =
                     hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::Explicit };
 
-                self.is_collecting_in_band_lifetimes = was_collecting_in_band;
+                self.is_collecting_anonymous_lifetimes = was_collecting_in_band;
 
                 (param_name, kind)
             }
@@ -2384,7 +2351,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
             // Hence `impl Foo for &u32` becomes `impl<'f> Foo for &'f u32` for some fresh
             // `'f`.
             AnonymousLifetimeMode::CreateParameter => {
-                let fresh_name = self.collect_fresh_in_band_lifetime(span);
+                let fresh_name = self.collect_fresh_anonymous_lifetime(span);
                 hir::Lifetime {
                     hir_id: self.next_id(),
                     span: self.lower_span(span),
diff --git a/compiler/rustc_error_codes/src/error_codes/E0687.md b/compiler/rustc_error_codes/src/error_codes/E0687.md
index 67b7db2d31f..05c4915535d 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0687.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0687.md
@@ -1,8 +1,10 @@
+#### Note: this error code is no longer emitted by the compiler.
+
 In-band lifetimes cannot be used in `fn`/`Fn` syntax.
 
 Erroneous code examples:
 
-```compile_fail,E0687
+```ignore (feature got removed)
 #![feature(in_band_lifetimes)]
 
 fn foo(x: fn(&'a u32)) {} // error!
diff --git a/compiler/rustc_error_codes/src/error_codes/E0688.md b/compiler/rustc_error_codes/src/error_codes/E0688.md
index db50f490208..44e641a2a0b 100644
--- a/compiler/rustc_error_codes/src/error_codes/E0688.md
+++ b/compiler/rustc_error_codes/src/error_codes/E0688.md
@@ -1,8 +1,10 @@
+#### Note: this error code is no longer emitted by the compiler.
+
 In-band lifetimes were mixed with explicit lifetime binders.
 
 Erroneous code example:
 
-```compile_fail,E0688
+```ignore (feature got removed)
 #![feature(in_band_lifetimes)]
 
 fn foo<'a>(x: &'a u32, y: &'b u32) {}   // error!
diff --git a/compiler/rustc_feature/src/active.rs b/compiler/rustc_feature/src/active.rs
index 5545abc6024..1d9d16e85cb 100644
--- a/compiler/rustc_feature/src/active.rs
+++ b/compiler/rustc_feature/src/active.rs
@@ -400,8 +400,6 @@ declare_features! (
     (active, if_let_guard, "1.47.0", Some(51114), None),
     /// Allows using imported `main` function
     (active, imported_main, "1.53.0", Some(28937), None),
-    /// Allows in-band quantification of lifetime bindings (e.g., `fn foo(x: &'a u8) -> &'a u8`).
-    (active, in_band_lifetimes, "1.23.0", Some(44524), None),
     /// Allows inferring `'static` outlives requirements (RFC 2093).
     (active, infer_static_outlives_requirements, "1.26.0", Some(54185), None),
     /// Allows associated types in inherent impls.
diff --git a/compiler/rustc_feature/src/removed.rs b/compiler/rustc_feature/src/removed.rs
index f5f944db5e9..fae9bd633af 100644
--- a/compiler/rustc_feature/src/removed.rs
+++ b/compiler/rustc_feature/src/removed.rs
@@ -104,6 +104,9 @@ declare_features! (
     (removed, impl_trait_in_bindings, "1.55.0", Some(63065), None,
      Some("the implementation was not maintainable, the feature may get reintroduced once the current refactorings are done")),
     (removed, import_shadowing, "1.0.0", None, None, None),
+    /// Allows in-band quantification of lifetime bindings (e.g., `fn foo(x: &'a u8) -> &'a u8`).
+    (removed, in_band_lifetimes, "1.23.0", Some(44524), None,
+     Some("removed due to unsolved ergonomic questions and added lifetime resolution complexity")),
     /// Lazily evaluate constants. This allows constants to depend on type parameters.
     (removed, lazy_normalization_consts, "1.46.0", Some(72219), None, Some("superseded by `generic_const_exprs`")),
     /// Allows using the `#[link_args]` attribute.
diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs
index 72c02932945..c3795e48d76 100644
--- a/compiler/rustc_hir/src/hir.rs
+++ b/compiler/rustc_hir/src/hir.rs
@@ -471,11 +471,6 @@ pub enum LifetimeParamKind {
     // `fn foo<'a>(x: &'a u8) -> &'a u8 { x }`).
     Explicit,
 
-    // Indicates that the lifetime definition was synthetically added
-    // as a result of an in-band lifetime usage (e.g., in
-    // `fn foo(x: &'a u8) -> &'a u8 { x }`).
-    InBand,
-
     // Indication that the lifetime was elided (e.g., in both cases in
     // `fn foo(x: &u8) -> &'_ u8 { x }`).
     Elided,
diff --git a/compiler/rustc_middle/src/middle/resolve_lifetime.rs b/compiler/rustc_middle/src/middle/resolve_lifetime.rs
index 2665ea8d7fd..4f1b391e94d 100644
--- a/compiler/rustc_middle/src/middle/resolve_lifetime.rs
+++ b/compiler/rustc_middle/src/middle/resolve_lifetime.rs
@@ -15,8 +15,6 @@ use rustc_macros::HashStable;
 pub enum LifetimeDefOrigin {
     // Explicit binders like `fn foo<'a>(x: &'a u8)` or elided like `impl Foo<&u32>`
     ExplicitOrElided,
-    // In-band declarations like `fn foo(x: &'a u8)`
-    InBand,
     // Some kind of erroneous origin
     Error,
 }
@@ -25,7 +23,6 @@ impl LifetimeDefOrigin {
     pub fn from_param(param: &GenericParam<'_>) -> Self {
         match param.kind {
             GenericParamKind::Lifetime { kind } => match kind {
-                LifetimeParamKind::InBand => LifetimeDefOrigin::InBand,
                 LifetimeParamKind::Explicit => LifetimeDefOrigin::ExplicitOrElided,
                 LifetimeParamKind::Elided => LifetimeDefOrigin::ExplicitOrElided,
                 LifetimeParamKind::Error => LifetimeDefOrigin::Error,
diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs
index f20cf29cc89..260fc81500a 100644
--- a/compiler/rustc_resolve/src/late/diagnostics.rs
+++ b/compiler/rustc_resolve/src/late/diagnostics.rs
@@ -1844,7 +1844,6 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
             lifetime_ref
         );
         err.span_label(lifetime_ref.span, "undeclared lifetime");
-        let mut suggests_in_band = false;
         let mut suggested_spans = vec![];
         for missing in &self.missing_named_lifetime_spots {
             match missing {
@@ -1860,7 +1859,6 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
                     }) {
                         (param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))
                     } else {
-                        suggests_in_band = true;
                         (generics.span, format!("<{}>", lifetime_ref))
                     };
                     if suggested_spans.contains(&span) {
@@ -1895,15 +1893,6 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
                 _ => {}
             }
         }
-        if self.tcx.sess.is_nightly_build()
-            && !self.tcx.features().in_band_lifetimes
-            && suggests_in_band
-        {
-            err.help(
-                "if you want to experiment with in-band lifetime bindings, \
-                 add `#![feature(in_band_lifetimes)]` to the crate attributes",
-            );
-        }
         err.emit();
     }
 
diff --git a/compiler/rustc_resolve/src/late/lifetimes.rs b/compiler/rustc_resolve/src/late/lifetimes.rs
index 2f0ad60709d..aa25304992b 100644
--- a/compiler/rustc_resolve/src/late/lifetimes.rs
+++ b/compiler/rustc_resolve/src/late/lifetimes.rs
@@ -16,7 +16,7 @@ use rustc_hir::def_id::{DefIdMap, LocalDefId};
 use rustc_hir::hir_id::ItemLocalId;
 use rustc_hir::intravisit::{self, Visitor};
 use rustc_hir::{GenericArg, GenericParam, LifetimeName, Node, ParamName, QPath};
-use rustc_hir::{GenericParamKind, HirIdMap, HirIdSet, LifetimeParamKind};
+use rustc_hir::{GenericParamKind, HirIdMap, HirIdSet};
 use rustc_middle::hir::map::Map;
 use rustc_middle::hir::nested_filter;
 use rustc_middle::middle::resolve_lifetime::*;
@@ -1325,9 +1325,6 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
     }
 
     fn visit_generics(&mut self, generics: &'tcx hir::Generics<'tcx>) {
-        if !self.trait_definition_only {
-            check_mixed_explicit_and_in_band_defs(self.tcx, &generics.params);
-        }
         let scope = Scope::TraitRefBoundary { s: self.scope };
         self.with(scope, |_, this| {
             for param in generics.params {
@@ -1535,30 +1532,6 @@ impl ShadowKind {
     }
 }
 
-fn check_mixed_explicit_and_in_band_defs(tcx: TyCtxt<'_>, params: &[hir::GenericParam<'_>]) {
-    let lifetime_params: Vec<_> = params
-        .iter()
-        .filter_map(|param| match param.kind {
-            GenericParamKind::Lifetime { kind, .. } => Some((kind, param.span)),
-            _ => None,
-        })
-        .collect();
-    let explicit = lifetime_params.iter().find(|(kind, _)| *kind == LifetimeParamKind::Explicit);
-    let in_band = lifetime_params.iter().find(|(kind, _)| *kind == LifetimeParamKind::InBand);
-
-    if let (Some((_, explicit_span)), Some((_, in_band_span))) = (explicit, in_band) {
-        struct_span_err!(
-            tcx.sess,
-            *in_band_span,
-            E0688,
-            "cannot mix in-band and explicit lifetime definitions"
-        )
-        .span_label(*in_band_span, "in-band lifetime definition here")
-        .span_label(*explicit_span, "explicit lifetime definition here")
-        .emit();
-    }
-}
-
 fn signal_shadowing_problem(tcx: TyCtxt<'_>, name: Symbol, orig: Original, shadower: Shadower) {
     let mut err = if let (ShadowKind::Lifetime, ShadowKind::Lifetime) = (orig.kind, shadower.kind) {
         // lifetime/lifetime shadowing is an error
@@ -1845,13 +1818,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
     fn lifetime_deletion_span(&self, name: Ident, generics: &hir::Generics<'_>) -> Option<Span> {
         generics.params.iter().enumerate().find_map(|(i, param)| {
             if param.name.ident() == name {
-                let in_band = matches!(
-                    param.kind,
-                    hir::GenericParamKind::Lifetime { kind: hir::LifetimeParamKind::InBand }
-                );
-                if in_band {
-                    Some(param.span)
-                } else if generics.params.len() == 1 {
+                if generics.params.len() == 1 {
                     // if sole lifetime, remove the entire `<>` brackets
                     Some(generics.span)
                 } else {
@@ -2337,39 +2304,6 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> {
                 }
             }
 
-            // Check for fn-syntax conflicts with in-band lifetime definitions
-            if !self.trait_definition_only && self.is_in_fn_syntax {
-                match def {
-                    Region::EarlyBound(_, _, LifetimeDefOrigin::InBand)
-                    | Region::LateBound(_, _, _, LifetimeDefOrigin::InBand) => {
-                        struct_span_err!(
-                            self.tcx.sess,
-                            lifetime_ref.span,
-                            E0687,
-                            "lifetimes used in `fn` or `Fn` syntax must be \
-                             explicitly declared using `<...>` binders"
-                        )
-                        .span_label(lifetime_ref.span, "in-band lifetime definition")
-                        .emit();
-                    }
-
-                    Region::Static
-                    | Region::EarlyBound(
-                        _,
-                        _,
-                        LifetimeDefOrigin::ExplicitOrElided | LifetimeDefOrigin::Error,
-                    )
-                    | Region::LateBound(
-                        _,
-                        _,
-                        _,
-                        LifetimeDefOrigin::ExplicitOrElided | LifetimeDefOrigin::Error,
-                    )
-                    | Region::LateBoundAnon(..)
-                    | Region::Free(..) => {}
-                }
-            }
-
             self.insert_lifetime(lifetime_ref, def);
         } else {
             self.emit_undeclared_lifetime_error(lifetime_ref);