Skip to content

Do not recover missing lifetime with random in-scope lifetime #137912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<_> =
Expand Down
1 change: 0 additions & 1 deletion tests/ui/async-await/issues/issue-63388-2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ impl Xyz {
) -> &dyn Foo //~ ERROR missing lifetime specifier
{
foo
//~^ ERROR explicit lifetime required in the type of `foo` [E0621]
}
}

Expand Down
14 changes: 2 additions & 12 deletions tests/ui/async-await/issues/issue-63388-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 2 previous errors
error: aborting due to 1 previous error

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`.
2 changes: 0 additions & 2 deletions tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
42 changes: 7 additions & 35 deletions tests/ui/impl-trait/in-trait/opaque-and-lifetime-mismatch.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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`.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion tests/ui/impl-trait/precise-capturing/bad-lifetimes.rs
Original file line number Diff line number Diff line change
@@ -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`
Expand Down
12 changes: 3 additions & 9 deletions tests/ui/impl-trait/precise-capturing/bad-lifetimes.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
1 change: 0 additions & 1 deletion tests/ui/issues/issue-13497.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
14 changes: 2 additions & 12 deletions tests/ui/issues/issue-13497.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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 2 previous errors
error: aborting due to 1 previous error

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`.
1 change: 0 additions & 1 deletion tests/ui/lifetimes/issue-26638.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!() }
Expand Down
17 changes: 3 additions & 14 deletions tests/ui/lifetimes/issue-26638.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 5 previous errors
error: aborting due to 4 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`.
Original file line number Diff line number Diff line change
@@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 2 previous errors
error: aborting due to 1 previous error

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`.
2 changes: 0 additions & 2 deletions tests/ui/suggestions/impl-trait-missing-lifetime-gated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
Loading
Loading