-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Note if the user wants to use associated items of a trait directly #111324
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eff9a27
Note if the user wants to use associated items of a trait directly
mu001999 c6215f2
Add tests for issue 111312
mu001999 e977046
Bless other tests
mu001999 4f92085
Use span_label
mu001999 fe76d62
Fix wrong spaces
mu001999 2b97370
Update the note
mu001999 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
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,12 @@ | ||
// edition:2021 | ||
|
||
trait Has { | ||
fn has() {} | ||
} | ||
|
||
trait HasNot {} | ||
|
||
fn main() { | ||
HasNot::has(); //~ ERROR E0782 | ||
//~^ ERROR E0599 | ||
} |
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,28 @@ | ||
error[E0782]: trait objects must include the `dyn` keyword | ||
--> $DIR/issue-111312.rs:10:5 | ||
| | ||
LL | HasNot::has(); | ||
| ^^^^^^ no desired associated item found in this trait, if you do not want to use a bare trait object here | ||
| | ||
help: add `dyn` keyword before this trait | ||
| | ||
LL | <dyn HasNot>::has(); | ||
| ++++ + | ||
|
||
error[E0599]: no function or associated item named `has` found for trait object `dyn HasNot` in the current scope | ||
--> $DIR/issue-111312.rs:10:13 | ||
| | ||
LL | HasNot::has(); | ||
| ^^^ function or associated item not found in `dyn HasNot` | ||
| | ||
= help: items from traits can only be used if the trait is implemented and in scope | ||
note: `Has` defines an item `has`, perhaps you need to implement it | ||
--> $DIR/issue-111312.rs:3:1 | ||
| | ||
LL | trait Has { | ||
| ^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
Some errors have detailed explanations: E0599, E0782. | ||
For more information about an error, try `rustc --explain E0599`. |
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ error[E0782]: trait objects must include the `dyn` keyword | |
--> $DIR/dyn-trait-sugg-2021.rs:10:5 | ||
| | ||
LL | Foo::hi(123); | ||
| ^^^ | ||
| ^^^ no desired associated item found in this trait, if you do not want to use a bare trait object here | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is the only suggestion I don't think it helps much. It's probably better to first do something different for when |
||
| | ||
help: add `dyn` keyword before this trait | ||
| | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we checking
res
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I think there is no need to make this note for trait objects with multi traits such as
<TraitA + TraitB>::foo()