-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
remove the unused :: between trait and type to give user correct diag… #102421
Merged
Merged
Changes from all commits
Commits
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 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,15 @@ | ||
trait TraitA<T> { | ||
fn func(); | ||
} | ||
|
||
struct StructA {} | ||
|
||
impl TraitA<i32> for StructA { | ||
fn func() {} | ||
} | ||
|
||
fn main() { | ||
TraitA::<i32>::func(); | ||
//~^ ERROR: cannot call associated function on trait without specifying the corresponding `impl` type [E0790] | ||
//~| help: use the fully-qualified path to the only available implementation | ||
} |
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,18 @@ | ||
error[E0790]: cannot call associated function on trait without specifying the corresponding `impl` type | ||
--> $DIR/issue-101866.rs:12:5 | ||
| | ||
LL | fn func(); | ||
| ---------- `TraitA::func` defined here | ||
... | ||
LL | TraitA::<i32>::func(); | ||
| ^^^^^^^^^^^^^^^^^^^ cannot call associated function of trait | ||
| | ||
help: use the fully-qualified path to the only available implementation | ||
| | ||
LL - TraitA::<i32>::func(); | ||
LL + <::StructA as TraitA<i32>>::func(); | ||
| | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0790`. |
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.
sidenote, using
self.tcx.def_path(impl_def_id).to_string_no_crate_verbose()
here feels wrong, I would expect us to useself.tcx.type_of(impl_def_id)
here to print the self type. rn this is causing us to print::StructA
instead ofStructA
.@lyming2007 would you be interested in changing this in a followup pr?
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.
both
<::StructA as TraitA<i32>>::func()
and<StructA as TraitA<i32>>::func()
will work for the compiler.Do we really need to change it from
::StructA
toStructA
?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.
we don't need to do it, but it's a lot more idiomatic to use
StructA
instead of::StructA
. Using::StructA
is pretty confusing to most people, so it's better to avoid imoThere 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.
see this PR #102670 @lcnr