forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#105679 - estebank:suggest-clone, r=compiler…
…-errors Suggest constraining type parameter with `Clone` Fix rust-lang#34896.
- Loading branch information
Showing
6 changed files
with
102 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// run-rustfix | ||
fn wat<T: Clone>(t: &T) -> T { | ||
t.clone() //~ ERROR E0308 | ||
} | ||
|
||
#[derive(Clone)] | ||
struct Foo; | ||
|
||
fn wut(t: &Foo) -> Foo { | ||
t.clone() //~ ERROR E0308 | ||
} | ||
|
||
fn main() { | ||
wat(&42); | ||
wut(&Foo); | ||
} |
15 changes: 15 additions & 0 deletions
15
src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// run-rustfix | ||
fn wat<T>(t: &T) -> T { | ||
t.clone() //~ ERROR E0308 | ||
} | ||
|
||
struct Foo; | ||
|
||
fn wut(t: &Foo) -> Foo { | ||
t.clone() //~ ERROR E0308 | ||
} | ||
|
||
fn main() { | ||
wat(&42); | ||
wut(&Foo); | ||
} |
43 changes: 43 additions & 0 deletions
43
src/test/ui/suggestions/clone-on-unconstrained-borrowed-type-param.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
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[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 struct `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)] | ||
| | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0308`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters