-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Don't ICE when RPITIT captures more method args than trait definition #130412
Merged
Merged
Changes from all commits
Commits
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.
16 changes: 16 additions & 0 deletions
16
tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.rs
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,16 @@ | ||
// Make sure we don't ICE when an RPITIT captures more method args than the | ||
// trait definition, which is not allowed. Due to the default lifetime capture | ||
// rules of RPITITs, this is only doable if we use precise capturing. | ||
|
||
pub trait Foo { | ||
fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>; | ||
//~^ ERROR `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits | ||
} | ||
|
||
impl Foo for () { | ||
fn bar<'im: 'im>(&'im mut self) -> impl Sized + 'im {} | ||
//~^ ERROR return type captures more lifetimes than trait definition | ||
//~| WARN impl trait in impl method signature does not match trait method signature | ||
} | ||
|
||
fn main() {} |
42 changes: 42 additions & 0 deletions
42
tests/ui/impl-trait/precise-capturing/rpitit-captures-more-method-lifetimes.stderr
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,42 @@ | ||
error: `use<...>` precise capturing syntax is currently not allowed in return-position `impl Trait` in traits | ||
--> $DIR/rpitit-captures-more-method-lifetimes.rs:6:53 | ||
| | ||
LL | fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>; | ||
| ^^^^^^^^^ | ||
| | ||
= note: currently, return-position `impl Trait` in traits and trait implementations capture all lifetimes in scope | ||
|
||
error: return type captures more lifetimes than trait definition | ||
--> $DIR/rpitit-captures-more-method-lifetimes.rs:11:40 | ||
| | ||
LL | fn bar<'im: 'im>(&'im mut self) -> impl Sized + 'im {} | ||
| --- ^^^^^^^^^^^^^^^^ | ||
| | | ||
| this lifetime was captured | ||
| | ||
note: hidden type must only reference lifetimes captured by this impl trait | ||
--> $DIR/rpitit-captures-more-method-lifetimes.rs:6:40 | ||
| | ||
LL | fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: hidden type inferred to be `impl Sized + 'im` | ||
|
||
warning: impl trait in impl method signature does not match trait method signature | ||
--> $DIR/rpitit-captures-more-method-lifetimes.rs:11:40 | ||
| | ||
LL | fn bar<'tr: 'tr>(&'tr mut self) -> impl Sized + use<Self>; | ||
| ---------------------- return type from trait method defined here | ||
... | ||
LL | fn bar<'im: 'im>(&'im mut self) -> impl Sized + 'im {} | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate | ||
= note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information | ||
= note: `#[warn(refining_impl_trait_reachable)]` on by default | ||
help: replace the return type so that it matches the trait | ||
| | ||
LL | fn bar<'im: 'im>(&'im mut self) -> impl Sized {} | ||
| ~~~~~~~~~~ | ||
|
||
error: aborting due to 2 previous errors; 1 warning emitted | ||
|
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 used the def id of the trait, rather than the def id of the impl method. The def id of the impl method is needed here because we're remapping args from the impl method's signature.