forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#98184 - compiler-errors:elided-lifetime-in-…
…impl-nll, r=cjgillot Give name if anonymous region appears in impl signature Fixes rust-lang#98170 We probably should remove the two unwraps in [`report_general_error`](https://doc.rust-lang.org/nightly/nightly-rustc/src/rustc_borrowck/diagnostics/region_errors.rs.html#683-685), but I have no idea what to provide if those regions are missing, so I've kept those in. Let me know if I should try harder to remove those.
- Loading branch information
Showing
4 changed files
with
125 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
pub struct MyStruct<'a> { | ||
field: &'a [u32], | ||
} | ||
|
||
impl MyStruct<'_> { | ||
pub fn new<'a>(field: &'a [u32]) -> MyStruct<'a> { | ||
Self { field } | ||
//~^ ERROR lifetime may not live long enough | ||
//~| ERROR lifetime may not live long enough | ||
} | ||
} | ||
|
||
trait Trait<'a> { | ||
fn new(field: &'a [u32]) -> MyStruct<'a>; | ||
} | ||
|
||
impl<'a> Trait<'a> for MyStruct<'_> { | ||
fn new(field: &'a [u32]) -> MyStruct<'a> { | ||
Self { field } | ||
//~^ ERROR lifetime may not live long enough | ||
//~| ERROR lifetime may not live long enough | ||
} | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
error: lifetime may not live long enough | ||
--> $DIR/issue-98170.rs:7:9 | ||
| | ||
LL | impl MyStruct<'_> { | ||
| -- lifetime `'1` appears in the `impl`'s self type | ||
LL | pub fn new<'a>(field: &'a [u32]) -> MyStruct<'a> { | ||
| -- lifetime `'a` defined here | ||
LL | Self { field } | ||
| ^^^^^^^^^^^^^^ associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/issue-98170.rs:7:16 | ||
| | ||
LL | impl MyStruct<'_> { | ||
| -- lifetime `'1` appears in the `impl`'s self type | ||
LL | pub fn new<'a>(field: &'a [u32]) -> MyStruct<'a> { | ||
| -- lifetime `'a` defined here | ||
LL | Self { field } | ||
| ^^^^^ this usage requires that `'a` must outlive `'1` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/issue-98170.rs:19:9 | ||
| | ||
LL | impl<'a> Trait<'a> for MyStruct<'_> { | ||
| -- -- lifetime `'1` appears in the `impl`'s self type | ||
| | | ||
| lifetime `'a` defined here | ||
LL | fn new(field: &'a [u32]) -> MyStruct<'a> { | ||
LL | Self { field } | ||
| ^^^^^^^^^^^^^^ associated function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'1` | ||
|
||
error: lifetime may not live long enough | ||
--> $DIR/issue-98170.rs:19:16 | ||
| | ||
LL | impl<'a> Trait<'a> for MyStruct<'_> { | ||
| -- -- lifetime `'1` appears in the `impl`'s self type | ||
| | | ||
| lifetime `'a` defined here | ||
LL | fn new(field: &'a [u32]) -> MyStruct<'a> { | ||
LL | Self { field } | ||
| ^^^^^ this usage requires that `'a` must outlive `'1` | ||
|
||
error: aborting due to 4 previous errors | ||
|