suggest adding a where-clause when that can help
suggest adding a where-clause when there is an unmet trait-bound that can be satisfied if some type can implement it.
This commit is contained in:
parent
513d9f208c
commit
8a461d940c
159 changed files with 420 additions and 297 deletions
|
|
@ -371,14 +371,13 @@ assert_eq!(6, answer);
|
|||
This gives us these long, related errors:
|
||||
|
||||
```text
|
||||
error: the trait `core::marker::Sized` is not implemented for the type
|
||||
`core::ops::Fn(i32) -> i32` [E0277]
|
||||
error: the predicate `core::ops::Fn(i32) -> i32 : core::marker::Sized` is not satisfied [E0277]
|
||||
fn factory() -> (Fn(i32) -> i32) {
|
||||
^~~~~~~~~~~~~~~~
|
||||
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
|
||||
fn factory() -> (Fn(i32) -> i32) {
|
||||
^~~~~~~~~~~~~~~~
|
||||
error: the trait `core::marker::Sized` is not implemented for the type `core::ops::Fn(i32) -> i32` [E0277]
|
||||
error: the predicate `core::ops::Fn(i32) -> i32 : core::marker::Sized` is not satisfied [E0277]
|
||||
let f = factory();
|
||||
^
|
||||
note: `core::ops::Fn(i32) -> i32` does not have a constant size known at compile-time
|
||||
|
|
|
|||
|
|
@ -231,8 +231,8 @@ fn main() {
|
|||
This won't work, however, and will give us the error:
|
||||
|
||||
```text
|
||||
13:9: 13:22 error: the trait `core::marker::Send` is not
|
||||
implemented for the type `alloc::rc::Rc<collections::vec::Vec<i32>>`
|
||||
13:9: 13:22 error: the predicate `alloc::rc::Rc<collections::vec::Vec<i32>> : core::marker::Send`
|
||||
is not satisfied
|
||||
...
|
||||
13:9: 13:22 note: `alloc::rc::Rc<collections::vec::Vec<i32>>`
|
||||
cannot be sent between threads safely
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ print_area(5);
|
|||
We get a compile-time error:
|
||||
|
||||
```text
|
||||
error: the trait `HasArea` is not implemented for the type `_` [E0277]
|
||||
error: the predicate `_ : HasArea` is not satisfied [E0277]
|
||||
```
|
||||
|
||||
## Trait bounds on generic structs
|
||||
|
|
@ -496,7 +496,7 @@ impl FooBar for Baz {
|
|||
If we forget to implement `Foo`, Rust will tell us:
|
||||
|
||||
```text
|
||||
error: the trait `main::Foo` is not implemented for the type `main::Baz` [E0277]
|
||||
error: the predicate `main::Baz : main::Foo` is not satisfied [E0277]
|
||||
```
|
||||
|
||||
# Deriving
|
||||
|
|
|
|||
|
|
@ -56,8 +56,8 @@ v[j];
|
|||
Indexing with a non-`usize` type gives an error that looks like this:
|
||||
|
||||
```text
|
||||
error: the trait `core::ops::Index<i32>` is not implemented for the type
|
||||
`collections::vec::Vec<_>` [E0277]
|
||||
error: the predicate `collections::vec::Vec<_> : core::ops::Index<i32>`
|
||||
is not satisfied [E0277]
|
||||
v[j];
|
||||
^~~~
|
||||
note: the type `collections::vec::Vec<_>` cannot be indexed by `i32`
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ fn main() {
|
|||
```
|
||||
|
||||
```text
|
||||
<anon>:10:5: 10:8 error: the trait `Trait` is not implemented for the type `&mut i32` [E0277]
|
||||
<anon>:10:5: 10:8 error: the predicate `&mut i32 : Trait` is not satisfied [E0277]
|
||||
<anon>:10 foo(t);
|
||||
^~~
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue