--> $DIR/gat-in-trait-path-undeclared-lifetime.rs:8:35
|
LL | fn _f(arg : Box<dyn for<'a> X<Y<'x> = &'a [u32]>>) {}
- | - ^^ undeclared lifetime
- | |
- | help: consider introducing lifetime `'x` here: `<'x>`
+ | ^^ undeclared lifetime
+ |
+ = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
+help: consider making the bound lifetime-generic with a new `'x` lifetime
+ |
+LL | fn _f(arg : Box<dyn for<'x, 'a> X<Y<'x> = &'a [u32]>>) {}
+ | +++
+help: consider introducing lifetime `'x` here
+ |
+LL | fn _f<'x>(arg : Box<dyn for<'a> X<Y<'x> = &'a [u32]>>) {}
+ | ++++
error[E0582]: binding for associated type `Y` references lifetime `'a`, which does not appear in the trait input types
--> $DIR/gat-in-trait-path-undeclared-lifetime.rs:8:33
LL | + Deref<Target = Self::Item<'b>>;
| ^^ undeclared lifetime
|
-help: consider introducing lifetime `'b` here
+ = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
+help: consider making the bound lifetime-generic with a new `'b` lifetime
|
-LL | trait Iterable<'b> {
- | ++++
+LL | + for<'b> Deref<Target = Self::Item<'b>>;
+ | +++++++
help: consider introducing lifetime `'b` here
|
LL | type Iter<'b, 'a>: Iterator<Item = Self::Item<'a>>
| +++
+help: consider introducing lifetime `'b` here
+ |
+LL | trait Iterable<'b> {
+ | ++++
error[E0261]: use of undeclared lifetime name `'undeclared`
--> $DIR/generic_associated_type_undeclared_lifetimes.rs:11:41
|
help: consider introducing lifetime `'undeclared` here
|
-LL | trait Iterable<'undeclared> {
- | +++++++++++++
-help: consider introducing lifetime `'undeclared` here
- |
LL | fn iter<'undeclared, 'a>(&'a self) -> Self::Iter<'undeclared>;
| ++++++++++++
+help: consider introducing lifetime `'undeclared` here
+ |
+LL | trait Iterable<'undeclared> {
+ | +++++++++++++
error: aborting due to 2 previous errors
type Y<'a>;
}
-fn f(x: Box<dyn X<Y<'a>=&'a ()>>) {}
- //~^ ERROR: use of undeclared lifetime name `'a`
- //~| ERROR: use of undeclared lifetime name `'a`
-
+fn f(x: Box<dyn X<Y<'a> = &'a ()>>) {}
+//~^ ERROR: use of undeclared lifetime name `'a`
+//~| ERROR: use of undeclared lifetime name `'a`
+//~| ERROR: the trait `X` cannot be made into an object [E0038]
fn main() {}
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/issue-67510.rs:7:21
|
-LL | fn f(x: Box<dyn X<Y<'a>=&'a ()>>) {}
- | - ^^ undeclared lifetime
- | |
- | help: consider introducing lifetime `'a` here: `<'a>`
+LL | fn f(x: Box<dyn X<Y<'a> = &'a ()>>) {}
+ | ^^ undeclared lifetime
+ |
+ = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
+help: consider making the bound lifetime-generic with a new `'a` lifetime
+ |
+LL | fn f(x: Box<dyn for<'a> X<Y<'a> = &'a ()>>) {}
+ | +++++++
+help: consider introducing lifetime `'a` here
+ |
+LL | fn f<'a>(x: Box<dyn X<Y<'a> = &'a ()>>) {}
+ | ++++
error[E0261]: use of undeclared lifetime name `'a`
- --> $DIR/issue-67510.rs:7:26
+ --> $DIR/issue-67510.rs:7:28
+ |
+LL | fn f(x: Box<dyn X<Y<'a> = &'a ()>>) {}
+ | ^^ undeclared lifetime
+ |
+help: consider making the bound lifetime-generic with a new `'a` lifetime
+ |
+LL | fn f(x: Box<dyn for<'a> X<Y<'a> = &'a ()>>) {}
+ | +++++++
+help: consider introducing lifetime `'a` here
+ |
+LL | fn f<'a>(x: Box<dyn X<Y<'a> = &'a ()>>) {}
+ | ++++
+
+error[E0038]: the trait `X` cannot be made into an object
+ --> $DIR/issue-67510.rs:7:13
+ |
+LL | fn f(x: Box<dyn X<Y<'a> = &'a ()>>) {}
+ | ^^^^^^^^^^^^^^^^^^^^^ `X` cannot be made into an object
+ |
+note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
+ --> $DIR/issue-67510.rs:4:10
|
-LL | fn f(x: Box<dyn X<Y<'a>=&'a ()>>) {}
- | - ^^ undeclared lifetime
- | |
- | help: consider introducing lifetime `'a` here: `<'a>`
+LL | trait X {
+ | - this trait cannot be made into an object...
+LL | type Y<'a>;
+ | ^ ...because it contains the generic associated type `Y`
+ = help: consider moving `Y` to another trait
-error: aborting due to 2 previous errors
+error: aborting due to 3 previous errors
-For more information about this error, try `rustc --explain E0261`.
+Some errors have detailed explanations: E0038, E0261.
+For more information about an error, try `rustc --explain E0038`.
type Cursor<'a> = DocCursorImpl<'a>;
fn cursor(&self) -> Self::Cursor<'_> {
- DocCursorImpl {
- document: &self,
- }
+ DocCursorImpl { document: &self }
}
}
-
trait DocCursor<'a> {}
struct DocCursorImpl<'a> {
_phantom: std::marker::PhantomData<&'d ()>,
}
-
impl<'d, Cursor> Lexer<'d, Cursor>
where
Cursor: DocCursor<'d>,
where
Doc: Document<Cursor<'d> = Cursor>,
{
- Lexer {
- cursor: document.cursor(),
- _phantom: std::marker::PhantomData,
- }
+ Lexer { cursor: document.cursor(), _phantom: std::marker::PhantomData }
}
}
fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> {
- //~^ ERROR: missing lifetime specifier
+ //~^ ERROR: missing lifetime specifier
DocumentImpl {}
}
error[E0106]: missing lifetime specifier
- --> $DIR/issue-70304.rs:54:41
+ --> $DIR/issue-70304.rs:47:41
|
LL | fn create_doc() -> impl Document<Cursor<'_> = DocCursorImpl<'_>> {
| ^^ expected named lifetime parameter
--> $DIR/generic-extern-lifetime.rs:6:26
|
LL | pub fn life2<'b>(x: &'a i32, y: &'b i32);
- | ^^ undeclared lifetime
+ | - ^^ undeclared lifetime
+ | |
+ | help: consider introducing lifetime `'a` here: `'a,`
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/generic-extern-lifetime.rs:8:37
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the type lifetime-generic with a new `'a` lifetime
|
-LL | pub fn life4<'b>(x: for<'c, 'a> fn(&'a i32));
- | ++++
+LL | pub fn life4<'b>(x: for<'a, 'c> fn(&'a i32));
+ | +++
+help: consider introducing lifetime `'a` here
+ |
+LL | pub fn life4<'a, 'b>(x: for<'c> fn(&'a i32));
+ | +++
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/generic-extern-lifetime.rs:11:39
LL | pub fn life7<'b>() -> for<'c> fn(&'a i32);
| ^^ undeclared lifetime
|
- = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
help: consider making the type lifetime-generic with a new `'a` lifetime
|
-LL | pub fn life7<'b>() -> for<'c, 'a> fn(&'a i32);
- | ++++
+LL | pub fn life7<'b>() -> for<'a, 'c> fn(&'a i32);
+ | +++
+help: consider introducing lifetime `'a` here
+ |
+LL | pub fn life7<'a, 'b>() -> for<'c> fn(&'a i32);
+ | +++
error: aborting due to 3 previous errors
#![allow(warnings)]
-trait MyTrait<'a> { }
+trait MyTrait<'a> {}
-impl MyTrait for u32 {
- //~^ ERROR implicit elided lifetime not allowed here
-}
+impl MyTrait for u32 {}
+//~^ ERROR implicit elided lifetime not allowed here
fn main() {}
error[E0726]: implicit elided lifetime not allowed here
--> $DIR/trait-elided.rs:5:6
|
-LL | impl MyTrait for u32 {
+LL | impl MyTrait for u32 {}
| ^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
|
= note: assuming a `'static` lifetime...
-trait Serializable<'self, T> { //~ ERROR lifetimes cannot use keyword names
- fn serialize(val : &'self T) -> Vec<u8>; //~ ERROR lifetimes cannot use keyword names
- fn deserialize(repr : &[u8]) -> &'self T; //~ ERROR lifetimes cannot use keyword names
+trait Serializable<'self, T> {
+ //~^ ERROR lifetimes cannot use keyword names
+ fn serialize(val: &'self T) -> Vec<u8>; //~ ERROR lifetimes cannot use keyword names
+ fn deserialize(repr: &[u8]) -> &'self T; //~ ERROR lifetimes cannot use keyword names
}
-impl<'self> Serializable<str> for &'self str { //~ ERROR lifetimes cannot use keyword names
+impl<'self> Serializable<str> for &'self str {
//~^ ERROR lifetimes cannot use keyword names
+ //~| ERROR lifetimes cannot use keyword names
//~| ERROR implicit elided lifetime not allowed here
- //~| ERROR the size for values of type `str` cannot be known at compilation time
- fn serialize(val : &'self str) -> Vec<u8> { //~ ERROR lifetimes cannot use keyword names
+ //~| ERROR the size for values of type `str` cannot be known at compilation time [E0277]
+ fn serialize(val: &'self str) -> Vec<u8> {
+ //~^ ERROR lifetimes cannot use keyword names
vec![1]
}
- fn deserialize(repr: &[u8]) -> &'self str { //~ ERROR lifetimes cannot use keyword names
+ fn deserialize(repr: &[u8]) -> &'self str {
+ //~^ ERROR lifetimes cannot use keyword names
"hi"
}
}
| ^^^^^
error: lifetimes cannot use keyword names
- --> $DIR/issue-10412.rs:2:25
+ --> $DIR/issue-10412.rs:3:24
|
-LL | fn serialize(val : &'self T) -> Vec<u8>;
- | ^^^^^
+LL | fn serialize(val: &'self T) -> Vec<u8>;
+ | ^^^^^
error: lifetimes cannot use keyword names
- --> $DIR/issue-10412.rs:3:38
+ --> $DIR/issue-10412.rs:4:37
|
-LL | fn deserialize(repr : &[u8]) -> &'self T;
- | ^^^^^
+LL | fn deserialize(repr: &[u8]) -> &'self T;
+ | ^^^^^
error: lifetimes cannot use keyword names
- --> $DIR/issue-10412.rs:6:6
+ --> $DIR/issue-10412.rs:7:6
|
LL | impl<'self> Serializable<str> for &'self str {
| ^^^^^
error: lifetimes cannot use keyword names
- --> $DIR/issue-10412.rs:6:36
+ --> $DIR/issue-10412.rs:7:36
|
LL | impl<'self> Serializable<str> for &'self str {
| ^^^^^
error: lifetimes cannot use keyword names
- --> $DIR/issue-10412.rs:10:25
+ --> $DIR/issue-10412.rs:12:24
|
-LL | fn serialize(val : &'self str) -> Vec<u8> {
- | ^^^^^
+LL | fn serialize(val: &'self str) -> Vec<u8> {
+ | ^^^^^
error: lifetimes cannot use keyword names
- --> $DIR/issue-10412.rs:13:37
+ --> $DIR/issue-10412.rs:16:37
|
LL | fn deserialize(repr: &[u8]) -> &'self str {
| ^^^^^
error[E0726]: implicit elided lifetime not allowed here
- --> $DIR/issue-10412.rs:6:13
+ --> $DIR/issue-10412.rs:7:13
|
LL | impl<'self> Serializable<str> for &'self str {
| ^^^^^^^^^^^^^^^^^ help: indicate the anonymous lifetime: `Serializable<'_, str>`
= note: assuming a `'static` lifetime...
error[E0277]: the size for values of type `str` cannot be known at compilation time
- --> $DIR/issue-10412.rs:6:13
+ --> $DIR/issue-10412.rs:7:13
|
LL | impl<'self> Serializable<str> for &'self str {
| ^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:3:9
|
+LL | #[derive(Eq, PartialEq)]
+ | -- lifetime `'b` is missing in item created through this procedural macro
LL | struct Test {
| - help: consider introducing lifetime `'b` here: `<'b>`
LL | a: &'b str,
|
help: consider introducing lifetime `'b` here
|
-LL | impl<'b> T for Test {
- | ++++
-help: consider introducing lifetime `'b` here
- |
LL | fn foo<'b>(&'b self) {}
| ++++
+help: consider introducing lifetime `'b` here
+ |
+LL | impl<'b> T for Test {
+ | ++++
error: aborting due to 3 previous errors
fn main() {
- 0.clone::<'a>(); //~ ERROR use of undeclared lifetime name `'a`
+ 0.clone::<'a>();
+ //~^ ERROR use of undeclared lifetime name `'a`
+ //~| WARN cannot specify lifetime arguments explicitly if late bound
+ //~| WARN this was previously accepted by the compiler
}
LL | 0.clone::<'a>();
| ^^ undeclared lifetime
-error: aborting due to previous error
+warning: cannot specify lifetime arguments explicitly if late bound lifetime parameters are present
+ --> $DIR/method-call-lifetime-args-unresolved.rs:2:15
+ |
+LL | 0.clone::<'a>();
+ | ^^
+ |
+ ::: $SRC_DIR/core/src/clone.rs:LL:COL
+ |
+LL | fn clone(&self) -> Self;
+ | - the late bound lifetime parameter is introduced here
+ |
+ = note: `#[warn(late_bound_lifetime_arguments)]` on by default
+ = 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 #42868 <https://github.com/rust-lang/rust/issues/42868>
+
+error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0261`.
-struct Foo<'static> { //~ ERROR invalid lifetime parameter name: `'static`
- x: &'static isize
+struct Foo<'static> {
+ //~^ ERROR invalid lifetime parameter name: `'static`
+ x: &'static isize,
}
fn main() {}
let y: &'a isize = x;
// &'a is not visible to *items*:
- type X = Option<&'a isize>; //~ ERROR undeclared lifetime
+ type X = Option<&'a isize>; //~ ERROR can't use generic parameters from outer item
enum E {
- E1(&'a isize) //~ ERROR undeclared lifetime
+ E1(&'a isize) //~ ERROR can't use generic parameters from outer item
}
struct S {
- f: &'a isize //~ ERROR undeclared lifetime
+ f: &'a isize //~ ERROR can't use generic parameters from outer item
}
- fn f(a: &'a isize) { } //~ ERROR undeclared lifetime
+ fn f(a: &'a isize) { } //~ ERROR can't use generic parameters from outer item
// &'a CAN be declared on functions and used then:
fn g<'a>(a: &'a isize) { } // OK
-error[E0261]: use of undeclared lifetime name `'a`
- --> $DIR/regions-name-undeclared.rs:28:13
- |
-LL | enum E {
- | - help: consider introducing lifetime `'a` here: `<'a>`
-LL | E1(&'a isize)
- | ^^ undeclared lifetime
-
-error[E0261]: use of undeclared lifetime name `'a`
- --> $DIR/regions-name-undeclared.rs:31:13
- |
-LL | struct S {
- | - help: consider introducing lifetime `'a` here: `<'a>`
-LL | f: &'a isize
- | ^^ undeclared lifetime
-
error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/regions-name-undeclared.rs:16:24
|
|
help: consider introducing lifetime `'b` here
|
-LL | impl<'b, 'a> Foo<'a> {
- | +++
-help: consider introducing lifetime `'b` here
- |
LL | fn m4<'b>(&self, arg: &'b isize) { }
| ++++
+help: consider introducing lifetime `'b` here
+ |
+LL | impl<'b, 'a> Foo<'a> {
+ | +++
error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/regions-name-undeclared.rs:17:12
|
help: consider introducing lifetime `'b` here
|
-LL | impl<'b, 'a> Foo<'a> {
- | +++
-help: consider introducing lifetime `'b` here
- |
LL | fn m5<'b>(&'b self) { }
| ++++
+help: consider introducing lifetime `'b` here
+ |
+LL | impl<'b, 'a> Foo<'a> {
+ | +++
error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/regions-name-undeclared.rs:18:27
|
help: consider introducing lifetime `'b` here
|
-LL | impl<'b, 'a> Foo<'a> {
- | +++
-help: consider introducing lifetime `'b` here
- |
LL | fn m6<'b>(&self, arg: Foo<'b>) { }
| ++++
+help: consider introducing lifetime `'b` here
+ |
+LL | impl<'b, 'a> Foo<'a> {
+ | +++
-error[E0261]: use of undeclared lifetime name `'a`
+error[E0401]: can't use generic parameters from outer item
--> $DIR/regions-name-undeclared.rs:26:22
|
+LL | fn bar<'a>(x: &'a isize) {
+ | -- lifetime parameter from outer item
+...
LL | type X = Option<&'a isize>;
- | - ^^ undeclared lifetime
+ | - ^^ use of generic parameter from outer item
| |
| help: consider introducing lifetime `'a` here: `<'a>`
-error[E0261]: use of undeclared lifetime name `'a`
+error[E0401]: can't use generic parameters from outer item
+ --> $DIR/regions-name-undeclared.rs:28:13
+ |
+LL | fn bar<'a>(x: &'a isize) {
+ | -- lifetime parameter from outer item
+...
+LL | enum E {
+ | - help: consider introducing lifetime `'a` here: `<'a>`
+LL | E1(&'a isize)
+ | ^^ use of generic parameter from outer item
+
+error[E0401]: can't use generic parameters from outer item
+ --> $DIR/regions-name-undeclared.rs:31:13
+ |
+LL | fn bar<'a>(x: &'a isize) {
+ | -- lifetime parameter from outer item
+...
+LL | struct S {
+ | - help: consider introducing lifetime `'a` here: `<'a>`
+LL | f: &'a isize
+ | ^^ use of generic parameter from outer item
+
+error[E0401]: can't use generic parameters from outer item
--> $DIR/regions-name-undeclared.rs:33:14
|
+LL | fn bar<'a>(x: &'a isize) {
+ | -- lifetime parameter from outer item
+...
LL | fn f(a: &'a isize) { }
- | - ^^ undeclared lifetime
+ | - ^^ use of generic parameter from outer item
| |
| help: consider introducing lifetime `'a` here: `<'a>`
| ^^ undeclared lifetime
|
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
+help: consider making the bound lifetime-generic with a new `'b` lifetime
+ |
+LL | b: Box<dyn for<'b, 'a> FnOnce(&'a isize,
+ | +++
help: consider introducing lifetime `'b` here
|
LL | fn fn_types<'b>(a: &'a isize,
| ++++
-help: consider making the bound lifetime-generic with a new `'b` lifetime
- |
-LL | b: Box<dyn for<'a, 'b> FnOnce(&'a isize,
- | ++++
error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/regions-name-undeclared.rs:46:36
LL | ... &'b isize)>,
| ^^ undeclared lifetime
|
- = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
+help: consider making the bound lifetime-generic with a new `'b` lifetime
+ |
+LL | b: Box<dyn for<'b, 'a> FnOnce(&'a isize,
+ | +++
help: consider introducing lifetime `'b` here
|
LL | fn fn_types<'b>(a: &'a isize,
| ++++
-help: consider making the bound lifetime-generic with a new `'b` lifetime
- |
-LL | b: Box<dyn for<'a, 'b> FnOnce(&'a isize,
- | ++++
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/regions-name-undeclared.rs:47:17
|
help: consider introducing lifetime `'a` here
|
-LL | impl<'a> Bug {
- | ++++
-help: consider introducing lifetime `'a` here
- |
LL | async fn buggy<'a>(&self) -> &'a str {
| ++++
+help: consider introducing lifetime `'a` here
+ |
+LL | impl<'a> Bug {
+ | ++++
error: aborting due to 12 previous errors
-For more information about this error, try `rustc --explain E0261`.
+Some errors have detailed explanations: E0261, E0401.
+For more information about an error, try `rustc --explain E0261`.
| ^^ undeclared lifetime
|
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
-help: consider introducing lifetime `'a` here
- |
-LL | struct S1<'a, F: Fn(&i32, &i32) -> &'a i32>(F);
- | +++
help: consider making the bound lifetime-generic with a new `'a` lifetime
|
LL | struct S1<F: for<'a> Fn(&i32, &i32) -> &'a i32>(F);
| +++++++
+help: consider introducing lifetime `'a` here
+ |
+LL | struct S1<'a, F: Fn(&i32, &i32) -> &'a i32>(F);
+ | +++
error[E0106]: missing lifetime specifier
--> $DIR/fn-missing-lifetime-in-item.rs:2:32
fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce()
where
- G: Get<T>
+ G: Get<T>,
{
move || {
+ //~^ ERROR hidden type for `impl Trait` captures lifetime
*dest = g.get();
}
}
// After applying suggestion for `foo`:
fn bar<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+//~^ ERROR the parameter type `G` may not live long enough
where
- G: Get<T>
+ G: Get<T>,
{
+ //~^ ERROR the parameter type `G` may not live long enough
move || {
*dest = g.get();
}
}
-
// After applying suggestion for `bar`:
-fn baz<G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ //~ ERROR undeclared lifetime
+fn baz<G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+//~^ ERROR undeclared lifetime name `'a`
where
- G: Get<T>
+ G: Get<T>,
{
move || {
*dest = g.get();
// After applying suggestion for `baz`:
fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+//~^ ERROR the parameter type `G` may not live long enough
where
- G: Get<T>
+ G: Get<T>,
{
+ //~^ ERROR the parameter type `G` may not live long enough
move || {
*dest = g.get();
}
// Same as above, but show that we pay attention to lifetime names from parent item
impl<'a> Foo {
fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ {
+ //~^ ERROR the parameter type `G` may not live long enough
+ //~| ERROR the parameter type `G` may not live long enough
move || {
*dest = g.get();
}
// After applying suggestion for `qux`:
fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
+//~^ ERROR explicit lifetime required in the type of `dest`
where
- G: Get<T>
+ G: Get<T>,
{
move || {
*dest = g.get();
// Potential incorrect attempt:
fn bak<'a, G, T>(g: G, dest: &'a mut T) -> impl FnOnce() + 'a
+//~^ ERROR the parameter type `G` may not live long enough
where
- G: Get<T>
+ G: Get<T>,
{
+ //~^ ERROR the parameter type `G` may not live long enough
move || {
*dest = g.get();
}
}
-
// We need to tie the lifetime of `G` with the lifetime of `&mut T` and the returned closure:
fn ok<'a, G: 'a, T>(g: G, dest: &'a mut T) -> impl FnOnce() + 'a
where
- G: Get<T>
+ G: Get<T>,
{
move || {
*dest = g.get();
// This also works. The `'_` isn't necessary but it's where we arrive to following the suggestions:
fn ok2<'a, G: 'a, T>(g: G, dest: &'a mut T) -> impl FnOnce() + '_ + 'a
where
- G: Get<T>
+ G: Get<T>,
{
move || {
*dest = g.get();
error[E0261]: use of undeclared lifetime name `'a`
- --> $DIR/missing-lifetimes-in-signature.rs:36:11
+ --> $DIR/missing-lifetimes-in-signature.rs:38:11
|
LL | fn baz<G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
| - ^^ undeclared lifetime
| |
| help: consider introducing lifetime `'a` here: `'a,`
-error: aborting due to previous error
+error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
+ --> $DIR/missing-lifetimes-in-signature.rs:19:5
+ |
+LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce()
+ | ------ hidden type `[closure@$DIR/missing-lifetimes-in-signature.rs:19:5: 22:6]` captures the anonymous lifetime defined here
+...
+LL | / move || {
+LL | |
+LL | | *dest = g.get();
+LL | | }
+ | |_____^
+ |
+help: to declare that the `impl Trait` captures `'_`, you can add an explicit `'_` lifetime bound
+ |
+LL | fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+ | ++++
+
+error[E0311]: the parameter type `G` may not live long enough
+ --> $DIR/missing-lifetimes-in-signature.rs:26:37
+ |
+LL | fn bar<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+ | ^^^^^^^^^^^^^^^^^^
+ |
+note: the parameter type `G` must be valid for the anonymous lifetime defined here...
+ --> $DIR/missing-lifetimes-in-signature.rs:26:26
+ |
+LL | fn bar<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+ | ^^^^^^
+note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:32:5: 34:6]` will meet its required lifetime bounds
+ --> $DIR/missing-lifetimes-in-signature.rs:26:37
+ |
+LL | fn bar<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+ | ^^^^^^^^^^^^^^^^^^
+help: consider introducing an explicit lifetime bound
+ |
+LL | fn bar<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
+ | ~~~~~ ++++
+
+error[E0311]: the parameter type `G` may not live long enough
+ --> $DIR/missing-lifetimes-in-signature.rs:30:1
+ |
+LL | / {
+LL | |
+LL | | move || {
+LL | | *dest = g.get();
+LL | | }
+LL | | }
+ | |_^
+ |
+note: the parameter type `G` must be valid for the anonymous lifetime defined here...
+ --> $DIR/missing-lifetimes-in-signature.rs:26:26
+ |
+LL | fn bar<G, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+ | ^^^^^^
+note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:32:5: 34:6]` will meet its required lifetime bounds
+ --> $DIR/missing-lifetimes-in-signature.rs:30:1
+ |
+LL | / {
+LL | |
+LL | | move || {
+LL | | *dest = g.get();
+LL | | }
+LL | | }
+ | |_^
+help: consider introducing an explicit lifetime bound
+ |
+LL ~ fn bar<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+LL |
+LL | where
+LL | G: Get<T>,
+LL | {
+LL |
+ ...
+
+error[E0311]: the parameter type `G` may not live long enough
+ --> $DIR/missing-lifetimes-in-signature.rs:49:45
+ |
+LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+ | ^^^^^^^^^^^^^^^^^^
+ |
+note: the parameter type `G` must be valid for the anonymous lifetime defined here...
+ --> $DIR/missing-lifetimes-in-signature.rs:49:34
+ |
+LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+ | ^^^^^^
+note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:55:5: 57:6]` will meet its required lifetime bounds
+ --> $DIR/missing-lifetimes-in-signature.rs:49:45
+ |
+LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+ | ^^^^^^^^^^^^^^^^^^
+help: consider introducing an explicit lifetime bound
+ |
+LL | fn qux<'b, 'a, G: 'b + 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'b
+ | +++ ~~~~~~~ ++++
+
+error[E0311]: the parameter type `G` may not live long enough
+ --> $DIR/missing-lifetimes-in-signature.rs:53:1
+ |
+LL | / {
+LL | |
+LL | | move || {
+LL | | *dest = g.get();
+LL | | }
+LL | | }
+ | |_^
+ |
+note: the parameter type `G` must be valid for the anonymous lifetime defined here...
+ --> $DIR/missing-lifetimes-in-signature.rs:49:34
+ |
+LL | fn qux<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+ | ^^^^^^
+note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:55:5: 57:6]` will meet its required lifetime bounds
+ --> $DIR/missing-lifetimes-in-signature.rs:53:1
+ |
+LL | / {
+LL | |
+LL | | move || {
+LL | | *dest = g.get();
+LL | | }
+LL | | }
+ | |_^
+help: consider introducing an explicit lifetime bound
+ |
+LL ~ fn qux<'b, 'a, G: 'b + 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_
+LL |
+LL | where
+LL | G: Get<T>,
+LL | {
+LL |
+ ...
+
+error[E0311]: the parameter type `G` may not live long enough
+ --> $DIR/missing-lifetimes-in-signature.rs:62:58
+ |
+LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ {
+ | ^^^^^^^^^^^^^^^^^^
+ |
+note: the parameter type `G` must be valid for the anonymous lifetime defined here...
+ --> $DIR/missing-lifetimes-in-signature.rs:62:47
+ |
+LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ {
+ | ^^^^^^
+note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:65:9: 67:10]` will meet its required lifetime bounds
+ --> $DIR/missing-lifetimes-in-signature.rs:62:58
+ |
+LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ {
+ | ^^^^^^^^^^^^^^^^^^
+help: consider introducing an explicit lifetime bound
+ |
+LL | fn qux<'c, 'b, G: 'c + Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'c {
+ | +++ ~~~~~~~ ++++
+
+error[E0311]: the parameter type `G` may not live long enough
+ --> $DIR/missing-lifetimes-in-signature.rs:62:77
+ |
+LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ {
+ | _____________________________________________________________________________^
+LL | |
+LL | |
+LL | | move || {
+LL | | *dest = g.get();
+LL | | }
+LL | | }
+ | |_____^
+ |
+note: the parameter type `G` must be valid for the anonymous lifetime defined here...
+ --> $DIR/missing-lifetimes-in-signature.rs:62:47
+ |
+LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ {
+ | ^^^^^^
+note: ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:65:9: 67:10]` will meet its required lifetime bounds
+ --> $DIR/missing-lifetimes-in-signature.rs:62:77
+ |
+LL | fn qux<'b, G: Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ {
+ | _____________________________________________________________________________^
+LL | |
+LL | |
+LL | | move || {
+LL | | *dest = g.get();
+LL | | }
+LL | | }
+ | |_____^
+help: consider introducing an explicit lifetime bound
+ |
+LL ~ fn qux<'c, 'b, G: 'c + Get<T> + 'b, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ {
+LL |
+LL |
+LL | move || {
+LL | *dest = g.get();
+LL | }
+ ...
+
+error[E0621]: explicit lifetime required in the type of `dest`
+ --> $DIR/missing-lifetimes-in-signature.rs:72:45
+ |
+LL | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
+ | ------ ^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
+ | |
+ | help: add explicit lifetime `'a` to the type of `dest`: `&'a mut T`
+
+error[E0309]: the parameter type `G` may not live long enough
+ --> $DIR/missing-lifetimes-in-signature.rs:83:44
+ |
+LL | fn bak<'a, G, T>(g: G, dest: &'a mut T) -> impl FnOnce() + 'a
+ | - ^^^^^^^^^^^^^^^^^^ ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:89:5: 91:6]` will meet its required lifetime bounds
+ | |
+ | help: consider adding an explicit lifetime bound...: `G: 'a`
+
+error[E0309]: the parameter type `G` may not live long enough
+ --> $DIR/missing-lifetimes-in-signature.rs:87:1
+ |
+LL | fn bak<'a, G, T>(g: G, dest: &'a mut T) -> impl FnOnce() + 'a
+ | - help: consider adding an explicit lifetime bound...: `G: 'a`
+...
+LL | / {
+LL | |
+LL | | move || {
+LL | | *dest = g.get();
+LL | | }
+LL | | }
+ | |_^ ...so that the type `[closure@$DIR/missing-lifetimes-in-signature.rs:89:5: 91:6]` will meet its required lifetime bounds
+
+error: aborting due to 11 previous errors
-For more information about this error, try `rustc --explain E0261`.
+Some errors have detailed explanations: E0261, E0309, E0621, E0700.
+For more information about an error, try `rustc --explain E0261`.
//~^ ERROR use of undeclared lifetime name `'a`
fn my_fun() -> Return<()> {}
+//~^ ERROR non-defining opaque type use in defining scope
+//~| ERROR non-defining opaque type use in defining scope
fn main() {}
--> $DIR/issue-69136-inner-lifetime-resolve-error.rs:17:65
|
LL | type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;
- | - ^^ undeclared lifetime
- | |
- | help: consider introducing lifetime `'a` here: `'a,`
+ | ^^ undeclared lifetime
+ |
+ = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
+help: consider making the bound lifetime-generic with a new `'a` lifetime
+ |
+LL | type Return<A> = impl for<'a> WithAssoc<A, AssocType = impl SomeTrait + 'a>;
+ | +++++++
+help: consider introducing lifetime `'a` here
+ |
+LL | type Return<'a, A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;
+ | +++
+
+error: non-defining opaque type use in defining scope
+ --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:20:27
+ |
+LL | fn my_fun() -> Return<()> {}
+ | ^^
+ |
+note: used non-generic type `()` for generic parameter
+ --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:17:13
+ |
+LL | type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;
+ | ^
+
+error: non-defining opaque type use in defining scope
+ --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:20:27
+ |
+LL | fn my_fun() -> Return<()> {}
+ | ^^
+ |
+note: used non-generic type `()` for generic parameter
+ --> $DIR/issue-69136-inner-lifetime-resolve-error.rs:17:13
+ |
+LL | type Return<A> = impl WithAssoc<A, AssocType = impl SomeTrait + 'a>;
+ | ^
-error: aborting due to previous error
+error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0261`.
//~^ ERROR `'_` cannot be used here
struct Struct<'_> {
-//~^ ERROR `'_` cannot be used here
+ //~^ ERROR `'_` cannot be used here
v: Vec<&'static char>
}
enum Enum<'_> {
-//~^ ERROR `'_` cannot be used here
+ //~^ ERROR `'_` cannot be used here
Variant
}
union Union<'_> {
-//~^ ERROR `'_` cannot be used here
+ //~^ ERROR `'_` cannot be used here
a: u32
}
trait Trait<'_> {
-//~^ ERROR `'_` cannot be used here
+ //~^ ERROR `'_` cannot be used here
}
fn foo<'_>() {
error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/where-lifetime-resolution.rs:6:38
|
-LL | fn f() where
- | - help: consider introducing lifetime `'a` here: `<'a>`
-LL | for<'a> dyn Trait1<'a>: Trait1<'a>, // OK
LL | (dyn for<'a> Trait1<'a>): Trait1<'a>,
| ^^ undeclared lifetime
+ |
+ = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
+help: consider making the bound lifetime-generic with a new `'a` lifetime
+ |
+LL | (dyn for<'a> Trait1<'a>): for<'a> Trait1<'a>,
+ | +++++++
+help: consider making the bound lifetime-generic with a new `'a` lifetime
+ |
+LL | for<'a> (dyn for<'a> Trait1<'a>): Trait1<'a>,
+ | +++++++
+help: consider introducing lifetime `'a` here
+ |
+LL | fn f<'a>() where
+ | ++++
error[E0261]: use of undeclared lifetime name `'b`
--> $DIR/where-lifetime-resolution.rs:8:52
|
-LL | fn f() where
- | - help: consider introducing lifetime `'b` here: `<'b>`
-...
LL | for<'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>,
| ^^ undeclared lifetime
+ |
+help: consider making the bound lifetime-generic with a new `'b` lifetime
+ |
+LL | for<'a> dyn for<'b> Trait2<'a, 'b>: for<'b> Trait2<'a, 'b>,
+ | +++++++
+help: consider making the bound lifetime-generic with a new `'b` lifetime
+ |
+LL | for<'b, 'a> dyn for<'b> Trait2<'a, 'b>: Trait2<'a, 'b>,
+ | +++
+help: consider introducing lifetime `'b` here
+ |
+LL | fn f<'b>() where
+ | ++++
error: aborting due to 2 previous errors