-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't ICE if HIR and middle types disagree in borrowck error reporting
- Loading branch information
1 parent
2ccafed
commit d004edf
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`. |