mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-30 14:01:51 +00:00
Add test for method on unbounded type parameter receiver
This commit is contained in:
parent
5ad7454f75
commit
d34b0fa495
15
tests/ui/traits/method-on-unbounded-type-param.rs
Normal file
15
tests/ui/traits/method-on-unbounded-type-param.rs
Normal 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
|
||||
}
|
83
tests/ui/traits/method-on-unbounded-type-param.stderr
Normal file
83
tests/ui/traits/method-on-unbounded-type-param.stderr
Normal 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`.
|
Loading…
Reference in New Issue
Block a user