Skip to content

regression test for Trait<A><B> in "consider further restricting this bound" suggestion#158454

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
Albab-Hasan:fix-restrict-bound-double-angle
Jun 28, 2026
Merged

regression test for Trait<A><B> in "consider further restricting this bound" suggestion#158454
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
Albab-Hasan:fix-restrict-bound-double-angle

Conversation

@Albab-Hasan

@Albab-Hasan Albab-Hasan commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

when a bound already has generic args (e.g. impl Pair<Left = A>) the "consider further restricting this bound" suggestion would generate invalid syntax by appending a new <Right = B> producing Pair<Left = A><Right = B>.

the fix detects when the insertion point immediately follows a > and merges into the existing arg list instead producing the valid Pair<Left = A, Right = B>.

fixes #142803

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 26, 2026
@rustbot

rustbot commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 18 candidates

@rustbot

This comment has been minimized.

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 26, 2026
@Albab-Hasan Albab-Hasan reopened this Jun 26, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 26, 2026
…ting this bound" suggestion

when a bound already has generic args (e.g. `impl Pair<Left = A>`) the "consider further restricting this bound" suggestion would generate invalid syntax by appending a new `<Right = B>` producing `Pair<Left = A><Right = B>`.

the fix detects when the insertion point immediately follows a `>` and merges into the existing arg list instead producing the valid `Pair<Left = A, Right = B>`.
@Albab-Hasan Albab-Hasan force-pushed the fix-restrict-bound-double-angle branch from 6efa6e1 to 9260f2e Compare June 26, 2026 17:28

@workingjubilee workingjubilee left a comment

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.

I am not entirely sure what we need here but I don't think we need this PR as it currently is. That said, I am happy to defer to Folkert otherwise as to what specific changes we want.

View changes since this review

@@ -0,0 +1,25 @@
// 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.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 26, 2026
@rustbot

rustbot commented Jun 26, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

dropped the code change. added //~ HELP and //~ SUGGESTION annotations.

@Albab-Hasan

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 27, 2026
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

A job failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
  PR_CI_JOB: 1
  IMAGE: x86_64-gnu-llvm-21
##[endgroup]
    Updating crates.io index
error: failed to get `cookie` as a dependency of package `cookie_store v0.21.1`
    ... which satisfies dependency `cookie_store = "^0.21.1"` of package `ureq v3.0.8`
    ... which satisfies dependency `ureq = "^3"` of package `citool v0.1.0 (/home/runner/work/rust/rust/src/ci/citool)`

Caused by:
  failed to load source for dependency `cookie`

Caused by:
  unable to update registry `crates-io`

Caused by:
  download of co/ok/cookie failed

Caused by:
  curl failed

Caused by:

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 27, 2026
@Albab-Hasan Albab-Hasan reopened this Jun 27, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 27, 2026
@folkertdev folkertdev changed the title fix: don't produce invalid Trait<A><B> in "consider further restricting this bound" suggestion regression test for Trait<A><B> in "consider further restricting this bound" suggestion Jun 28, 2026
@folkertdev

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

📌 Commit dde5f49 has been approved by folkertdev

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jun 28, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 28, 2026
rust-bors Bot pushed a commit that referenced this pull request Jun 28, 2026
…uwer

Rollup of 4 pull requests

Successful merges:

 - #158486 (std: treat ENFILE as transient in the pidfd support probe)
 - #158454 (regression test for `Trait<A><B>` in "consider further restricting this bound" suggestion)
 - #158518 (Fix mixed use of "a" / "an" article in E0277)
 - #158519 (add crashtests [2/N])
rust-bors Bot pushed a commit that referenced this pull request Jun 28, 2026
…uwer

Rollup of 4 pull requests

Successful merges:

 - #158486 (std: treat ENFILE as transient in the pidfd support probe)
 - #158454 (regression test for `Trait<A><B>` in "consider further restricting this bound" suggestion)
 - #158518 (Fix mixed use of "a" / "an" article in E0277)
 - #158519 (add crashtests [2/N])
@rust-bors rust-bors Bot merged commit acdfef5 into rust-lang:main Jun 28, 2026
15 of 26 checks passed
@rustbot rustbot added this to the 1.98.0 milestone Jun 28, 2026
rust-timer added a commit that referenced this pull request Jun 28, 2026
Rollup merge of #158454 - Albab-Hasan:fix-restrict-bound-double-angle, r=folkertdev

regression test for `Trait<A><B>` in "consider further restricting this bound" suggestion

when a bound already has generic args (e.g. `impl Pair<Left = A>`) the "consider further restricting this bound" suggestion would generate invalid syntax by appending a new `<Right = B>` producing `Pair<Left = A><Right = B>`.

the fix detects when the insertion point immediately follows a `>` and merges into the existing arg list instead producing the valid `Pair<Left = A, Right = B>`.

fixes #142803
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

invalid syntax in "consider further restricting this bound" when there is already a bound present

5 participants