Skip to content

Commit

Permalink
Add UI Test for issue rust-lang#125143
Browse files Browse the repository at this point in the history
  • Loading branch information
bovinebuddha committed May 17, 2024
1 parent 4ee2fce commit c4210bb
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/ui/inference/unnamed-lifetime-span-mixup-125143.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
struct X;

// Test that the error correctly differentiate between the two unnamed lifetimes
impl std::ops::Add<&X> for &X {
type Output = X;

fn add(self, _rhs: Self) -> Self::Output {
X
}
}
//~^^^^ ERROR method not compatible with trait

// Test that the error correctly differentiate between named and the unnamed lifetimes
impl<'a> std::ops::Mul<&'a X> for &X {
type Output = X;

fn mul(self, _rhs: Self) -> Self::Output {
X
}
}
//~^^^^ ERROR method not compatible with trait

// Test that the error correctly differentiate between named and the unnamed lifetimes
impl<'a> std::ops::Sub<&X> for &'a X {
type Output = X;

fn sub(self, _rhs: Self) -> Self::Output {
X
}
}
//~^^^^ ERROR method not compatible with trait

// This should pass since the lifetime subtyping will pass typecheck
impl<'a, 'b> std::ops::Div<&'a X> for &'b X where 'a : 'b {
type Output = X;

fn div(self, _rhs: Self) -> Self::Output {
X
}
}

fn main() {}
60 changes: 60 additions & 0 deletions tests/ui/inference/unnamed-lifetime-span-mixup-125143.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
error[E0308]: method not compatible with trait
--> $DIR/unnamed-lifetime-span-mixup-125143.rs:7:5
|
LL | fn add(self, _rhs: Self) -> Self::Output {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected signature `fn(&X, &X) -> X`
found signature `fn(&X, &X) -> X`
note: the anonymous lifetime as defined here...
--> $DIR/unnamed-lifetime-span-mixup-125143.rs:4:20
|
LL | impl std::ops::Add<&X> for &X {
| ^
note: ...does not necessarily outlive the anonymous lifetime as defined here
--> $DIR/unnamed-lifetime-span-mixup-125143.rs:4:28
|
LL | impl std::ops::Add<&X> for &X {
| ^

error[E0308]: method not compatible with trait
--> $DIR/unnamed-lifetime-span-mixup-125143.rs:17:5
|
LL | fn mul(self, _rhs: Self) -> Self::Output {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected signature `fn(&X, &'a X) -> X`
found signature `fn(&X, &X) -> X`
note: the lifetime `'a` as defined here...
--> $DIR/unnamed-lifetime-span-mixup-125143.rs:14:6
|
LL | impl<'a> std::ops::Mul<&'a X> for &X {
| ^^
note: ...does not necessarily outlive the anonymous lifetime as defined here
--> $DIR/unnamed-lifetime-span-mixup-125143.rs:14:35
|
LL | impl<'a> std::ops::Mul<&'a X> for &X {
| ^

error[E0308]: method not compatible with trait
--> $DIR/unnamed-lifetime-span-mixup-125143.rs:27:5
|
LL | fn sub(self, _rhs: Self) -> Self::Output {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected signature `fn(&'a X, &X) -> X`
found signature `fn(&'a X, &'a X) -> X`
note: the anonymous lifetime as defined here...
--> $DIR/unnamed-lifetime-span-mixup-125143.rs:24:24
|
LL | impl<'a> std::ops::Sub<&X> for &'a X {
| ^
note: ...does not necessarily outlive the lifetime `'a` as defined here
--> $DIR/unnamed-lifetime-span-mixup-125143.rs:24:6
|
LL | impl<'a> std::ops::Sub<&X> for &'a X {
| ^^

error: aborting due to 3 previous errors

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

0 comments on commit c4210bb

Please sign in to comment.