forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Suggest constraining type parameter with
Clone
Fix rust-lang#34896.
- Loading branch information
Showing
4 changed files
with
55 additions
and
1 deletion.
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
8 changes: 8 additions & 0 deletions
8
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,8 @@ | ||
// run-rustfix | ||
fn wat<T: Clone>(t: &T) -> T { | ||
t.clone() //~ ERROR E0308 | ||
} | ||
|
||
fn main() { | ||
wat(&42); | ||
} |
8 changes: 8 additions & 0 deletions
8
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,8 @@ | ||
// run-rustfix | ||
fn wat<T>(t: &T) -> T { | ||
t.clone() //~ ERROR E0308 | ||
} | ||
|
||
fn main() { | ||
wat(&42); | ||
} |
25 changes: 25 additions & 0 deletions
25
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,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`. |