Add test for method on unbounded type parameter receiver

This commit is contained in:
Esteban Küber 2024-01-26 18:57:58 +00:00
parent 5ad7454f75
commit d34b0fa495
2 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,15 @@
fn f<T>(a: T, b: T) -> std::cmp::Ordering {
a.cmp(&b) //~ ERROR E0599
}
fn g<T>(a: T, b: T) -> std::cmp::Ordering {
(&a).cmp(&b) //~ ERROR E0599
}
fn h<T>(a: &T, b: T) -> std::cmp::Ordering {
a.cmp(&b) //~ ERROR E0599
}
trait T {}
impl<X: std::cmp::Ord> T for X {}
fn main() {
let x: Box<dyn T> = Box::new(0);
x.cmp(&x); //~ ERROR E0599
}

View File

@ -0,0 +1,83 @@
error[E0599]: `T` is not an iterator
--> $DIR/method-on-unbounded-type-param.rs:2:7
|
LL | fn f<T>(a: T, b: T) -> std::cmp::Ordering {
| - method `cmp` not found for this type parameter
LL | a.cmp(&b)
| ^^^ `T` is not an iterator
|
= note: the following trait bounds were not satisfied:
`T: Iterator`
which is required by `&mut T: Iterator`
help: consider restricting the type parameter to satisfy the trait bound
|
LL | fn f<T>(a: T, b: T) -> std::cmp::Ordering where T: Iterator {
| +++++++++++++++++
error[E0599]: the method `cmp` exists for reference `&T`, but its trait bounds were not satisfied
--> $DIR/method-on-unbounded-type-param.rs:5:10
|
LL | (&a).cmp(&b)
| ^^^ method cannot be called on `&T` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`T: Ord`
which is required by `&T: Ord`
`&T: Iterator`
which is required by `&mut &T: Iterator`
`T: Iterator`
which is required by `&mut T: Iterator`
help: consider restricting the type parameters to satisfy the trait bounds
|
LL | fn g<T>(a: T, b: T) -> std::cmp::Ordering where T: Iterator, T: Ord {
| +++++++++++++++++++++++++
error[E0599]: the method `cmp` exists for reference `&T`, but its trait bounds were not satisfied
--> $DIR/method-on-unbounded-type-param.rs:8:7
|
LL | a.cmp(&b)
| ^^^ method cannot be called on `&T` due to unsatisfied trait bounds
|
= note: the following trait bounds were not satisfied:
`T: Ord`
which is required by `&T: Ord`
`&T: Iterator`
which is required by `&mut &T: Iterator`
`T: Iterator`
which is required by `&mut T: Iterator`
help: consider restricting the type parameters to satisfy the trait bounds
|
LL | fn h<T>(a: &T, b: T) -> std::cmp::Ordering where T: Iterator, T: Ord {
| +++++++++++++++++++++++++
error[E0599]: the method `cmp` exists for struct `Box<dyn T>`, but its trait bounds were not satisfied
--> $DIR/method-on-unbounded-type-param.rs:14:7
|
LL | trait T {}
| -------
| |
| doesn't satisfy `dyn T: Iterator`
| doesn't satisfy `dyn T: Ord`
...
LL | x.cmp(&x);
| ^^^ method cannot be called on `Box<dyn T>` due to unsatisfied trait bounds
--> $SRC_DIR/alloc/src/boxed.rs:LL:COL
::: $SRC_DIR/alloc/src/boxed.rs:LL:COL
|
= note: doesn't satisfy `Box<dyn T>: Iterator`
|
= note: doesn't satisfy `Box<dyn T>: Ord`
|
= note: the following trait bounds were not satisfied:
`dyn T: Iterator`
which is required by `Box<dyn T>: Iterator`
`dyn T: Ord`
which is required by `Box<dyn T>: Ord`
`Box<dyn T>: Iterator`
which is required by `&mut Box<dyn T>: Iterator`
`dyn T: Iterator`
which is required by `&mut dyn T: Iterator`
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0599`.