Skip to content

Commit 2b2bd08

Browse files
authored
Unrolled build for #158454
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
2 parents b4486ca + dde5f49 commit 2b2bd08

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Regression test for https://github.com/rust-lang/rust/issues/142803.
2+
3+
trait Pair {
4+
type Left;
5+
type Right;
6+
7+
fn split(self) -> (Self::Left, Self::Right);
8+
}
9+
10+
impl<A, B> Pair for (A, B) {
11+
type Left = A;
12+
type Right = B;
13+
14+
fn split(self) -> (Self::Left, Self::Right) {
15+
self
16+
}
17+
}
18+
19+
fn frob<A, B>(pair: impl Pair<Left = A>) -> impl Pair<Left = A, Right = B> {
20+
//~^ ERROR type mismatch
21+
//~| HELP consider further restricting this bound
22+
//~| SUGGESTION , Right = B
23+
let (left, right) = pair.split();
24+
(left, right)
25+
}
26+
27+
fn main() {}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0271]: type mismatch resolving `<(A, <impl Pair<Left = A> as Pair>::Right) as Pair>::Right == B`
2+
--> $DIR/restrict-bound-already-has-generic-args.rs:19:45
3+
|
4+
LL | fn frob<A, B>(pair: impl Pair<Left = A>) -> impl Pair<Left = A, Right = B> {
5+
| - expected this type parameter ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<(A, <impl Pair<Left = A> as Pair>::Right) as Pair>::Right == B`
6+
...
7+
LL | (left, right)
8+
| ------------- return type was inferred to be `(A, <impl Pair<Left = A> as Pair>::Right)` here
9+
|
10+
note: expected this to be `B`
11+
--> $DIR/restrict-bound-already-has-generic-args.rs:12:18
12+
|
13+
LL | type Right = B;
14+
| ^
15+
= note: expected type parameter `B`
16+
found associated type `<impl Pair<Left = A> as Pair>::Right`
17+
help: consider further restricting this bound
18+
|
19+
LL | fn frob<A, B>(pair: impl Pair<Left = A, Right = B>) -> impl Pair<Left = A, Right = B> {
20+
| +++++++++++
21+
22+
error: aborting due to 1 previous error
23+
24+
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)