-
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
Error when RPITITs' hidden types capture more lifetimes than their trait definitions #113182
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
65 changes: 55 additions & 10 deletions
65
tests/ui/impl-trait/in-trait/signature-mismatch.current.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 |
---|---|---|
@@ -1,16 +1,61 @@ | ||
error: `impl` item signature doesn't match `trait` item signature | ||
--> $DIR/signature-mismatch.rs:17:5 | ||
error: return type captures more lifetimes than trait definition | ||
--> $DIR/signature-mismatch.rs:36:47 | ||
| | ||
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a { | ||
| -- this lifetime was captured ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: hidden type must only reference lifetimes captured by this impl trait | ||
--> $DIR/signature-mismatch.rs:17:40 | ||
| | ||
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>; | ||
| ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '3` | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + 'a` | ||
|
||
error: return type captures more lifetimes than trait definition | ||
--> $DIR/signature-mismatch.rs:41:57 | ||
| | ||
LL | fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a { | ||
| -- this lifetime was captured ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: hidden type must only reference lifetimes captured by this impl trait | ||
--> $DIR/signature-mismatch.rs:18:57 | ||
| | ||
LL | fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + 'a` | ||
|
||
error: return type captures more lifetimes than trait definition | ||
--> $DIR/signature-mismatch.rs:49:10 | ||
| | ||
LL | fn async_fn_multiple<'a, 'b>( | ||
| -- this lifetime was captured | ||
... | ||
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2` | ||
LL | ) -> impl Future<Output = Vec<u8>> + Captures2<'a, 'b> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: hidden type must only reference lifetimes captured by this impl trait | ||
--> $DIR/signature-mismatch.rs:20:12 | ||
| | ||
LL | -> impl Future<Output = Vec<u8>> + Captures<'a>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + Captures2<'a, 'b>` | ||
|
||
error[E0309]: the parameter type `T` may not live long enough | ||
--> $DIR/signature-mismatch.rs:58:10 | ||
| | ||
LL | ) -> impl Future<Output = Vec<u8>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `impl Future<Output = Vec<u8>>` will meet its required lifetime bounds... | ||
| | ||
note: ...that is required by this bound | ||
--> $DIR/signature-mismatch.rs:25:42 | ||
| | ||
LL | ) -> impl Future<Output = Vec<u8>> + 'a; | ||
| ^^ | ||
help: consider adding an explicit lifetime bound... | ||
| | ||
= note: expected signature `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '3` | ||
found signature `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2` | ||
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait` | ||
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output | ||
LL | fn async_fn_reduce_outlive<'a, 'b, T: 'a>( | ||
| ++++ | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0309`. |
65 changes: 55 additions & 10 deletions
65
tests/ui/impl-trait/in-trait/signature-mismatch.next.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 |
---|---|---|
@@ -1,16 +1,61 @@ | ||
error: `impl` item signature doesn't match `trait` item signature | ||
--> $DIR/signature-mismatch.rs:17:5 | ||
error: return type captures more lifetimes than trait definition | ||
--> $DIR/signature-mismatch.rs:36:47 | ||
| | ||
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a { | ||
| -- this lifetime was captured ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: hidden type must only reference lifetimes captured by this impl trait | ||
--> $DIR/signature-mismatch.rs:17:40 | ||
| | ||
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>; | ||
| ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '3` | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + 'a` | ||
|
||
error: return type captures more lifetimes than trait definition | ||
--> $DIR/signature-mismatch.rs:41:57 | ||
| | ||
LL | fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a { | ||
| -- this lifetime was captured ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: hidden type must only reference lifetimes captured by this impl trait | ||
--> $DIR/signature-mismatch.rs:18:57 | ||
| | ||
LL | fn async_fn_early<'a: 'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + 'a` | ||
|
||
error: return type captures more lifetimes than trait definition | ||
--> $DIR/signature-mismatch.rs:49:10 | ||
| | ||
LL | fn async_fn_multiple<'a, 'b>( | ||
| -- this lifetime was captured | ||
... | ||
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2` | ||
LL | ) -> impl Future<Output = Vec<u8>> + Captures2<'a, 'b> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
note: hidden type must only reference lifetimes captured by this impl trait | ||
--> $DIR/signature-mismatch.rs:20:12 | ||
| | ||
LL | -> impl Future<Output = Vec<u8>> + Captures<'a>; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
= note: hidden type inferred to be `impl Future<Output = Vec<u8>> + Captures2<'a, 'b>` | ||
|
||
error[E0309]: the parameter type `T` may not live long enough | ||
--> $DIR/signature-mismatch.rs:58:10 | ||
| | ||
LL | ) -> impl Future<Output = Vec<u8>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...so that the type `impl Future<Output = Vec<u8>>` will meet its required lifetime bounds... | ||
| | ||
note: ...that is required by this bound | ||
--> $DIR/signature-mismatch.rs:25:42 | ||
| | ||
LL | ) -> impl Future<Output = Vec<u8>> + 'a; | ||
| ^^ | ||
help: consider adding an explicit lifetime bound... | ||
| | ||
= note: expected signature `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '3` | ||
found signature `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2` | ||
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait` | ||
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output | ||
LL | fn async_fn_reduce_outlive<'a, 'b, T: 'a>( | ||
| ++++ | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0309`. |
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 will try to remap all opaques (even taits), should we do something about that? I mean it's not going to do any actual remapping due to how variances are set up, but still a bit odd
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.
I don't think it matters. We do the same thing for opaques in borrowck, for example.