Open
Description
Code
trait Pair {
type Left;
type Right;
fn cons(left: Self::Left, right: Self::Right) -> Self;
fn split(self) -> (Self::Left, Self::Right);
}
impl<A, B> Pair for (A, B) {
type Left = A;
type Right = B;
fn cons(left: Self::Left, right: Self::Right) -> Self {
(left, right)
}
fn split(self) -> (Self::Left, Self::Right) {
self
}
}
fn frob<A, B>(pair: impl Pair<Left = A>) -> impl Pair<Left = A, Right = B> {
let (left, right) = pair.split();
(left, right)
}
Current output
error[E0271]: type mismatch resolving `<(A, <impl Pair<Left = A> as Pair>::Right) as Pair>::Right == B`
--> src/lib.rs:22:45
|
22 | 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`
23 | let (left, right) = pair.split();
24 | (left, right)
| ------------- return type was inferred to be `(A, <impl Pair<Left = A> as Pair>::Right)` here
|
note: expected this to be `B`
--> src/lib.rs:11:18
|
11 | type Right = B;
| ^
= note: expected type parameter `B`
found associated type `<impl Pair<Left = A> as Pair>::Right`
help: consider further restricting this bound
|
22 | 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`.
Desired output
error[E0271]: type mismatch resolving `<(A, <impl Pair<Left = A> as Pair>::Right) as Pair>::Right == B`
--> src/lib.rs:22:45
|
22 | 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`
23 | let (left, right) = pair.split();
24 | (left, right)
| ------------- return type was inferred to be `(A, <impl Pair<Left = A> as Pair>::Right)` here
|
note: expected this to be `B`
--> src/lib.rs:11:18
|
11 | type Right = B;
| ^
= note: expected type parameter `B`
found associated type `<impl Pair<Left = A> as Pair>::Right`
help: consider further restricting this bound
|
22 | 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`.
Rationale and extra context
No response
Other cases
Rust Version
rustc 1.89.0-nightly (1677d46cb 2025-06-10)
binary: rustc
commit-hash: 1677d46cb128cc8f285dbd32b0dc4d7a46437050
commit-date: 2025-06-10
host: x86_64-unknown-linux-gnu
release: 1.89.0-nightly
LLVM version: 20.1.5
Anything else?
No response