-
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
Use existing infcx
when emitting trait impl diagnostic
#75363
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
28 changes: 28 additions & 0 deletions
28
src/test/ui/mismatched_types/issue-74918-missing-lifetime.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,28 @@ | ||
// Regression test for issue #74918 | ||
// Tests that we don't ICE after emitting an error | ||
|
||
struct ChunkingIterator<T, S: 'static + Iterator<Item = T>> { | ||
source: S, | ||
} | ||
|
||
impl<T, S: Iterator<Item = T>> Iterator for ChunkingIterator<T, S> { | ||
type Item = IteratorChunk<T, S>; //~ ERROR missing lifetime | ||
|
||
fn next(&mut self) -> Option<IteratorChunk<T, S>> { //~ ERROR `impl` | ||
todo!() | ||
} | ||
} | ||
|
||
struct IteratorChunk<'a, T, S: Iterator<Item = T>> { | ||
source: &'a mut S, | ||
} | ||
|
||
impl<T, S: Iterator<Item = T>> Iterator for IteratorChunk<'_, T, S> { | ||
type Item = T; | ||
|
||
fn next(&mut self) -> Option<T> { | ||
todo!() | ||
} | ||
} | ||
|
||
fn main() {} |
30 changes: 30 additions & 0 deletions
30
src/test/ui/mismatched_types/issue-74918-missing-lifetime.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,30 @@ | ||
error[E0106]: missing lifetime specifier | ||
--> $DIR/issue-74918-missing-lifetime.rs:9:31 | ||
| | ||
LL | type Item = IteratorChunk<T, S>; | ||
| ^ expected named lifetime parameter | ||
| | ||
help: consider introducing a named lifetime parameter | ||
| | ||
LL | type Item<'a> = IteratorChunk<<'a>T, S>; | ||
| ^^^^ ^^^^ | ||
|
||
error: `impl` item signature doesn't match `trait` item signature | ||
--> $DIR/issue-74918-missing-lifetime.rs:11:5 | ||
| | ||
LL | fn next(&mut self) -> Option<IteratorChunk<T, S>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&mut ChunkingIterator<T, S>) -> std::option::Option<IteratorChunk<'_, T, S>>` | ||
| | ||
::: $SRC_DIR/core/src/iter/traits/iterator.rs:LL:COL | ||
| | ||
LL | fn next(&mut self) -> Option<Self::Item>; | ||
| ----------------------------------------- expected `fn(&mut ChunkingIterator<T, S>) -> std::option::Option<IteratorChunk<'static, _, _>>` | ||
| | ||
= note: expected `fn(&mut ChunkingIterator<T, S>) -> std::option::Option<IteratorChunk<'static, _, _>>` | ||
found `fn(&mut ChunkingIterator<T, S>) -> std::option::Option<IteratorChunk<'_, _, _>>` | ||
= 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 | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0106`. |
24 changes: 24 additions & 0 deletions
24
src/test/ui/mismatched_types/issue-75361-mismatched-impl.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,24 @@ | ||
// Regresison test for issue #75361 | ||
// Tests that we don't ICE on mismatched types with inference variables | ||
|
||
|
||
trait MyTrait { | ||
type Item; | ||
} | ||
|
||
pub trait Graph { | ||
type EdgeType; | ||
|
||
fn adjacent_edges(&self) -> Box<dyn MyTrait<Item = &Self::EdgeType>>; | ||
} | ||
|
||
impl<T> Graph for T { | ||
type EdgeType = T; | ||
|
||
fn adjacent_edges(&self) -> Box<dyn MyTrait<Item = &Self::EdgeType> + '_> { //~ ERROR `impl` | ||
panic!() | ||
} | ||
|
||
} | ||
|
||
fn main() {} |
19 changes: 19 additions & 0 deletions
19
src/test/ui/mismatched_types/issue-75361-mismatched-impl.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,19 @@ | ||
error: `impl` item signature doesn't match `trait` item signature | ||
--> $DIR/issue-75361-mismatched-impl.rs:18:3 | ||
| | ||
LL | fn adjacent_edges(&self) -> Box<dyn MyTrait<Item = &Self::EdgeType>>; | ||
| --------------------------------------------------------------------- expected `fn(&T) -> std::boxed::Box<(dyn MyTrait<Item = &_> + 'static)>` | ||
... | ||
LL | fn adjacent_edges(&self) -> Box<dyn MyTrait<Item = &Self::EdgeType> + '_> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&T) -> std::boxed::Box<dyn MyTrait<Item = &_>>` | ||
| | ||
= note: expected `fn(&T) -> std::boxed::Box<(dyn MyTrait<Item = &T> + 'static)>` | ||
found `fn(&T) -> std::boxed::Box<dyn MyTrait<Item = &T>>` | ||
help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait` | ||
--> $DIR/issue-75361-mismatched-impl.rs:12:55 | ||
| | ||
LL | fn adjacent_edges(&self) -> Box<dyn MyTrait<Item = &Self::EdgeType>>; | ||
| ^^^^^^^^^^^^^^ consider borrowing this type parameter in the trait | ||
|
||
error: aborting due to previous error | ||
|
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.
do we already have an issue for this error message?
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'm not sure, but to fix it we need to extend the logic in the last
match
at the end ofadd_missing_lifetime_specifiers_label
.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.
#75372 tested locally: