-
-
Notifications
You must be signed in to change notification settings - Fork 15.3k
regression test for Trait<A><B> in "consider further restricting this bound" suggestion
#158454
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
Merged
rust-bors
merged 2 commits into
rust-lang:main
from
Albab-Hasan:fix-restrict-bound-double-angle
Jun 28, 2026
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
27 changes: 27 additions & 0 deletions
27
tests/ui/suggestions/restrict-bound-already-has-generic-args.rs
This file contains hidden or 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,27 @@ | ||
| // Regression test for https://github.com/rust-lang/rust/issues/142803. | ||
|
|
||
| trait Pair { | ||
| type Left; | ||
| type Right; | ||
|
|
||
| fn split(self) -> (Self::Left, Self::Right); | ||
| } | ||
|
|
||
| impl<A, B> Pair for (A, B) { | ||
| type Left = A; | ||
| type Right = B; | ||
|
|
||
| fn split(self) -> (Self::Left, Self::Right) { | ||
| self | ||
| } | ||
| } | ||
|
|
||
| fn frob<A, B>(pair: impl Pair<Left = A>) -> impl Pair<Left = A, Right = B> { | ||
| //~^ ERROR type mismatch | ||
| //~| HELP consider further restricting this bound | ||
| //~| SUGGESTION , Right = B | ||
| let (left, right) = pair.split(); | ||
| (left, right) | ||
| } | ||
|
|
||
| fn main() {} | ||
24 changes: 24 additions & 0 deletions
24
tests/ui/suggestions/restrict-bound-already-has-generic-args.stderr
This file contains hidden or 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 @@ | ||
| error[E0271]: type mismatch resolving `<(A, <impl Pair<Left = A> as Pair>::Right) as Pair>::Right == B` | ||
| --> $DIR/restrict-bound-already-has-generic-args.rs:19:45 | ||
| | | ||
| LL | fn frob<A, B>(pair: impl Pair<Left = A>) -> impl Pair<Left = A, Right = B> { | ||
| | - expected this type parameter ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<(A, <impl Pair<Left = A> as Pair>::Right) as Pair>::Right == B` | ||
| ... | ||
| LL | (left, right) | ||
| | ------------- return type was inferred to be `(A, <impl Pair<Left = A> as Pair>::Right)` here | ||
| | | ||
| note: expected this to be `B` | ||
| --> $DIR/restrict-bound-already-has-generic-args.rs:12:18 | ||
| | | ||
| LL | type Right = B; | ||
| | ^ | ||
| = note: expected type parameter `B` | ||
| found associated type `<impl Pair<Left = A> as Pair>::Right` | ||
| help: consider further restricting this bound | ||
| | | ||
| LL | fn frob<A, B>(pair: impl Pair<Left = A, Right = B>) -> impl Pair<Left = A, Right = B> { | ||
| | +++++++++++ | ||
|
|
||
| error: aborting due to 1 previous error | ||
|
|
||
| For more information about this error, try `rustc --explain E0271`. |
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 regression test seems insufficient to me, but even so it exhibits the desired behavior without any compiler changes applied. Specifically, this is currently the output of the lines in question when considering the latest stable:
This was fixed somewhere between 1.95 and 1.96, as it is specifically 1.96 that has the desired output.
@Albab-Hasan Would you be so kind as to bisect rustc to determine the speciifc commit at which this behavior was fixed? This regression test may still be needed if the fix was incidental, with some updates to the error matching to make sure it verifies that the specific behavior we want is obtained without relying on direct verification of the stderr. Otherwise, it may just be duplicating another test.
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.
mb the fix landed in #154655 ("Fix associated type bound suggestion span issue", fixes #145586) merged 2026-04-01, nightly-2026-04-02. that PR touches
rustc_trait_selection/src/error_reporting/infer/note_and_explain.rs. my fix for #142803 was incidental.its test covers a different pattern (
Visitor/Deserializerwith lifetimes) so the test case here is not a duplicate.since the fix is incidental ill drop the code change to
diagnostics.rs(now unreachable) and update the test to use inline//~annotations targeting the suggestion text directly so it explicitly guards the merged-args behavior without relying on full stderr.