diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 8ddaf7a630d31..03e74e3e1d40f 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -43,7 +43,6 @@ declare_lint_pass! { DEPRECATED_WHERE_CLAUSE_LOCATION, DUPLICATE_FEATURES, DUPLICATE_MACRO_ATTRIBUTES, - ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT, ELIDED_LIFETIMES_IN_PATHS, EXPLICIT_BUILTIN_CFGS_IN_FLAGS, EXPORTED_PRIVATE_DEPENDENCIES, @@ -4809,48 +4808,6 @@ declare_lint! { "impl trait in impl method signature does not match trait method signature", } -declare_lint! { - /// The `elided_lifetimes_in_associated_constant` lint detects elided lifetimes - /// in associated constants when there are other lifetimes in scope. This was - /// accidentally supported, and this lint was later relaxed to allow eliding - /// lifetimes to `'static` when there are no lifetimes in scope. - /// - /// ### Example - /// - /// ```rust,compile_fail - /// #![deny(elided_lifetimes_in_associated_constant)] - /// - /// struct Foo<'a>(&'a ()); - /// - /// impl<'a> Foo<'a> { - /// const STR: &str = "hello, world"; - /// } - /// ``` - /// - /// {{produces}} - /// - /// ### Explanation - /// - /// Previous version of Rust - /// - /// Implicit static-in-const behavior was decided [against] for associated - /// constants because of ambiguity. This, however, regressed and the compiler - /// erroneously treats elided lifetimes in associated constants as lifetime - /// parameters on the impl. - /// - /// This is a [future-incompatible] lint to transition this to a - /// hard error in the future. - /// - /// [against]: https://github.com/rust-lang/rust/issues/38831 - /// [future-incompatible]: ../index.md#future-incompatible-lints - pub ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT, - Deny, - "elided lifetimes cannot be used in associated constants in impls", - @future_incompatible = FutureIncompatibleInfo { - reason: fcw!(FutureReleaseError #115010), - }; -} - declare_lint! { /// The `private_macro_use` lint detects private macros that are imported /// with `#[macro_use]`. diff --git a/compiler/rustc_resolve/src/errors.rs b/compiler/rustc_resolve/src/errors.rs index 4bcc7a5eb02e8..390a733639456 100644 --- a/compiler/rustc_resolve/src/errors.rs +++ b/compiler/rustc_resolve/src/errors.rs @@ -1661,28 +1661,6 @@ pub(crate) struct UnusedQualifications { pub removal_span: Span, } -#[derive(Diagnostic)] -#[diag( - "{$elided -> - [true] `&` without an explicit lifetime name cannot be used here - *[false] `'_` cannot be used here - }" -)] -pub(crate) struct AssociatedConstElidedLifetime { - #[suggestion( - "use the `'static` lifetime", - style = "verbose", - code = "{code}", - applicability = "machine-applicable" - )] - pub span: Span, - - pub code: &'static str, - pub elided: bool, - #[note("cannot automatically infer `'static` because of other lifetimes in scope")] - pub lifetimes_in_scope: MultiSpan, -} - #[derive(Diagnostic)] #[diag("lifetime parameter `{$ident}` only used once")] pub(crate) struct SingleUseLifetime { diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index d7ff0ebb3c993..db5ea1b5aa8d5 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -342,11 +342,6 @@ enum LifetimeRibKind { /// error on default object bounds (e.g., `Box`). AnonymousReportError, - /// Resolves elided lifetimes to `'static` if there are no other lifetimes in scope, - /// otherwise give a warning that the previous behavior of introducing a new early-bound - /// lifetime is a bug and will be removed (if `emit_lint` is enabled). - StaticIfNoLifetimeInScope { lint_id: NodeId, emit_lint: bool }, - /// Signal we cannot find which should be the anonymous lifetime. ElisionFailure, @@ -1373,7 +1368,6 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc } LifetimeRibKind::AnonymousCreateParameter { .. } | LifetimeRibKind::AnonymousReportError - | LifetimeRibKind::StaticIfNoLifetimeInScope { .. } | LifetimeRibKind::ImplTrait | LifetimeRibKind::Elided(_) | LifetimeRibKind::ElisionFailure @@ -1779,7 +1773,6 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // lifetime would be illegal. LifetimeRibKind::Item | LifetimeRibKind::AnonymousReportError - | LifetimeRibKind::StaticIfNoLifetimeInScope { .. } | LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many), // An anonymous lifetime is legal here, and bound to the right // place, go ahead. @@ -1843,8 +1836,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { | LifetimeRibKind::Generics { .. } | LifetimeRibKind::ElisionFailure | LifetimeRibKind::AnonymousReportError - | LifetimeRibKind::ImplTrait - | LifetimeRibKind::StaticIfNoLifetimeInScope { .. } => {} + | LifetimeRibKind::ImplTrait => {} } } @@ -1883,48 +1875,6 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { self.record_lifetime_use(lifetime.id, res, elision_candidate); return; } - LifetimeRibKind::StaticIfNoLifetimeInScope { lint_id: node_id, emit_lint } => { - let mut lifetimes_in_scope = vec![]; - for rib in self.lifetime_ribs[..i].iter().rev() { - lifetimes_in_scope.extend(rib.bindings.iter().map(|(ident, _)| ident.span)); - // Consider any anonymous lifetimes, too - if let LifetimeRibKind::AnonymousCreateParameter { binder, .. } = rib.kind - && let Some(extra) = self.r.extra_lifetime_params_map.get(&binder) - { - lifetimes_in_scope.extend(extra.iter().map(|(ident, _, _)| ident.span)); - } - if let LifetimeRibKind::Item = rib.kind { - break; - } - } - if lifetimes_in_scope.is_empty() { - self.record_lifetime_use( - lifetime.id, - LifetimeRes::Static, - elision_candidate, - ); - return; - } else if emit_lint { - let lt_span = if elided { - lifetime.ident.span.shrink_to_hi() - } else { - lifetime.ident.span - }; - let code = if elided { "'static " } else { "'static" }; - - self.r.lint_buffer.buffer_lint( - lint::builtin::ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT, - node_id, - lifetime.ident.span, - crate::errors::AssociatedConstElidedLifetime { - elided, - code, - span: lt_span, - lifetimes_in_scope: lifetimes_in_scope.into(), - }, - ); - } - } LifetimeRibKind::AnonymousReportError => { let guar = if elided { let suggestion = self.lifetime_ribs[i..].iter().rev().find_map(|rib| { @@ -2274,8 +2224,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { // // impl Foo for std::cell::Ref // note lack of '_ // async fn foo(_: std::cell::Ref) { ... } - LifetimeRibKind::AnonymousCreateParameter { report_in_path: true, .. } - | LifetimeRibKind::StaticIfNoLifetimeInScope { .. } => { + LifetimeRibKind::AnonymousCreateParameter { report_in_path: true, .. } => { let sess = self.r.tcx.sess; let subdiag = elided_lifetime_in_path_suggestion( sess.source_map(), @@ -3348,10 +3297,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { generics.span, |this| { this.with_lifetime_rib( - LifetimeRibKind::StaticIfNoLifetimeInScope { - lint_id: item.id, - emit_lint: false, - }, + LifetimeRibKind::Elided(LifetimeRes::Static), |this| { this.visit_generics(generics); if rhs_kind.is_type_const() @@ -3567,67 +3513,44 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { generics.span, |this| { this.with_lifetime_rib( - // Until these are a hard error, we need to create them within the - // correct binder, Otherwise the lifetimes of this assoc const think - // they are lifetimes of the trait. - LifetimeRibKind::AnonymousCreateParameter { - binder: item.id, - report_in_path: true, - }, + LifetimeRibKind::Elided(LifetimeRes::Static), |this| { - this.with_lifetime_rib( - LifetimeRibKind::StaticIfNoLifetimeInScope { - lint_id: item.id, - // In impls, it's not a hard error yet due to backcompat. - emit_lint: true, - }, - |this| { - // If this is a trait impl, ensure the const - // exists in trait - this.check_trait_item( - item.id, - *ident, - *ident, - &item.kind, - ValueNS, - item.span, - seen_trait_items, - |i, s, c| ConstNotMemberOfTrait(i, s, c), - ); + // If this is a trait impl, ensure the const + // exists in trait + this.check_trait_item( + item.id, + *ident, + *ident, + &item.kind, + ValueNS, + item.span, + seen_trait_items, + |i, s, c| ConstNotMemberOfTrait(i, s, c), + ); - this.visit_generics(generics); - if rhs_kind.is_type_const() - && !this - .r - .tcx - .features() - .generic_const_parameter_types() - { - this.with_rib(TypeNS, RibKind::ConstParamTy, |this| { - this.with_rib( - ValueNS, - RibKind::ConstParamTy, - |this| { - this.with_lifetime_rib( - LifetimeRibKind::ConstParamTy, - |this| this.visit_ty(ty), - ) - }, - ) - }); - } else { - this.visit_ty(ty); - } - // We allow arbitrary const expressions inside of associated consts, - // even if they are potentially not const evaluatable. - // - // Type parameters can already be used and as associated consts are - // not used as part of the type system, this is far less surprising. - this.resolve_const_item_rhs(rhs_kind, None); - }, - ) + this.visit_generics(generics); + if rhs_kind.is_type_const() + && !this.r.tcx.features().generic_const_parameter_types() + { + this.with_rib(TypeNS, RibKind::ConstParamTy, |this| { + this.with_rib(ValueNS, RibKind::ConstParamTy, |this| { + this.with_lifetime_rib( + LifetimeRibKind::ConstParamTy, + |this| this.visit_ty(ty), + ) + }) + }); + } else { + this.visit_ty(ty); + } + // We allow arbitrary const expressions inside of associated consts, + // even if they are potentially not const evaluatable. + // + // Type parameters can already be used and as associated consts are + // not used as part of the type system, this is far less surprising. + this.resolve_const_item_rhs(rhs_kind, None); }, - ); + ) }, ); self.resolve_define_opaques(define_opaque); diff --git a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs index 264bb4fa814dc..a486024332f8f 100644 --- a/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs +++ b/src/tools/rust-analyzer/crates/ide-db/src/generated/lints.rs @@ -383,13 +383,6 @@ pub const DEFAULT_LINTS: &[Lint] = &[ warn_since: None, deny_since: None, }, - Lint { - label: "elided_lifetimes_in_associated_constant", - description: r##"elided lifetimes cannot be used in associated constants in impls"##, - default_severity: Severity::Error, - warn_since: None, - deny_since: None, - }, Lint { label: "elided_lifetimes_in_paths", description: r##"hidden lifetime parameters in types are deprecated"##, @@ -1851,7 +1844,6 @@ pub const DEFAULT_LINT_GROUPS: &[LintGroup] = &[ "coherence_leak_check", "conflicting_repr_hints", "const_evaluatable_unchecked", - "elided_lifetimes_in_associated_constant", "float_literal_f32_fallback", "forbidden_lint_groups", "ill_formed_attribute_input", diff --git a/tests/ui/consts/assoc-const-elided-lifetime.rs b/tests/ui/consts/assoc-const-elided-lifetime.rs index 10cd33a8fed59..3fdd725d32a31 100644 --- a/tests/ui/consts/assoc-const-elided-lifetime.rs +++ b/tests/ui/consts/assoc-const-elided-lifetime.rs @@ -1,4 +1,4 @@ -#![deny(elided_lifetimes_in_associated_constant)] +//@ check-pass use std::marker::PhantomData; @@ -8,12 +8,8 @@ struct Foo<'a> { impl<'a> Foo<'a> { const FOO: Foo<'_> = Foo { x: PhantomData::<&()> }; - //~^ ERROR `'_` cannot be used here - //~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! const BAR: &() = &(); - //~^ ERROR `&` without an explicit lifetime name cannot be used here - //~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! } fn main() {} diff --git a/tests/ui/consts/assoc-const-elided-lifetime.stderr b/tests/ui/consts/assoc-const-elided-lifetime.stderr deleted file mode 100644 index 6277b079bdac7..0000000000000 --- a/tests/ui/consts/assoc-const-elided-lifetime.stderr +++ /dev/null @@ -1,44 +0,0 @@ -error: `'_` cannot be used here - --> $DIR/assoc-const-elided-lifetime.rs:10:20 - | -LL | const FOO: Foo<'_> = Foo { x: PhantomData::<&()> }; - | ^^ - | -note: cannot automatically infer `'static` because of other lifetimes in scope - --> $DIR/assoc-const-elided-lifetime.rs:9:6 - | -LL | impl<'a> Foo<'a> { - | ^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #115010 -note: the lint level is defined here - --> $DIR/assoc-const-elided-lifetime.rs:1:9 - | -LL | #![deny(elided_lifetimes_in_associated_constant)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: use the `'static` lifetime - | -LL - const FOO: Foo<'_> = Foo { x: PhantomData::<&()> }; -LL + const FOO: Foo<'static> = Foo { x: PhantomData::<&()> }; - | - -error: `&` without an explicit lifetime name cannot be used here - --> $DIR/assoc-const-elided-lifetime.rs:14:16 - | -LL | const BAR: &() = &(); - | ^ - | -note: cannot automatically infer `'static` because of other lifetimes in scope - --> $DIR/assoc-const-elided-lifetime.rs:9:6 - | -LL | impl<'a> Foo<'a> { - | ^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #115010 -help: use the `'static` lifetime - | -LL | const BAR: &'static () = &(); - | +++++++ - -error: aborting due to 2 previous errors - diff --git a/tests/ui/consts/static-default-lifetime/elided-lifetime.rs b/tests/ui/consts/static-default-lifetime/elided-lifetime.rs index 989de389180a1..87ca5e082c032 100644 --- a/tests/ui/consts/static-default-lifetime/elided-lifetime.rs +++ b/tests/ui/consts/static-default-lifetime/elided-lifetime.rs @@ -1,11 +1,9 @@ -#![deny(elided_lifetimes_in_associated_constant)] +//@check-pass struct Foo<'a>(&'a ()); impl Foo<'_> { const STATIC: &str = ""; - //~^ ERROR `&` without an explicit lifetime name cannot be used here - //~| WARN this was previously accepted by the compiler but is being phased out } trait Bar { @@ -14,9 +12,6 @@ trait Bar { impl Bar for Foo<'_> { const STATIC: &str = ""; - //~^ ERROR `&` without an explicit lifetime name cannot be used here - //~| WARN this was previously accepted by the compiler but is being phased out - //~| ERROR lifetime parameters or bounds on associated constant `STATIC` do not match the trait declaration } fn main() {} diff --git a/tests/ui/consts/static-default-lifetime/elided-lifetime.stderr b/tests/ui/consts/static-default-lifetime/elided-lifetime.stderr deleted file mode 100644 index 370e6655d8607..0000000000000 --- a/tests/ui/consts/static-default-lifetime/elided-lifetime.stderr +++ /dev/null @@ -1,53 +0,0 @@ -error: `&` without an explicit lifetime name cannot be used here - --> $DIR/elided-lifetime.rs:6:19 - | -LL | const STATIC: &str = ""; - | ^ - | -note: cannot automatically infer `'static` because of other lifetimes in scope - --> $DIR/elided-lifetime.rs:5:10 - | -LL | impl Foo<'_> { - | ^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #115010 -note: the lint level is defined here - --> $DIR/elided-lifetime.rs:1:9 - | -LL | #![deny(elided_lifetimes_in_associated_constant)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: use the `'static` lifetime - | -LL | const STATIC: &'static str = ""; - | +++++++ - -error: `&` without an explicit lifetime name cannot be used here - --> $DIR/elided-lifetime.rs:16:19 - | -LL | const STATIC: &str = ""; - | ^ - | -note: cannot automatically infer `'static` because of other lifetimes in scope - --> $DIR/elided-lifetime.rs:15:18 - | -LL | impl Bar for Foo<'_> { - | ^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #115010 -help: use the `'static` lifetime - | -LL | const STATIC: &'static str = ""; - | +++++++ - -error[E0195]: lifetime parameters or bounds on associated constant `STATIC` do not match the trait declaration - --> $DIR/elided-lifetime.rs:16:17 - | -LL | const STATIC: &str; - | - lifetimes in impl do not match this associated constant in trait -... -LL | const STATIC: &str = ""; - | ^ lifetimes do not match associated constant in trait - -error: aborting due to 3 previous errors - -For more information about this error, try `rustc --explain E0195`. diff --git a/tests/ui/consts/static-default-lifetime/generic-associated-const.rs b/tests/ui/consts/static-default-lifetime/generic-associated-const.rs index 8fabaa43f5a27..04e7e3d5f7cec 100644 --- a/tests/ui/consts/static-default-lifetime/generic-associated-const.rs +++ b/tests/ui/consts/static-default-lifetime/generic-associated-const.rs @@ -1,18 +1,16 @@ -#![deny(elided_lifetimes_in_associated_constant)] +//@ check-pass + #![feature(generic_const_items)] struct A; impl A { const GAC_TYPE: &str = ""; const GAC_LIFETIME<'a>: &str = ""; - //~^ ERROR `&` without an explicit lifetime name cannot be used here - //~| WARN this was previously accepted by the compiler but is being phased out } trait Trait { const GAC_TYPE: &str = ""; const GAC_LIFETIME<'a>: &str = ""; - //~^ ERROR missing lifetime specifier } fn main() {} diff --git a/tests/ui/consts/static-default-lifetime/generic-associated-const.stderr b/tests/ui/consts/static-default-lifetime/generic-associated-const.stderr deleted file mode 100644 index fe858d685f7fa..0000000000000 --- a/tests/ui/consts/static-default-lifetime/generic-associated-const.stderr +++ /dev/null @@ -1,37 +0,0 @@ -error[E0106]: missing lifetime specifier - --> $DIR/generic-associated-const.rs:14:29 - | -LL | const GAC_LIFETIME<'a>: &str = ""; - | ^ expected named lifetime parameter - | -help: consider using the `'a` lifetime - | -LL | const GAC_LIFETIME<'a>: &'a str = ""; - | ++ - -error: `&` without an explicit lifetime name cannot be used here - --> $DIR/generic-associated-const.rs:7:29 - | -LL | const GAC_LIFETIME<'a>: &str = ""; - | ^ - | -note: cannot automatically infer `'static` because of other lifetimes in scope - --> $DIR/generic-associated-const.rs:7:24 - | -LL | const GAC_LIFETIME<'a>: &str = ""; - | ^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #115010 -note: the lint level is defined here - --> $DIR/generic-associated-const.rs:1:9 - | -LL | #![deny(elided_lifetimes_in_associated_constant)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: use the `'static` lifetime - | -LL | const GAC_LIFETIME<'a>: &'static str = ""; - | +++++++ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0106`. diff --git a/tests/ui/consts/static-default-lifetime/static-trait-impl.rs b/tests/ui/consts/static-default-lifetime/static-trait-impl.rs index ecc163aecbf1a..d146034114b96 100644 --- a/tests/ui/consts/static-default-lifetime/static-trait-impl.rs +++ b/tests/ui/consts/static-default-lifetime/static-trait-impl.rs @@ -1,4 +1,4 @@ -#![deny(elided_lifetimes_in_associated_constant)] +//@ check-pass trait Bar<'a> { const STATIC: &'a str; @@ -7,9 +7,6 @@ trait Bar<'a> { struct A; impl Bar<'_> for A { const STATIC: &str = ""; - //~^ ERROR `&` without an explicit lifetime name cannot be used here - //~| WARN this was previously accepted by the compiler but is being phased out - //~| ERROR lifetime parameters or bounds on associated constant `STATIC` do not match the trait declaration } struct B; @@ -19,12 +16,10 @@ impl Bar<'static> for B { struct C; impl Bar<'_> for C { - // make ^^ not cause const STATIC: &'static str = { struct B; impl Bar<'static> for B { const STATIC: &str = ""; - // ^ to emit a future incompat warning } "" }; diff --git a/tests/ui/consts/static-default-lifetime/static-trait-impl.stderr b/tests/ui/consts/static-default-lifetime/static-trait-impl.stderr deleted file mode 100644 index ab82515162014..0000000000000 --- a/tests/ui/consts/static-default-lifetime/static-trait-impl.stderr +++ /dev/null @@ -1,35 +0,0 @@ -error: `&` without an explicit lifetime name cannot be used here - --> $DIR/static-trait-impl.rs:9:19 - | -LL | const STATIC: &str = ""; - | ^ - | -note: cannot automatically infer `'static` because of other lifetimes in scope - --> $DIR/static-trait-impl.rs:8:10 - | -LL | impl Bar<'_> for A { - | ^^ - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #115010 -note: the lint level is defined here - --> $DIR/static-trait-impl.rs:1:9 - | -LL | #![deny(elided_lifetimes_in_associated_constant)] - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: use the `'static` lifetime - | -LL | const STATIC: &'static str = ""; - | +++++++ - -error[E0195]: lifetime parameters or bounds on associated constant `STATIC` do not match the trait declaration - --> $DIR/static-trait-impl.rs:9:17 - | -LL | const STATIC: &'a str; - | - lifetimes in impl do not match this associated constant in trait -... -LL | const STATIC: &str = ""; - | ^ lifetimes do not match associated constant in trait - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0195`. diff --git a/tests/ui/suggestions/missing-lifetime-in-assoc-const-type.default.stderr b/tests/ui/suggestions/missing-lifetime-in-assoc-const-type.default.stderr deleted file mode 100644 index 71ac55bf04483..0000000000000 --- a/tests/ui/suggestions/missing-lifetime-in-assoc-const-type.default.stderr +++ /dev/null @@ -1,25 +0,0 @@ -error[E0726]: implicit elided lifetime not allowed here - --> $DIR/missing-lifetime-in-assoc-const-type.rs:7:14 - | -LL | const B: S = S { s: &() }; - | ^ expected lifetime parameter - | -help: indicate the anonymous lifetime - | -LL | const B: S<'_> = S { s: &() }; - | ++++ - -error[E0726]: implicit elided lifetime not allowed here - --> $DIR/missing-lifetime-in-assoc-const-type.rs:9:14 - | -LL | const D: T = T { a: &(), b: &() }; - | ^ expected lifetime parameters - | -help: indicate the anonymous lifetimes - | -LL | const D: T<'_, '_> = T { a: &(), b: &() }; - | ++++++++ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0726`. diff --git a/tests/ui/suggestions/missing-lifetime-in-assoc-const-type.generic_const_items.stderr b/tests/ui/suggestions/missing-lifetime-in-assoc-const-type.generic_const_items.stderr deleted file mode 100644 index 71ac55bf04483..0000000000000 --- a/tests/ui/suggestions/missing-lifetime-in-assoc-const-type.generic_const_items.stderr +++ /dev/null @@ -1,25 +0,0 @@ -error[E0726]: implicit elided lifetime not allowed here - --> $DIR/missing-lifetime-in-assoc-const-type.rs:7:14 - | -LL | const B: S = S { s: &() }; - | ^ expected lifetime parameter - | -help: indicate the anonymous lifetime - | -LL | const B: S<'_> = S { s: &() }; - | ++++ - -error[E0726]: implicit elided lifetime not allowed here - --> $DIR/missing-lifetime-in-assoc-const-type.rs:9:14 - | -LL | const D: T = T { a: &(), b: &() }; - | ^ expected lifetime parameters - | -help: indicate the anonymous lifetimes - | -LL | const D: T<'_, '_> = T { a: &(), b: &() }; - | ++++++++ - -error: aborting due to 2 previous errors - -For more information about this error, try `rustc --explain E0726`. diff --git a/tests/ui/suggestions/missing-lifetime-in-assoc-const-type.rs b/tests/ui/suggestions/missing-lifetime-in-assoc-const-type.rs index a60f0b94587f8..215abadb24e45 100644 --- a/tests/ui/suggestions/missing-lifetime-in-assoc-const-type.rs +++ b/tests/ui/suggestions/missing-lifetime-in-assoc-const-type.rs @@ -1,14 +1,21 @@ +//@ check-pass + //@ revisions: default generic_const_items #![cfg_attr(generic_const_items, feature(generic_const_items), allow(incomplete_features))] trait ZstAssert: Sized { const A: &str = ""; - const B: S = S { s: &() }; //~ ERROR implicit elided lifetime not allowed here + const B: S = S { s: &() }; const C: &'_ str = ""; - const D: T = T { a: &(), b: &() }; //~ ERROR implicit elided lifetime not allowed here + const D: T = T { a: &(), b: &() }; } +const A: &str = ""; +const B: S = S { s: &() }; +const C: &'_ str = ""; +const D: T = T { a: &(), b: &() }; + struct S<'a> { s: &'a (), }