forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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#128172 - compiler-errors:non-self-arg, r=chenyukang Don't ICE if HIR and middle types disagree in borrowck error reporting We try to match up the `middle::ty::Ty` and `hir::Ty` types in borrowck error reporting, but due to things like `Self` self type alias, or regular type aliases, these might not match up. Don't ICE. This PR also tries to recover the error by looking up the self type of the impl in case we see `Self`. The diagnostic is frankly quite confusing, but I also didn't really want to look at it because I don't understand the conflict error reporting logic. 🤷 Fixes rust-lang#121816
- Loading branch information
Showing
4 changed files
with
81 additions
and
20 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 was deleted.
Oops, something went wrong.
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,19 @@ | ||
// Don't ICE when trying to annotate signature and we see `&()` | ||
|
||
fn f<'a, T>(_: &'static &'a (), x: &'a T) -> &'static T { | ||
x | ||
} | ||
trait W<'a> { | ||
fn g<T>(self, x: &'a T) -> &'static T; | ||
} | ||
|
||
// Frankly this error message is impossible to parse, but :shrug:. | ||
impl<'a> W<'a> for &'static () { | ||
fn g<T>(self, x: &'a T) -> &'static T { | ||
f(&self, x) | ||
//~^ ERROR borrowed data escapes outside of method | ||
//~| ERROR `self` does 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,36 @@ | ||
error[E0521]: borrowed data escapes outside of method | ||
--> $DIR/ice-on-non-ref-sig-ty.rs:13:9 | ||
| | ||
LL | impl<'a> W<'a> for &'static () { | ||
| -- lifetime `'a` defined here | ||
LL | fn g<T>(self, x: &'a T) -> &'static T { | ||
| ---- - `x` is a reference that is only valid in the method body | ||
| | | ||
| `self` declared here, outside of the method body | ||
LL | f(&self, x) | ||
| ^^^^^^^^^^^ | ||
| | | ||
| `x` escapes the method body here | ||
| argument requires that `'a` must outlive `'static` | ||
|
||
error[E0597]: `self` does not live long enough | ||
--> $DIR/ice-on-non-ref-sig-ty.rs:13:11 | ||
| | ||
LL | impl<'a> W<'a> for &'static () { | ||
| ------- has lifetime `'static` | ||
LL | fn g<T>(self, x: &'a T) -> &'static T { | ||
| ------- also has lifetime `'static` | ||
LL | f(&self, x) | ||
| ^^^^^ `self` would have to be valid for `'static`... | ||
... | ||
LL | } | ||
| - ...but `self` will be dropped here, when the function `g` returns | ||
| | ||
= help: use data from the highlighted arguments which match the `'static` lifetime of the return type | ||
= note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments | ||
= note: to learn more, visit <https://doc.rust-lang.org/book/ch04-02-references-and-borrowing.html#dangling-references> | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0521, E0597. | ||
For more information about an error, try `rustc --explain E0521`. |