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.
diagnostics: suggest
Clone
bounds when noop clone()
- Loading branch information
Showing
3 changed files
with
88 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#[derive(Clone)] | ||
struct ThingThatDoesAThing; | ||
|
||
trait DoesAThing {} | ||
|
||
impl DoesAThing for ThingThatDoesAThing {} | ||
|
||
fn clones_impl_ref_inline(thing: &impl DoesAThing) { | ||
//~^ HELP consider further restricting this bound | ||
drops_impl_owned(thing.clone()); //~ ERROR E0277 | ||
//~^ NOTE copies the reference | ||
//~| NOTE the trait `DoesAThing` is not implemented for `&impl DoesAThing` | ||
} | ||
|
||
fn drops_impl_owned(_thing: impl DoesAThing) { } | ||
|
||
fn main() { | ||
clones_impl_ref_inline(&ThingThatDoesAThing); | ||
} |
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,19 @@ | ||
error[E0277]: the trait bound `&impl DoesAThing: DoesAThing` is not satisfied | ||
--> $DIR/clone-bounds-121524.rs:10:22 | ||
| | ||
LL | drops_impl_owned(thing.clone()); | ||
| ^^^^^^^^^^^^^ the trait `DoesAThing` is not implemented for `&impl DoesAThing` | ||
| | ||
note: this `clone()` copies the reference, which does not do anything, because `impl DoesAThing` does not implement `Clone` | ||
--> $DIR/clone-bounds-121524.rs:10:28 | ||
| | ||
LL | drops_impl_owned(thing.clone()); | ||
| ^^^^^ | ||
help: consider further restricting this bound | ||
| | ||
LL | fn clones_impl_ref_inline(thing: &impl DoesAThing + Clone) { | ||
| +++++++ | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |