1
Fork 0

Do not recover missing lifetime with random in-scope lifetime

This commit is contained in:
Michael Goulet 2025-03-03 05:14:52 +00:00
parent daf59857d6
commit 0ad48b47e6
20 changed files with 36 additions and 180 deletions

View file

@ -3515,12 +3515,6 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
}
}
}
// Record as using the suggested resolution.
let (_, (_, res)) = in_scope_lifetimes[0];
for &lt in &lifetime_refs {
self.r.lifetimes_res_map.insert(lt.id, res);
}
}
_ => {
let lifetime_spans: Vec<_> =

View file

@ -12,7 +12,6 @@ impl Xyz {
) -> &dyn Foo //~ ERROR missing lifetime specifier
{
foo
//~^ ERROR explicit lifetime required in the type of `foo` [E0621]
}
}

View file

@ -12,16 +12,6 @@ help: consider using the `'a` lifetime
LL | ) -> &'a dyn Foo
| ++
error[E0621]: explicit lifetime required in the type of `foo`
--> $DIR/issue-63388-2.rs:14:9
|
LL | foo: &dyn Foo, bar: &'a dyn Foo
| -------- help: add explicit lifetime `'a` to the type of `foo`: `&'a (dyn Foo + 'a)`
...
LL | foo
| ^^^ lifetime `'a` required
error: aborting due to 1 previous error
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0106, E0621.
For more information about an error, try `rustc --explain E0106`.
For more information about this error, try `rustc --explain E0106`.

View file

@ -8,8 +8,6 @@ trait Foo {
impl Foo for () {
fn bar() -> i32 {
//~^ ERROR method `bar` has an incompatible type for trait
//~| ERROR method `bar` has an incompatible return type for trait
0
}
}

View file

@ -11,7 +11,7 @@ LL | fn bar() -> Wrapper<'static, impl Sized>;
| ++++++++
error[E0106]: missing lifetime specifier
--> $DIR/opaque-and-lifetime-mismatch.rs:18:24
--> $DIR/opaque-and-lifetime-mismatch.rs:16:24
|
LL | fn foo() -> Wrapper<impl Sized>;
| ^ expected named lifetime parameter
@ -23,7 +23,7 @@ LL | fn foo() -> Wrapper<'static, impl Sized>;
| ++++++++
error[E0106]: missing lifetime specifier
--> $DIR/opaque-and-lifetime-mismatch.rs:24:24
--> $DIR/opaque-and-lifetime-mismatch.rs:22:24
|
LL | fn foo() -> Wrapper<impl Sized> {
| ^ expected named lifetime parameter
@ -49,7 +49,7 @@ LL | struct Wrapper<'rom>(&'rom ());
| ^^^^^^^
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/opaque-and-lifetime-mismatch.rs:18:17
--> $DIR/opaque-and-lifetime-mismatch.rs:16:17
|
LL | fn foo() -> Wrapper<impl Sized>;
| ^^^^^^^ ---------- help: remove the unnecessary generic argument
@ -62,36 +62,8 @@ note: struct defined here, with 0 generic parameters
LL | struct Wrapper<'rom>(&'rom ());
| ^^^^^^^
error[E0053]: method `bar` has an incompatible return type for trait
--> $DIR/opaque-and-lifetime-mismatch.rs:10:17
|
LL | fn bar() -> i32 {
| ^^^
| |
| expected `Wrapper<'static>`, found `i32`
| return type in trait
error[E0053]: method `bar` has an incompatible type for trait
--> $DIR/opaque-and-lifetime-mismatch.rs:10:17
|
LL | fn bar() -> i32 {
| ^^^ expected `Wrapper<'static>`, found `i32`
|
note: type in trait
--> $DIR/opaque-and-lifetime-mismatch.rs:4:17
|
LL | fn bar() -> Wrapper<impl Sized>;
| ^^^^^^^^^^^^^^^^^^^
= note: expected signature `fn() -> Wrapper<'static>`
found signature `fn() -> i32`
help: change the output type to match the trait
|
LL - fn bar() -> i32 {
LL + fn bar() -> Wrapper<'static> {
|
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/opaque-and-lifetime-mismatch.rs:24:17
--> $DIR/opaque-and-lifetime-mismatch.rs:22:17
|
LL | fn foo() -> Wrapper<impl Sized> {
| ^^^^^^^ ---------- help: remove the unnecessary generic argument
@ -104,7 +76,7 @@ note: struct defined here, with 0 generic parameters
LL | struct Wrapper<'rom>(&'rom ());
| ^^^^^^^
error: aborting due to 8 previous errors
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0053, E0106, E0107.
For more information about an error, try `rustc --explain E0053`.
Some errors have detailed explanations: E0106, E0107.
For more information about an error, try `rustc --explain E0106`.

View file

@ -75,7 +75,7 @@ error[E0061]: this function takes 0 arguments but 1 argument was supplied
--> $DIR/opaque-used-in-extraneous-argument.rs:20:5
|
LL | open_parent(&old_path)
| ^^^^^^^^^^^ --------- unexpected argument of type `&impl Fn<{type error}> + FnOnce<{type error}, Output = {type error}> + 'static`
| ^^^^^^^^^^^ --------- unexpected argument of type `&impl Fn<{type error}> + FnOnce<{type error}, Output = {type error}> + '_`
|
note: function defined here
--> $DIR/opaque-used-in-extraneous-argument.rs:12:4

View file

@ -1,6 +1,5 @@
fn no_elided_lt() -> impl Sized + use<'_> {}
//~^ ERROR missing lifetime specifier
//~| ERROR expected lifetime parameter in `use<...>` precise captures list, found `'_`
fn static_lt() -> impl Sized + use<'static> {}
//~^ ERROR expected lifetime parameter in `use<...>` precise captures list, found `'static`

View file

@ -12,26 +12,20 @@ LL + fn no_elided_lt() -> impl Sized + use<'static> {}
|
error[E0261]: use of undeclared lifetime name `'missing`
--> $DIR/bad-lifetimes.rs:8:37
--> $DIR/bad-lifetimes.rs:7:37
|
LL | fn missing_lt() -> impl Sized + use<'missing> {}
| - ^^^^^^^^ undeclared lifetime
| |
| help: consider introducing lifetime `'missing` here: `<'missing>`
error: expected lifetime parameter in `use<...>` precise captures list, found `'_`
--> $DIR/bad-lifetimes.rs:1:39
|
LL | fn no_elided_lt() -> impl Sized + use<'_> {}
| ^^
error: expected lifetime parameter in `use<...>` precise captures list, found `'static`
--> $DIR/bad-lifetimes.rs:5:36
--> $DIR/bad-lifetimes.rs:4:36
|
LL | fn static_lt() -> impl Sized + use<'static> {}
| ^^^^^^^
error: aborting due to 4 previous errors
error: aborting due to 3 previous errors
Some errors have detailed explanations: E0106, E0261.
For more information about an error, try `rustc --explain E0106`.

View file

@ -3,7 +3,6 @@ fn read_lines_borrowed1() -> Vec<
> {
let rawLines: Vec<String> = vec!["foo ".to_string(), " bar".to_string()];
rawLines.iter().map(|l| l.trim()).collect()
//~^ ERROR: cannot return value referencing
}
fn main() {}

View file

@ -15,16 +15,6 @@ LL - &str
LL + String
|
error[E0515]: cannot return value referencing local variable `rawLines`
--> $DIR/issue-13497.rs:5:5
|
LL | rawLines.iter().map(|l| l.trim()).collect()
| --------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| returns a value referencing data owned by the current function
| `rawLines` is borrowed here
error: aborting due to 1 previous error
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0106, E0515.
For more information about an error, try `rustc --explain E0106`.
For more information about this error, try `rustc --explain E0106`.

View file

@ -3,7 +3,6 @@ fn parse_type(iter: Box<dyn Iterator<Item=&str>+'static>) -> &str { iter.next()
fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() }
//~^ ERROR missing lifetime specifier [E0106]
//~| ERROR mismatched types
//~| ERROR function takes 1 argument but 0 arguments were supplied
fn parse_type_3() -> &str { unimplemented!() }

View file

@ -32,7 +32,7 @@ LL + fn parse_type_2(iter: fn(&u8)->&u8) -> String { iter() }
|
error[E0106]: missing lifetime specifier
--> $DIR/issue-26638.rs:9:22
--> $DIR/issue-26638.rs:8:22
|
LL | fn parse_type_3() -> &str { unimplemented!() }
| ^ expected named lifetime parameter
@ -59,18 +59,7 @@ help: provide the argument
LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter(/* &u8 */) }
| +++++++++
error[E0308]: mismatched types
--> $DIR/issue-26638.rs:4:47
|
LL | fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() }
| ---- ^^^^^^ expected `&str`, found `&u8`
| |
| expected `&'static str` because of return type
|
= note: expected reference `&'static str`
found reference `&u8`
error: aborting due to 4 previous errors
error: aborting due to 5 previous errors
Some errors have detailed explanations: E0061, E0106, E0308.
Some errors have detailed explanations: E0061, E0106.
For more information about an error, try `rustc --explain E0061`.

View file

@ -1,5 +1,5 @@
#![feature(default_field_values)]
struct A<'a> { //~ ERROR lifetime parameter `'a` is never used
struct A<'a> {
x: Vec<A> = Vec::new(), //~ ERROR missing lifetime specifier
}

View file

@ -9,15 +9,6 @@ help: consider using the `'a` lifetime
LL | x: Vec<A<'a>> = Vec::new(),
| ++++
error[E0392]: lifetime parameter `'a` is never used
--> $DIR/do-not-ice-on-invalid-lifetime.rs:2:10
|
LL | struct A<'a> {
| ^^ unused lifetime parameter
|
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData`
error: aborting due to 1 previous error
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0106, E0392.
For more information about an error, try `rustc --explain E0106`.
For more information about this error, try `rustc --explain E0106`.

View file

@ -18,7 +18,6 @@ mod elided {
// But that lifetime does not participate in resolution.
async fn i(mut x: impl Iterator<Item = &()>) -> Option<&()> { x.next() }
//~^ ERROR missing lifetime specifier
//~| ERROR lifetime may not live long enough
}
mod underscore {
@ -37,7 +36,6 @@ mod underscore {
// But that lifetime does not participate in resolution.
async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
//~^ ERROR missing lifetime specifier
//~| ERROR lifetime may not live long enough
}
mod alone_in_path {

View file

@ -41,7 +41,7 @@ LL + async fn i(mut x: impl Iterator<Item = &()>) -> Option<()> { x.next() }
|
error[E0106]: missing lifetime specifier
--> $DIR/impl-trait-missing-lifetime-gated.rs:28:58
--> $DIR/impl-trait-missing-lifetime-gated.rs:27:58
|
LL | fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
| ^^ expected named lifetime parameter
@ -64,7 +64,7 @@ LL + fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<()> { x.next() }
|
error[E0106]: missing lifetime specifier
--> $DIR/impl-trait-missing-lifetime-gated.rs:38:64
--> $DIR/impl-trait-missing-lifetime-gated.rs:37:64
|
LL | async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
| ^^ expected named lifetime parameter
@ -87,7 +87,7 @@ LL + async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<()> { x.next(
|
error[E0106]: missing lifetime specifier
--> $DIR/impl-trait-missing-lifetime-gated.rs:49:37
--> $DIR/impl-trait-missing-lifetime-gated.rs:47:37
|
LL | fn g(mut x: impl Foo) -> Option<&()> { x.next() }
| ^ expected named lifetime parameter
@ -108,7 +108,7 @@ LL + fn g(mut x: impl Foo) -> Option<()> { x.next() }
|
error[E0106]: missing lifetime specifier
--> $DIR/impl-trait-missing-lifetime-gated.rs:60:41
--> $DIR/impl-trait-missing-lifetime-gated.rs:58:41
|
LL | fn g(mut x: impl Foo<()>) -> Option<&()> { x.next() }
| ^ expected named lifetime parameter
@ -129,7 +129,7 @@ LL + fn g(mut x: impl Foo<()>) -> Option<()> { x.next() }
|
warning: elided lifetime has a name
--> $DIR/impl-trait-missing-lifetime-gated.rs:66:57
--> $DIR/impl-trait-missing-lifetime-gated.rs:64:57
|
LL | fn resolved_anonymous<'a, T: 'a>(f: impl Fn(&'a str) -> &T) {
| -- lifetime `'a` declared here ^ this elided lifetime gets resolved as `'a`
@ -162,16 +162,8 @@ help: consider introducing a named lifetime parameter
LL | fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&()> { x.next() }
| ++++ ++
error: lifetime may not live long enough
--> $DIR/impl-trait-missing-lifetime-gated.rs:19:67
|
LL | async fn i(mut x: impl Iterator<Item = &()>) -> Option<&()> { x.next() }
| ----------------------------------------------------------- ^^^^^^^^ returning this value requires that `'1` must outlive `'static`
| |
| return type `impl Future<Output = Option<&'static ()>>` contains a lifetime `'1`
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
--> $DIR/impl-trait-missing-lifetime-gated.rs:25:35
--> $DIR/impl-trait-missing-lifetime-gated.rs:24:35
|
LL | fn f(_: impl Iterator<Item = &'_ ()>) {}
| ^^ expected named lifetime parameter
@ -185,7 +177,7 @@ LL + fn f<'a>(_: impl Iterator<Item = &'a ()>) {}
|
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
--> $DIR/impl-trait-missing-lifetime-gated.rs:28:39
--> $DIR/impl-trait-missing-lifetime-gated.rs:27:39
|
LL | fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
| ^^ expected named lifetime parameter
@ -198,16 +190,8 @@ LL - fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next()
LL + fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'_ ()> { x.next() }
|
error: lifetime may not live long enough
--> $DIR/impl-trait-missing-lifetime-gated.rs:38:73
|
LL | async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
| ----------------------------------------------------------------- ^^^^^^^^ returning this value requires that `'1` must outlive `'static`
| |
| return type `impl Future<Output = Option<&'static ()>>` contains a lifetime `'1`
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
--> $DIR/impl-trait-missing-lifetime-gated.rs:46:18
--> $DIR/impl-trait-missing-lifetime-gated.rs:44:18
|
LL | fn f(_: impl Foo) {}
| ^^^ expected named lifetime parameter
@ -220,7 +204,7 @@ LL | fn f<'a>(_: impl Foo<'a>) {}
| ++++ ++++
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
--> $DIR/impl-trait-missing-lifetime-gated.rs:49:22
--> $DIR/impl-trait-missing-lifetime-gated.rs:47:22
|
LL | fn g(mut x: impl Foo) -> Option<&()> { x.next() }
| ^^^ expected named lifetime parameter
@ -233,7 +217,7 @@ LL | fn g<'a>(mut x: impl Foo<'a>) -> Option<&()> { x.next() }
| ++++ ++++
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
--> $DIR/impl-trait-missing-lifetime-gated.rs:57:22
--> $DIR/impl-trait-missing-lifetime-gated.rs:55:22
|
LL | fn f(_: impl Foo<()>) {}
| ^ expected named lifetime parameter
@ -246,7 +230,7 @@ LL | fn f<'a>(_: impl Foo<'a, ()>) {}
| ++++ +++
error[E0658]: anonymous lifetimes in `impl Trait` are unstable
--> $DIR/impl-trait-missing-lifetime-gated.rs:60:26
--> $DIR/impl-trait-missing-lifetime-gated.rs:58:26
|
LL | fn g(mut x: impl Foo<()>) -> Option<&()> { x.next() }
| ^ expected named lifetime parameter
@ -258,7 +242,7 @@ help: consider introducing a named lifetime parameter
LL | fn g<'a>(mut x: impl Foo<'a, ()>) -> Option<&()> { x.next() }
| ++++ +++
error: aborting due to 16 previous errors; 1 warning emitted
error: aborting due to 14 previous errors; 1 warning emitted
Some errors have detailed explanations: E0106, E0658.
For more information about an error, try `rustc --explain E0106`.

View file

@ -8,7 +8,6 @@ fn f(_: impl Iterator<Item = &'_ ()>) {}
// But that lifetime does not participate in resolution.
fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
//~^ ERROR missing lifetime specifier
//~| ERROR lifetime may not live long enough
// This is understood as `fn foo<'_1>(_: impl Iterator<Item = &'_1 ()>) {}`.
async fn h(_: impl Iterator<Item = &'_ ()>) {}
@ -16,6 +15,5 @@ async fn h(_: impl Iterator<Item = &'_ ()>) {}
// But that lifetime does not participate in resolution.
async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
//~^ ERROR missing lifetime specifier
//~| ERROR lifetime may not live long enough
fn main() {}

View file

@ -22,7 +22,7 @@ LL + fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<()> { x.next() }
|
error[E0106]: missing lifetime specifier
--> $DIR/impl-trait-missing-lifetime.rs:17:60
--> $DIR/impl-trait-missing-lifetime.rs:16:60
|
LL | async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
| ^^ expected named lifetime parameter
@ -44,20 +44,6 @@ LL - async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next(
LL + async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<()> { x.next() }
|
error: lifetime may not live long enough
--> $DIR/impl-trait-missing-lifetime.rs:17:69
|
LL | async fn i(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
| ----------------------------------------------------------------- ^^^^^^^^ returning this value requires that `'1` must outlive `'static`
| |
| return type `impl Future<Output = Option<&'static ()>>` contains a lifetime `'1`
error: lifetime may not live long enough
--> $DIR/impl-trait-missing-lifetime.rs:9:63
|
LL | fn g(mut x: impl Iterator<Item = &'_ ()>) -> Option<&'_ ()> { x.next() }
| ----- has type `x` ^^^^^^^^ returning this value requires that `'1` must outlive `'static`
error: aborting due to 4 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0106`.

View file

@ -8,8 +8,6 @@ fn main() {
let x = S(&|x| {
println!("hi");
x
//~^ ERROR lifetime may not live long enough
//~| ERROR lifetime may not live long enough
});
x.0(&X(&()));
}

View file

@ -31,28 +31,6 @@ help: consider using one of the available lifetimes here
LL | struct V<'a>(&'a dyn for<'b> Fn(&X) -> &'lifetime X<'lifetime>);
| +++++++++ +++++++++++
error: lifetime may not live long enough
--> $DIR/missing-lt-for-hrtb.rs:10:9
|
LL | let x = S(&|x| {
| -- return type of closure is &'2 X<'_>
| |
| has type `&'1 X<'_>`
LL | println!("hi");
LL | x
| ^ returning this value requires that `'1` must outlive `'2`
error: lifetime may not live long enough
--> $DIR/missing-lt-for-hrtb.rs:10:9
|
LL | let x = S(&|x| {
| -- return type of closure is &X<'4>
| |
| has type `&X<'3>`
LL | println!("hi");
LL | x
| ^ returning this value requires that `'3` must outlive `'4`
error: aborting due to 4 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0106`.