Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions tests/ui/suggestions/restrict-bound-already-has-generic-args.rs
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.

Copy link
Copy Markdown
Member

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:

             found associated type `<impl Pair<Left = A> as Pair>::Right`
help: consider further restricting this bound
   |
18 | fn frob<A, B>(pair: impl Pair<Left = A, Right = B>) -> impl Pair<Left = A, Right = B> {
   |                                       +++++++++++

For more information about this error, try `rustc --explain E0271`.

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.

Copy link
Copy Markdown
Contributor Author

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/Deserializer with 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.


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() {}
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`.
Loading