-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #86943 - ptrojahn:suggest_derive, r=estebank
Suggest deriving traits if possible This only applies to builtin derives as I don't think there is a clean way to get the available derives in typeck. Closes #85851
- Loading branch information
Showing
11 changed files
with
235 additions
and
0 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
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
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
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,44 @@ | ||
use std::time::Instant; | ||
|
||
enum Enum { | ||
First | ||
} | ||
|
||
#[derive(Clone)] | ||
enum CloneEnum { | ||
First | ||
} | ||
|
||
struct Struct { | ||
} | ||
|
||
#[derive(Clone)] | ||
struct CloneStruct { | ||
} | ||
|
||
struct Foo<X, Y> (X, Y); | ||
impl<X: Clone + Default + , Y: Clone + Default> Foo<X, Y> { | ||
fn test(&self) -> (X, Y) { | ||
(self.0, self.1) | ||
} | ||
} | ||
|
||
fn test1() { | ||
let x = Foo(Enum::First, CloneEnum::First); | ||
let y = x.test(); | ||
//~^the method `test` exists for struct `Foo<Enum, CloneEnum>`, but its trait bounds were not satisfied [E0599] | ||
} | ||
|
||
fn test2() { | ||
let x = Foo(Struct{}, CloneStruct{}); | ||
let y = x.test(); | ||
//~^the method `test` exists for struct `Foo<Struct, CloneStruct>`, but its trait bounds were not satisfied [E0599] | ||
} | ||
|
||
fn test3() { | ||
let x = Foo(Vec::<Enum>::new(), Instant::now()); | ||
let y = x.test(); | ||
//~^the method `test` exists for struct `Foo<Vec<Enum>, Instant>`, but its trait bounds were not satisfied [E0599] | ||
} | ||
|
||
fn main() {} |
84 changes: 84 additions & 0 deletions
84
src/test/ui/suggestions/derive-trait-for-method-call.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,84 @@ | ||
error[E0599]: the method `test` exists for struct `Foo<Enum, CloneEnum>`, but its trait bounds were not satisfied | ||
--> $DIR/derive-trait-for-method-call.rs:28:15 | ||
| | ||
LL | enum Enum { | ||
| --------- | ||
| | | ||
| doesn't satisfy `Enum: Clone` | ||
| doesn't satisfy `Enum: Default` | ||
... | ||
LL | enum CloneEnum { | ||
| -------------- doesn't satisfy `CloneEnum: Default` | ||
... | ||
LL | struct Foo<X, Y> (X, Y); | ||
| ------------------------ method `test` not found for this | ||
... | ||
LL | let y = x.test(); | ||
| ^^^^ method cannot be called on `Foo<Enum, CloneEnum>` due to unsatisfied trait bounds | ||
| | ||
= note: the following trait bounds were not satisfied: | ||
`Enum: Clone` | ||
`Enum: Default` | ||
`CloneEnum: Default` | ||
help: consider annotating `Enum` with `#[derive(Clone)]` | ||
| | ||
LL | #[derive(Clone)] | ||
| | ||
|
||
error[E0599]: the method `test` exists for struct `Foo<Struct, CloneStruct>`, but its trait bounds were not satisfied | ||
--> $DIR/derive-trait-for-method-call.rs:34:15 | ||
| | ||
LL | struct Struct { | ||
| ------------- | ||
| | | ||
| doesn't satisfy `Struct: Clone` | ||
| doesn't satisfy `Struct: Default` | ||
... | ||
LL | struct CloneStruct { | ||
| ------------------ doesn't satisfy `CloneStruct: Default` | ||
... | ||
LL | struct Foo<X, Y> (X, Y); | ||
| ------------------------ method `test` not found for this | ||
... | ||
LL | let y = x.test(); | ||
| ^^^^ method cannot be called on `Foo<Struct, CloneStruct>` due to unsatisfied trait bounds | ||
| | ||
= note: the following trait bounds were not satisfied: | ||
`Struct: Clone` | ||
`Struct: Default` | ||
`CloneStruct: Default` | ||
help: consider annotating `CloneStruct` with `#[derive(Default)]` | ||
| | ||
LL | #[derive(Default)] | ||
| | ||
help: consider annotating `Struct` with `#[derive(Clone, Default)]` | ||
| | ||
LL | #[derive(Clone, Default)] | ||
| | ||
|
||
error[E0599]: the method `test` exists for struct `Foo<Vec<Enum>, Instant>`, but its trait bounds were not satisfied | ||
--> $DIR/derive-trait-for-method-call.rs:40:15 | ||
| | ||
LL | struct Foo<X, Y> (X, Y); | ||
| ------------------------ method `test` not found for this | ||
... | ||
LL | let y = x.test(); | ||
| ^^^^ method cannot be called on `Foo<Vec<Enum>, Instant>` due to unsatisfied trait bounds | ||
| | ||
::: $SRC_DIR/std/src/time.rs:LL:COL | ||
| | ||
LL | pub struct Instant(time::Instant); | ||
| ---------------------------------- doesn't satisfy `Instant: Default` | ||
| | ||
::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL | ||
| | ||
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> { | ||
| ------------------------------------------------------------------------------------------------ doesn't satisfy `Vec<Enum>: Clone` | ||
| | ||
= note: the following trait bounds were not satisfied: | ||
`Vec<Enum>: Clone` | ||
`Instant: Default` | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0599`. |
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
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