diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2022-12-13 18:55:00 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2022-12-15 10:15:41 -0800 |
| commit | f19488064a4752703fde8a3596a9d90ca2095534 (patch) | |
| tree | 85707ce865df42a8ca156f99fc45d9efd6d29637 /src/test | |
| parent | 984eab57f708e62c09b3d708033fe620130b5f39 (diff) | |
| download | rust-f19488064a4752703fde8a3596a9d90ca2095534.tar.gz rust-f19488064a4752703fde8a3596a9d90ca2095534.zip | |
Suggest constraining type parameter with `Clone`
Fix #34896.
Diffstat (limited to 'src/test')
3 files changed, 41 insertions, 0 deletions
diff --git a/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.fixed b/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.fixed new file mode 100644 index 00000000000..3e5ded6738b --- /dev/null +++ b/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.fixed @@ -0,0 +1,8 @@ +// run-rustfix +fn wat<T: Clone>(t: &T) -> T { + t.clone() //~ ERROR E0308 +} + +fn main() { + wat(&42); +} diff --git a/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.rs b/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.rs new file mode 100644 index 00000000000..1a5a38369ec --- /dev/null +++ b/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.rs @@ -0,0 +1,8 @@ +// run-rustfix +fn wat<T>(t: &T) -> T { + t.clone() //~ ERROR E0308 +} + +fn main() { + wat(&42); +} diff --git a/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr b/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr new file mode 100644 index 00000000000..01246955fae --- /dev/null +++ b/src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr @@ -0,0 +1,25 @@ +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 + | | + | this type parameter +LL | t.clone() + | ^^^^^^^^^ expected type parameter `T`, found `&T` + | + = note: expected type parameter `T` + found reference `&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: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. |
