Resolve const lifetimes to static in trait too
This commit is contained in:
parent
805397c16f
commit
5f3357c3c6
@ -312,8 +312,8 @@ enum LifetimeRibKind {
|
|||||||
|
|
||||||
/// Resolves elided lifetimes to `'static` if there are no other lifetimes in scope,
|
/// 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
|
/// otherwise give a warning that the previous behavior of introducing a new early-bound
|
||||||
/// lifetime is a bug and will be removed.
|
/// lifetime is a bug and will be removed (if `emit_lint` is enabled).
|
||||||
StaticIfNoLifetimeInScope(NodeId),
|
StaticIfNoLifetimeInScope { lint_id: NodeId, emit_lint: bool },
|
||||||
|
|
||||||
/// Signal we cannot find which should be the anonymous lifetime.
|
/// Signal we cannot find which should be the anonymous lifetime.
|
||||||
ElisionFailure,
|
ElisionFailure,
|
||||||
@ -1213,7 +1213,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
|||||||
}
|
}
|
||||||
LifetimeRibKind::AnonymousCreateParameter { .. }
|
LifetimeRibKind::AnonymousCreateParameter { .. }
|
||||||
| LifetimeRibKind::AnonymousReportError
|
| LifetimeRibKind::AnonymousReportError
|
||||||
| LifetimeRibKind::StaticIfNoLifetimeInScope(_)
|
| LifetimeRibKind::StaticIfNoLifetimeInScope { .. }
|
||||||
| LifetimeRibKind::Elided(_)
|
| LifetimeRibKind::Elided(_)
|
||||||
| LifetimeRibKind::ElisionFailure
|
| LifetimeRibKind::ElisionFailure
|
||||||
| LifetimeRibKind::ConcreteAnonConst(_)
|
| LifetimeRibKind::ConcreteAnonConst(_)
|
||||||
@ -1581,7 +1581,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||||||
// lifetime would be illegal.
|
// lifetime would be illegal.
|
||||||
LifetimeRibKind::Item
|
LifetimeRibKind::Item
|
||||||
| LifetimeRibKind::AnonymousReportError
|
| LifetimeRibKind::AnonymousReportError
|
||||||
| LifetimeRibKind::StaticIfNoLifetimeInScope(_)
|
| LifetimeRibKind::StaticIfNoLifetimeInScope { .. }
|
||||||
| LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many),
|
| LifetimeRibKind::ElisionFailure => Some(LifetimeUseSet::Many),
|
||||||
// An anonymous lifetime is legal here, and bound to the right
|
// An anonymous lifetime is legal here, and bound to the right
|
||||||
// place, go ahead.
|
// place, go ahead.
|
||||||
@ -1644,7 +1644,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||||||
| LifetimeRibKind::Generics { .. }
|
| LifetimeRibKind::Generics { .. }
|
||||||
| LifetimeRibKind::ElisionFailure
|
| LifetimeRibKind::ElisionFailure
|
||||||
| LifetimeRibKind::AnonymousReportError
|
| LifetimeRibKind::AnonymousReportError
|
||||||
| LifetimeRibKind::StaticIfNoLifetimeInScope(_) => {}
|
| LifetimeRibKind::StaticIfNoLifetimeInScope { .. } => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1678,7 +1678,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||||||
self.record_lifetime_res(lifetime.id, res, elision_candidate);
|
self.record_lifetime_res(lifetime.id, res, elision_candidate);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LifetimeRibKind::StaticIfNoLifetimeInScope(node_id) => {
|
LifetimeRibKind::StaticIfNoLifetimeInScope { lint_id: node_id, emit_lint } => {
|
||||||
let mut lifetimes_in_scope = vec![];
|
let mut lifetimes_in_scope = vec![];
|
||||||
for rib in &self.lifetime_ribs[..i] {
|
for rib in &self.lifetime_ribs[..i] {
|
||||||
lifetimes_in_scope.extend(rib.bindings.iter().map(|(ident, _)| ident.span));
|
lifetimes_in_scope.extend(rib.bindings.iter().map(|(ident, _)| ident.span));
|
||||||
@ -1696,7 +1696,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||||||
elision_candidate,
|
elision_candidate,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
} else {
|
} else if emit_lint {
|
||||||
self.r.lint_buffer.buffer_lint(
|
self.r.lint_buffer.buffer_lint(
|
||||||
lint::builtin::ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
|
lint::builtin::ELIDED_LIFETIMES_IN_ASSOCIATED_CONSTANT,
|
||||||
node_id,
|
node_id,
|
||||||
@ -1925,7 +1925,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||||||
// impl Foo for std::cell::Ref<u32> // note lack of '_
|
// impl Foo for std::cell::Ref<u32> // note lack of '_
|
||||||
// async fn foo(_: std::cell::Ref<u32>) { ... }
|
// async fn foo(_: std::cell::Ref<u32>) { ... }
|
||||||
LifetimeRibKind::AnonymousCreateParameter { report_in_path: true, .. }
|
LifetimeRibKind::AnonymousCreateParameter { report_in_path: true, .. }
|
||||||
| LifetimeRibKind::StaticIfNoLifetimeInScope(_) => {
|
| LifetimeRibKind::StaticIfNoLifetimeInScope { .. } => {
|
||||||
let sess = self.r.tcx.sess;
|
let sess = self.r.tcx.sess;
|
||||||
let subdiag = rustc_errors::elided_lifetime_in_path_suggestion(
|
let subdiag = rustc_errors::elided_lifetime_in_path_suggestion(
|
||||||
sess.source_map(),
|
sess.source_map(),
|
||||||
@ -2858,6 +2858,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||||||
span: generics.span,
|
span: generics.span,
|
||||||
kind: LifetimeBinderKind::ConstItem,
|
kind: LifetimeBinderKind::ConstItem,
|
||||||
},
|
},
|
||||||
|
|this| {
|
||||||
|
this.with_lifetime_rib(
|
||||||
|
LifetimeRibKind::StaticIfNoLifetimeInScope {
|
||||||
|
lint_id: item.id,
|
||||||
|
emit_lint: false,
|
||||||
|
},
|
||||||
|this| {
|
|this| {
|
||||||
this.visit_generics(generics);
|
this.visit_generics(generics);
|
||||||
this.visit_ty(ty);
|
this.visit_ty(ty);
|
||||||
@ -2873,6 +2879,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||||||
this.resolve_const_body(expr, None);
|
this.resolve_const_body(expr, None);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
)
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
AssocItemKind::Fn(box Fn { generics, .. }) => {
|
AssocItemKind::Fn(box Fn { generics, .. }) => {
|
||||||
@ -3052,7 +3060,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
|||||||
},
|
},
|
||||||
|this| {
|
|this| {
|
||||||
this.with_lifetime_rib(
|
this.with_lifetime_rib(
|
||||||
LifetimeRibKind::StaticIfNoLifetimeInScope(item.id),
|
LifetimeRibKind::StaticIfNoLifetimeInScope {
|
||||||
|
lint_id: item.id,
|
||||||
|
// In impls, it's not a hard error yet due to backcompat.
|
||||||
|
emit_lint: true,
|
||||||
|
},
|
||||||
|this| {
|
|this| {
|
||||||
// If this is a trait impl, ensure the const
|
// If this is a trait impl, ensure the const
|
||||||
// exists in trait
|
// exists in trait
|
||||||
|
@ -9,8 +9,7 @@ impl Foo<'_> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
trait Bar {
|
trait Bar {
|
||||||
const STATIC: &'static str;
|
const STATIC: &str;
|
||||||
// TODO^
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Bar for Foo<'_> {
|
impl Bar for Foo<'_> {
|
||||||
|
@ -22,7 +22,7 @@ LL | const STATIC: &'static str = "";
|
|||||||
| +++++++
|
| +++++++
|
||||||
|
|
||||||
error: `&` without an explicit lifetime name cannot be used here
|
error: `&` without an explicit lifetime name cannot be used here
|
||||||
--> $DIR/elided-lifetime.rs:17:19
|
--> $DIR/elided-lifetime.rs:16:19
|
||||||
|
|
|
|
||||||
LL | const STATIC: &str = "";
|
LL | const STATIC: &str = "";
|
||||||
| ^
|
| ^
|
||||||
@ -30,7 +30,7 @@ LL | const STATIC: &str = "";
|
|||||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
= 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 <https://github.com/rust-lang/rust/issues/115010>
|
= note: for more information, see issue #115010 <https://github.com/rust-lang/rust/issues/115010>
|
||||||
note: cannot automatically infer `'static` because of other lifetimes in scope
|
note: cannot automatically infer `'static` because of other lifetimes in scope
|
||||||
--> $DIR/elided-lifetime.rs:16:18
|
--> $DIR/elided-lifetime.rs:15:18
|
||||||
|
|
|
|
||||||
LL | impl Bar for Foo<'_> {
|
LL | impl Bar for Foo<'_> {
|
||||||
| ^^
|
| ^^
|
||||||
@ -40,7 +40,7 @@ LL | const STATIC: &'static str = "";
|
|||||||
| +++++++
|
| +++++++
|
||||||
|
|
||||||
error[E0308]: const not compatible with trait
|
error[E0308]: const not compatible with trait
|
||||||
--> $DIR/elided-lifetime.rs:17:5
|
--> $DIR/elided-lifetime.rs:16:5
|
||||||
|
|
|
|
||||||
LL | const STATIC: &str = "";
|
LL | const STATIC: &str = "";
|
||||||
| ^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
| ^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
||||||
@ -48,7 +48,7 @@ LL | const STATIC: &str = "";
|
|||||||
= note: expected reference `&'static _`
|
= note: expected reference `&'static _`
|
||||||
found reference `&_`
|
found reference `&_`
|
||||||
note: the anonymous lifetime as defined here...
|
note: the anonymous lifetime as defined here...
|
||||||
--> $DIR/elided-lifetime.rs:16:18
|
--> $DIR/elided-lifetime.rs:15:18
|
||||||
|
|
|
|
||||||
LL | impl Bar for Foo<'_> {
|
LL | impl Bar for Foo<'_> {
|
||||||
| ^^
|
| ^^
|
||||||
|
@ -12,7 +12,6 @@ impl A {
|
|||||||
|
|
||||||
trait Trait {
|
trait Trait {
|
||||||
const GAC_TYPE<T>: &str = "";
|
const GAC_TYPE<T>: &str = "";
|
||||||
//~^ ERROR missing lifetime specifier
|
|
||||||
const GAC_LIFETIME<'a>: &str = "";
|
const GAC_LIFETIME<'a>: &str = "";
|
||||||
//~^ ERROR missing lifetime specifier
|
//~^ ERROR missing lifetime specifier
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,5 @@
|
|||||||
error[E0106]: missing lifetime specifier
|
error[E0106]: missing lifetime specifier
|
||||||
--> $DIR/generic-associated-const.rs:14:24
|
--> $DIR/generic-associated-const.rs:15:29
|
||||||
|
|
|
||||||
LL | const GAC_TYPE<T>: &str = "";
|
|
||||||
| ^ expected named lifetime parameter
|
|
||||||
|
|
|
||||||
help: consider introducing a named lifetime parameter
|
|
||||||
|
|
|
||||||
LL | const GAC_TYPE<'a, T>: &'a str = "";
|
|
||||||
| +++ ++
|
|
||||||
|
|
||||||
error[E0106]: missing lifetime specifier
|
|
||||||
--> $DIR/generic-associated-const.rs:16:29
|
|
||||||
|
|
|
|
||||||
LL | const GAC_LIFETIME<'a>: &str = "";
|
LL | const GAC_LIFETIME<'a>: &str = "";
|
||||||
| ^ expected named lifetime parameter
|
| ^ expected named lifetime parameter
|
||||||
@ -52,6 +41,6 @@ help: use the `'static` lifetime
|
|||||||
LL | const GAC_LIFETIME<'a>: &'static str = "";
|
LL | const GAC_LIFETIME<'a>: &'static str = "";
|
||||||
| +++++++
|
| +++++++
|
||||||
|
|
||||||
error: aborting due to 3 previous errors; 1 warning emitted
|
error: aborting due to 2 previous errors; 1 warning emitted
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0106`.
|
For more information about this error, try `rustc --explain E0106`.
|
||||||
|
@ -1,57 +1,25 @@
|
|||||||
error[E0106]: missing lifetime specifier
|
error[E0726]: implicit elided lifetime not allowed here
|
||||||
--> $DIR/missing-lifetime-in-assoc-const-type.rs:6:14
|
|
||||||
|
|
|
||||||
LL | const A: &str = "";
|
|
||||||
| ^ expected named lifetime parameter
|
|
||||||
|
|
|
||||||
help: consider introducing a named lifetime parameter
|
|
||||||
|
|
|
||||||
LL ~ trait ZstAssert<'a>: Sized {
|
|
||||||
LL ~ const A: &'a str = "";
|
|
||||||
|
|
|
||||||
|
|
||||||
error[E0106]: missing lifetime specifier
|
|
||||||
--> $DIR/missing-lifetime-in-assoc-const-type.rs:7:14
|
--> $DIR/missing-lifetime-in-assoc-const-type.rs:7:14
|
||||||
|
|
|
|
||||||
LL | const B: S = S { s: &() };
|
LL | const B: S = S { s: &() };
|
||||||
| ^ expected named lifetime parameter
|
| ^ expected lifetime parameter
|
||||||
|
|
|
|
||||||
help: consider introducing a named lifetime parameter
|
help: indicate the anonymous lifetime
|
||||||
|
|
|
||||||
LL ~ trait ZstAssert<'a>: Sized {
|
|
||||||
LL | const A: &str = "";
|
|
||||||
LL ~ const B: S<'a> = S { s: &() };
|
|
||||||
|
|
|
|
||||||
|
LL | const B: S<'_> = S { s: &() };
|
||||||
|
| ++++
|
||||||
|
|
||||||
error[E0106]: missing lifetime specifier
|
error[E0726]: implicit elided lifetime not allowed here
|
||||||
--> $DIR/missing-lifetime-in-assoc-const-type.rs:8:15
|
|
||||||
|
|
|
||||||
LL | const C: &'_ str = "";
|
|
||||||
| ^^ expected named lifetime parameter
|
|
||||||
|
|
|
||||||
help: consider introducing a named lifetime parameter
|
|
||||||
|
|
|
||||||
LL ~ trait ZstAssert<'a>: Sized {
|
|
||||||
LL | const A: &str = "";
|
|
||||||
LL | const B: S = S { s: &() };
|
|
||||||
LL ~ const C: &'a str = "";
|
|
||||||
|
|
|
||||||
|
|
||||||
error[E0106]: missing lifetime specifiers
|
|
||||||
--> $DIR/missing-lifetime-in-assoc-const-type.rs:9:14
|
--> $DIR/missing-lifetime-in-assoc-const-type.rs:9:14
|
||||||
|
|
|
|
||||||
LL | const D: T = T { a: &(), b: &() };
|
LL | const D: T = T { a: &(), b: &() };
|
||||||
| ^ expected 2 lifetime parameters
|
| ^ expected lifetime parameters
|
||||||
|
|
|
|
||||||
help: consider introducing a named lifetime parameter
|
help: indicate the anonymous lifetimes
|
||||||
|
|
|
||||||
LL ~ trait ZstAssert<'a>: Sized {
|
|
||||||
LL | const A: &str = "";
|
|
||||||
LL | const B: S = S { s: &() };
|
|
||||||
LL | const C: &'_ str = "";
|
|
||||||
LL ~ const D: T<'a, 'a> = T { a: &(), b: &() };
|
|
||||||
|
|
|
|
||||||
|
LL | const D: T<'_, '_> = T { a: &(), b: &() };
|
||||||
|
| ++++++++
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0106`.
|
For more information about this error, try `rustc --explain E0726`.
|
||||||
|
@ -1,47 +1,25 @@
|
|||||||
error[E0106]: missing lifetime specifier
|
error[E0726]: implicit elided lifetime not allowed here
|
||||||
--> $DIR/missing-lifetime-in-assoc-const-type.rs:6:14
|
|
||||||
|
|
|
||||||
LL | const A: &str = "";
|
|
||||||
| ^ expected named lifetime parameter
|
|
||||||
|
|
|
||||||
help: consider introducing a named lifetime parameter
|
|
||||||
|
|
|
||||||
LL | const A<'a>: &'a str = "";
|
|
||||||
| ++++ ++
|
|
||||||
|
|
||||||
error[E0106]: missing lifetime specifier
|
|
||||||
--> $DIR/missing-lifetime-in-assoc-const-type.rs:7:14
|
--> $DIR/missing-lifetime-in-assoc-const-type.rs:7:14
|
||||||
|
|
|
|
||||||
LL | const B: S = S { s: &() };
|
LL | const B: S = S { s: &() };
|
||||||
| ^ expected named lifetime parameter
|
| ^ expected lifetime parameter
|
||||||
|
|
|
|
||||||
help: consider introducing a named lifetime parameter
|
help: indicate the anonymous lifetime
|
||||||
|
|
|
|
||||||
LL | const B<'a>: S<'a> = S { s: &() };
|
LL | const B: S<'_> = S { s: &() };
|
||||||
| ++++ ++++
|
| ++++
|
||||||
|
|
||||||
error[E0106]: missing lifetime specifier
|
error[E0726]: implicit elided lifetime not allowed here
|
||||||
--> $DIR/missing-lifetime-in-assoc-const-type.rs:8:15
|
|
||||||
|
|
|
||||||
LL | const C: &'_ str = "";
|
|
||||||
| ^^ expected named lifetime parameter
|
|
||||||
|
|
|
||||||
help: consider introducing a named lifetime parameter
|
|
||||||
|
|
|
||||||
LL | const C<'a>: &'a str = "";
|
|
||||||
| ++++ ~~
|
|
||||||
|
|
||||||
error[E0106]: missing lifetime specifiers
|
|
||||||
--> $DIR/missing-lifetime-in-assoc-const-type.rs:9:14
|
--> $DIR/missing-lifetime-in-assoc-const-type.rs:9:14
|
||||||
|
|
|
|
||||||
LL | const D: T = T { a: &(), b: &() };
|
LL | const D: T = T { a: &(), b: &() };
|
||||||
| ^ expected 2 lifetime parameters
|
| ^ expected lifetime parameters
|
||||||
|
|
|
|
||||||
help: consider introducing a named lifetime parameter
|
help: indicate the anonymous lifetimes
|
||||||
|
|
|
|
||||||
LL | const D<'a>: T<'a, 'a> = T { a: &(), b: &() };
|
LL | const D: T<'_, '_> = T { a: &(), b: &() };
|
||||||
| ++++ ++++++++
|
| ++++++++
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0106`.
|
For more information about this error, try `rustc --explain E0726`.
|
||||||
|
@ -3,10 +3,10 @@
|
|||||||
#![cfg_attr(generic_const_items, feature(generic_const_items), allow(incomplete_features))]
|
#![cfg_attr(generic_const_items, feature(generic_const_items), allow(incomplete_features))]
|
||||||
|
|
||||||
trait ZstAssert: Sized {
|
trait ZstAssert: Sized {
|
||||||
const A: &str = ""; //~ ERROR missing lifetime specifier
|
const A: &str = "";
|
||||||
const B: S = S { s: &() }; //~ ERROR missing lifetime specifier
|
const B: S = S { s: &() }; //~ ERROR implicit elided lifetime not allowed here
|
||||||
const C: &'_ str = ""; //~ ERROR missing lifetime specifier
|
const C: &'_ str = "";
|
||||||
const D: T = T { a: &(), b: &() }; //~ ERROR missing lifetime specifier
|
const D: T = T { a: &(), b: &() }; //~ ERROR implicit elided lifetime not allowed here
|
||||||
}
|
}
|
||||||
|
|
||||||
struct S<'a> {
|
struct S<'a> {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user