rust/tests/ui/suggestions/clone-on-unconstrained-borr...

46 lines
1.4 KiB
Plaintext

error[E0308]: mismatched types
--> $DIR/clone-on-unconstrained-borrowed-type-param.rs:3:5
|
LL | fn wat<T>(t: &T) -> T {
| - - expected `T` because of return type
| |
| expected this type parameter
LL | t.clone()
| ^^^^^^^^^ expected type parameter `T`, found `&T`
|
= note: expected type parameter `_`
found reference `&_`
= note: the caller chooses a type for `T` which can be different from `&T`
note: `T` does not implement `Clone`, so `&T` was cloned instead
--> $DIR/clone-on-unconstrained-borrowed-type-param.rs:3:5
|
LL | t.clone()
| ^
help: consider restricting type parameter `T`
|
LL | fn wat<T: Clone>(t: &T) -> T {
| +++++++
error[E0308]: mismatched types
--> $DIR/clone-on-unconstrained-borrowed-type-param.rs:9:5
|
LL | fn wut(t: &Foo) -> Foo {
| --- expected `Foo` because of return type
LL | t.clone()
| ^^^^^^^^^ expected `Foo`, found `&Foo`
|
note: `Foo` does not implement `Clone`, so `&Foo` was cloned instead
--> $DIR/clone-on-unconstrained-borrowed-type-param.rs:9:5
|
LL | t.clone()
| ^
help: consider annotating `Foo` with `#[derive(Clone)]`
|
LL + #[derive(Clone)]
LL | struct Foo;
|
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0308`.