regression test for Trait<A><B> in "consider further restricting this bound" suggestion#158454
Conversation
|
r? @folkertdev rustbot has assigned @folkertdev. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
…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>`.
6efa6e1 to
9260f2e
Compare
| @@ -0,0 +1,25 @@ | |||
| // Regression test for https://github.com/rust-lang/rust/issues/142803. | |||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
Reminder, once the PR becomes ready for a review, use |
|
dropped the code change. added |
|
@rustbot ready |
|
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) |
Trait<A><B> in "consider further restricting this bound" suggestionTrait<A><B> in "consider further restricting this bound" suggestion
|
@bors r+ rollup |
…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])
…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])
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
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>producingPair<Left = A><Right = B>.the fix detects when the insertion point immediately follows a
>and merges into the existing arg list instead producing the validPair<Left = A, Right = B>.fixes #142803