-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Fix ambiguous cases of multiple & in elided self lifetimes #117967
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8d1958f
Ambiguous Self lifetimes: don't elide.
adetaylor e62599f
Do not elide if there's ambiguity in self lifetime.
adetaylor 6287c94
Adjust crash bug to still reproduce.
adetaylor 8c17777
Remove duplicative test.
adetaylor c20a90f
Add additional tests.
adetaylor 386838d
Additional test due to Pin<&Self> discovery
adetaylor a22130e
Elision: consider lifetimes from &T iff T has Self
adetaylor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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,22 @@ | ||
//@ check-pass | ||
|
||
struct Foo<'a>(&'a str); | ||
|
||
impl<'b> Foo<'b> { | ||
fn a<'a>(self: Self, a: &'a str) -> &str { | ||
a | ||
} | ||
fn b<'a>(self: Foo<'b>, a: &'a str) -> &str { | ||
a | ||
} | ||
} | ||
|
||
struct Foo2<'a>(&'a u32); | ||
impl<'a> Foo2<'a> { | ||
fn foo(self: &Self) -> &u32 { self.0 } // ok | ||
fn bar(self: &Foo2<'a>) -> &u32 { self.0 } // ok (do not look into `Foo`) | ||
fn baz2(self: Self, arg: &u32) -> &u32 { arg } // use lt from `arg` | ||
fn baz3(self: Foo2<'a>, arg: &u32) -> &u32 { arg } // use lt from `arg` | ||
} | ||
|
||
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
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,63 @@ | ||
error[E0106]: missing lifetime specifier | ||
--> $DIR/multiple-ref-self-async.rs:22:74 | ||
| | ||
LL | async fn wrap_ref_Self_ref_Self(self: Wrap<&Self, &Self>, f: &u8) -> &u8 { | ||
| ------------------ --- ^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from one of `self`'s 2 lifetimes or `f` | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | async fn wrap_ref_Self_ref_Self<'a>(self: Wrap<&'a Self, &'a Self>, f: &'a u8) -> &'a u8 { | ||
| ++++ ++ ++ ++ ++ | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/multiple-ref-self-async.rs:27:84 | ||
| | ||
LL | async fn box_wrap_ref_Self_ref_Self(self: Box<Wrap<&Self, &Self>>, f: &u32) -> &u32 { | ||
| ----------------------- ---- ^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from one of `self`'s 2 lifetimes or `f` | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | async fn box_wrap_ref_Self_ref_Self<'a>(self: Box<Wrap<&'a Self, &'a Self>>, f: &'a u32) -> &'a u32 { | ||
| ++++ ++ ++ ++ ++ | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/multiple-ref-self-async.rs:32:84 | ||
| | ||
LL | async fn pin_wrap_ref_Self_ref_Self(self: Pin<Wrap<&Self, &Self>>, f: &u32) -> &u32 { | ||
| ----------------------- ---- ^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from one of `self`'s 2 lifetimes or `f` | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | async fn pin_wrap_ref_Self_ref_Self<'a>(self: Pin<Wrap<&'a Self, &'a Self>>, f: &'a u32) -> &'a u32 { | ||
| ++++ ++ ++ ++ ++ | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/multiple-ref-self-async.rs:37:93 | ||
| | ||
LL | async fn box_box_wrap_ref_Self_ref_Self(self: Box<Box<Wrap<&Self, &Self>>>, f: &u32) -> &u32 { | ||
| ---------------------------- ---- ^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from one of `self`'s 2 lifetimes or `f` | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | async fn box_box_wrap_ref_Self_ref_Self<'a>(self: Box<Box<Wrap<&'a Self, &'a Self>>>, f: &'a u32) -> &'a u32 { | ||
| ++++ ++ ++ ++ ++ | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/multiple-ref-self-async.rs:42:93 | ||
| | ||
LL | async fn box_pin_wrap_ref_Self_ref_Self(self: Box<Pin<Wrap<&Self, &Self>>>, f: &u32) -> &u32 { | ||
| ---------------------------- ---- ^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from one of `self`'s 2 lifetimes or `f` | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | async fn box_pin_wrap_ref_Self_ref_Self<'a>(self: Box<Pin<Wrap<&'a Self, &'a Self>>>, f: &'a u32) -> &'a u32 { | ||
| ++++ ++ ++ ++ ++ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0106`. |
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,63 @@ | ||
error[E0106]: missing lifetime specifier | ||
--> $DIR/multiple-ref-self.rs:20:68 | ||
| | ||
LL | fn wrap_ref_Self_ref_Self(self: Wrap<&Self, &Self>, f: &u8) -> &u8 { | ||
| ------------------ --- ^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from one of `self`'s 2 lifetimes or `f` | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | fn wrap_ref_Self_ref_Self<'a>(self: Wrap<&'a Self, &'a Self>, f: &'a u8) -> &'a u8 { | ||
| ++++ ++ ++ ++ ++ | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/multiple-ref-self.rs:25:78 | ||
| | ||
LL | fn box_wrap_ref_Self_ref_Self(self: Box<Wrap<&Self, &Self>>, f: &u32) -> &u32 { | ||
| ----------------------- ---- ^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from one of `self`'s 2 lifetimes or `f` | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | fn box_wrap_ref_Self_ref_Self<'a>(self: Box<Wrap<&'a Self, &'a Self>>, f: &'a u32) -> &'a u32 { | ||
| ++++ ++ ++ ++ ++ | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/multiple-ref-self.rs:30:78 | ||
| | ||
LL | fn pin_wrap_ref_Self_ref_Self(self: Pin<Wrap<&Self, &Self>>, f: &u32) -> &u32 { | ||
| ----------------------- ---- ^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from one of `self`'s 2 lifetimes or `f` | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | fn pin_wrap_ref_Self_ref_Self<'a>(self: Pin<Wrap<&'a Self, &'a Self>>, f: &'a u32) -> &'a u32 { | ||
| ++++ ++ ++ ++ ++ | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/multiple-ref-self.rs:35:87 | ||
| | ||
LL | fn box_box_wrap_ref_Self_ref_Self(self: Box<Box<Wrap<&Self, &Self>>>, f: &u32) -> &u32 { | ||
| ---------------------------- ---- ^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from one of `self`'s 2 lifetimes or `f` | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | fn box_box_wrap_ref_Self_ref_Self<'a>(self: Box<Box<Wrap<&'a Self, &'a Self>>>, f: &'a u32) -> &'a u32 { | ||
| ++++ ++ ++ ++ ++ | ||
|
||
error[E0106]: missing lifetime specifier | ||
--> $DIR/multiple-ref-self.rs:40:87 | ||
| | ||
LL | fn box_pin_wrap_ref_Self_ref_Self(self: Box<Pin<Wrap<&Self, &Self>>>, f: &u32) -> &u32 { | ||
| ---------------------------- ---- ^ expected named lifetime parameter | ||
| | ||
= help: this function's return type contains a borrowed value, but the signature does not say whether it is borrowed from one of `self`'s 2 lifetimes or `f` | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | fn box_pin_wrap_ref_Self_ref_Self<'a>(self: Box<Pin<Wrap<&'a Self, &'a Self>>>, f: &'a u32) -> &'a u32 { | ||
| ++++ ++ ++ ++ ++ | ||
|
||
error: aborting due to 5 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0106`. |
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,17 @@ | ||
use std::pin::Pin; | ||
trait Trait { | ||
fn method<'a>(self: Pin<&Self>, f: &'a u32) -> &'a u32 { | ||
f | ||
} | ||
} | ||
|
||
impl<P> Trait for Pin<P> { | ||
// This should not hide `&Self`, which would cause this to compile. | ||
fn method(self: Pin<&Self>, f: &u32) -> &u32 { | ||
//~^ ERROR `impl` item signature doesn't match `trait` | ||
f | ||
//~^ ERROR lifetime may not live long enough | ||
} | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test is now instead testing the "no-recurse-into-self" rule, isn't it?