-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix duplicate derive clone suggestion
- Loading branch information
Showing
3 changed files
with
96 additions
and
16 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,25 @@ | ||
// Reproduce the issue with vec | ||
pub struct NoDerives; | ||
fn fun1(foo: &mut Vec<NoDerives>, bar: &[NoDerives]) { | ||
foo.extend_from_slice(bar); //~ ERROR | ||
} | ||
|
||
// Reproduce the issue with vec | ||
// and demonstrate that other derives are ignored in the suggested output | ||
#[derive(Default, PartialEq)] | ||
pub struct SomeDerives; | ||
fn fun2(foo: &mut Vec<SomeDerives>, bar: &[SomeDerives]) { | ||
foo.extend_from_slice(bar); //~ ERROR | ||
} | ||
|
||
// Try and fail to reproduce the issue without vec. | ||
// No idea why it doesnt reproduce the issue but its still a useful test case. | ||
struct Object<T, A>(T, A); | ||
impl<T: Clone, A: Default> Object<T, A> { | ||
fn use_clone(&self) {} | ||
} | ||
fn fun3(foo: Object<NoDerives, SomeDerives>) { | ||
foo.use_clone(); //~ ERROR | ||
} | ||
|
||
fn main() {} |
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,54 @@ | ||
error[E0599]: the method `extend_from_slice` exists for mutable reference `&mut Vec<NoDerives>`, but its trait bounds were not satisfied | ||
--> $DIR/issue-91492.rs:4:9 | ||
| | ||
LL | pub struct NoDerives; | ||
| --------------------- doesn't satisfy `NoDerives: Clone` | ||
LL | fn fun1(foo: &mut Vec<NoDerives>, bar: &[NoDerives]) { | ||
LL | foo.extend_from_slice(bar); | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: the following trait bounds were not satisfied: | ||
`NoDerives: Clone` | ||
help: consider annotating `NoDerives` with `#[derive(Clone)]` | ||
| | ||
LL | #[derive(Clone)] | ||
| | ||
|
||
error[E0599]: the method `extend_from_slice` exists for mutable reference `&mut Vec<SomeDerives>`, but its trait bounds were not satisfied | ||
--> $DIR/issue-91492.rs:12:9 | ||
| | ||
LL | pub struct SomeDerives; | ||
| ----------------------- doesn't satisfy `SomeDerives: Clone` | ||
LL | fn fun2(foo: &mut Vec<SomeDerives>, bar: &[SomeDerives]) { | ||
LL | foo.extend_from_slice(bar); | ||
| ^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: the following trait bounds were not satisfied: | ||
`SomeDerives: Clone` | ||
help: consider annotating `SomeDerives` with `#[derive(Clone)]` | ||
| | ||
LL | #[derive(Clone)] | ||
| | ||
|
||
error[E0599]: the method `use_clone` exists for struct `Object<NoDerives, SomeDerives>`, but its trait bounds were not satisfied | ||
--> $DIR/issue-91492.rs:22:9 | ||
| | ||
LL | pub struct NoDerives; | ||
| --------------------- doesn't satisfy `NoDerives: Clone` | ||
... | ||
LL | struct Object<T, A>(T, A); | ||
| -------------------------- method `use_clone` not found for this | ||
... | ||
LL | foo.use_clone(); | ||
| ^^^^^^^^^ method cannot be called on `Object<NoDerives, SomeDerives>` due to unsatisfied trait bounds | ||
| | ||
= note: the following trait bounds were not satisfied: | ||
`NoDerives: Clone` | ||
help: consider annotating `NoDerives` with `#[derive(Clone)]` | ||
| | ||
LL | #[derive(Clone)] | ||
| | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0599`. |