-
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? 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
Changes from all commits
eff9a27
c6215f2
e977046
4f92085
fe76d62
2b97370
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
} |
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`. |
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 | ||
| | ||
|
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()