-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Suggest blanket impl to the local traits #97488
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
58 changes: 58 additions & 0 deletions
58
src/test/ui/suggestions/suggest-blanket-impl-local-trait.rs
This file contains hidden or 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,58 @@ | ||
// Ensure that the compiler include the blanklet implementation suggestion | ||
// when inside a `impl` statment are used two local traits. | ||
// | ||
// edition:2021 | ||
use std::fmt; | ||
|
||
trait LocalTraitOne { } | ||
|
||
trait LocalTraitTwo { } | ||
|
||
trait GenericTrait<T> {} | ||
|
||
impl LocalTraitTwo for LocalTraitOne {} | ||
vincenzopalazzo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
//~^ ERROR trait objects must include the `dyn` keyword | ||
//~| HELP add `dyn` keyword before this trait | ||
//~| HELP alternatively use a blanket implementation to implement `LocalTraitTwo` for all types that also implement `LocalTraitOne` | ||
|
||
impl fmt::Display for LocalTraitOne { | ||
//~^ ERROR trait objects must include the `dyn` keyword | ||
//~| HELP add `dyn` keyword before this trait | ||
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
todo!(); | ||
} | ||
} | ||
|
||
impl fmt::Display for LocalTraitTwo + Send { | ||
//~^ ERROR trait objects must include the `dyn` keyword | ||
//~| HELP add `dyn` keyword before this trait | ||
fn fmt(&self, _f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
todo!(); | ||
} | ||
} | ||
|
||
impl LocalTraitOne for fmt::Display {} | ||
//~^ ERROR trait objects must include the `dyn` keyword | ||
//~| HELP add `dyn` keyword before this trait | ||
//~| HELP alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display` | ||
|
||
|
||
impl LocalTraitOne for fmt::Display + Send {} | ||
//~^ ERROR trait objects must include the `dyn` keyword | ||
//~| HELP add `dyn` keyword before this trait | ||
//~| HELP alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display + Send` | ||
|
||
|
||
impl<E> GenericTrait<E> for LocalTraitOne {} | ||
//~^ ERROR trait objects must include the `dyn` keyword | ||
//~| HELP add `dyn` keyword before this trait | ||
//~| HELP alternatively use a blanket implementation to implement `GenericTrait<E>` for all types that also implement `LocalTraitOne` | ||
|
||
trait GenericTraitTwo<T> {} | ||
|
||
impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {} | ||
//~^ ERROR trait objects must include the `dyn` keyword | ||
//~| HELP add `dyn` keyword before this trait | ||
//~| HELP alternatively use a blanket implementation to implement `GenericTraitTwo<E>` for all types that also implement `GenericTrait<T>` | ||
|
||
fn main() {} |
107 changes: 107 additions & 0 deletions
107
src/test/ui/suggestions/suggest-blanket-impl-local-trait.stderr
This file contains hidden or 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,107 @@ | ||
error[E0782]: trait objects must include the `dyn` keyword | ||
--> $DIR/suggest-blanket-impl-local-trait.rs:13:24 | ||
| | ||
LL | impl LocalTraitTwo for LocalTraitOne {} | ||
| ^^^^^^^^^^^^^ | ||
| | ||
help: add `dyn` keyword before this trait | ||
| | ||
LL - impl LocalTraitTwo for LocalTraitOne {} | ||
LL + impl LocalTraitTwo for dyn LocalTraitOne {} | ||
| | ||
help: alternatively use a blanket implementation to implement `LocalTraitTwo` for all types that also implement `LocalTraitOne` | ||
| | ||
LL | impl<T: LocalTraitOne> LocalTraitTwo for T {} | ||
| ++++++++++++++++++ ~ | ||
|
||
error[E0782]: trait objects must include the `dyn` keyword | ||
--> $DIR/suggest-blanket-impl-local-trait.rs:18:23 | ||
| | ||
LL | impl fmt::Display for LocalTraitOne { | ||
| ^^^^^^^^^^^^^ | ||
| | ||
help: add `dyn` keyword before this trait | ||
| | ||
LL - impl fmt::Display for LocalTraitOne { | ||
LL + impl fmt::Display for dyn LocalTraitOne { | ||
| | ||
|
||
error[E0782]: trait objects must include the `dyn` keyword | ||
--> $DIR/suggest-blanket-impl-local-trait.rs:26:23 | ||
| | ||
LL | impl fmt::Display for LocalTraitTwo + Send { | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: add `dyn` keyword before this trait | ||
| | ||
LL - impl fmt::Display for LocalTraitTwo + Send { | ||
LL + impl fmt::Display for dyn LocalTraitTwo + Send { | ||
| | ||
|
||
error[E0782]: trait objects must include the `dyn` keyword | ||
--> $DIR/suggest-blanket-impl-local-trait.rs:34:24 | ||
| | ||
LL | impl LocalTraitOne for fmt::Display {} | ||
| ^^^^^^^^^^^^ | ||
| | ||
help: add `dyn` keyword before this trait | ||
| | ||
LL - impl LocalTraitOne for fmt::Display {} | ||
LL + impl LocalTraitOne for dyn fmt::Display {} | ||
| | ||
help: alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display` | ||
| | ||
LL | impl<T: fmt::Display> LocalTraitOne for T {} | ||
| +++++++++++++++++ ~ | ||
|
||
error[E0782]: trait objects must include the `dyn` keyword | ||
--> $DIR/suggest-blanket-impl-local-trait.rs:40:24 | ||
| | ||
LL | impl LocalTraitOne for fmt::Display + Send {} | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: add `dyn` keyword before this trait | ||
| | ||
LL - impl LocalTraitOne for fmt::Display + Send {} | ||
LL + impl LocalTraitOne for dyn fmt::Display + Send {} | ||
| | ||
help: alternatively use a blanket implementation to implement `LocalTraitOne` for all types that also implement `fmt::Display + Send` | ||
| | ||
LL | impl<T: fmt::Display + Send> LocalTraitOne for T {} | ||
| ++++++++++++++++++++++++ ~ | ||
|
||
error[E0782]: trait objects must include the `dyn` keyword | ||
--> $DIR/suggest-blanket-impl-local-trait.rs:46:29 | ||
| | ||
LL | impl<E> GenericTrait<E> for LocalTraitOne {} | ||
| ^^^^^^^^^^^^^ | ||
| | ||
help: add `dyn` keyword before this trait | ||
| | ||
LL - impl<E> GenericTrait<E> for LocalTraitOne {} | ||
LL + impl<E> GenericTrait<E> for dyn LocalTraitOne {} | ||
| | ||
help: alternatively use a blanket implementation to implement `GenericTrait<E>` for all types that also implement `LocalTraitOne` | ||
| | ||
LL | impl<E, T: LocalTraitOne> GenericTrait<E> for T {} | ||
| ++++++++++++++++++ ~ | ||
|
||
error[E0782]: trait objects must include the `dyn` keyword | ||
--> $DIR/suggest-blanket-impl-local-trait.rs:53:35 | ||
| | ||
LL | impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {} | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
help: add `dyn` keyword before this trait | ||
| | ||
LL - impl<T, E> GenericTraitTwo<E> for GenericTrait<T> {} | ||
LL + impl<T, E> GenericTraitTwo<E> for dyn GenericTrait<T> {} | ||
| | ||
help: alternatively use a blanket implementation to implement `GenericTraitTwo<E>` for all types that also implement `GenericTrait<T>` | ||
| | ||
LL | impl<T, E, U: GenericTrait<T>> GenericTraitTwo<E> for U {} | ||
| ++++++++++++++++++++ ~ | ||
|
||
error: aborting due to 7 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0782`. |
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.