-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Note if the user wants to use associated items of a trait directly #111324
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
diag.note(format!( | ||
"desired associated item not found in trait `{}` if you want to use such one", | ||
snippet, | ||
)); | ||
} else { | ||
diag.note(format!( | ||
"desired associated item not found in this trait if you want to use such one", | ||
)); |
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.
You should probably just use a label here, instead of span_to_snippet
.
if in_path && res.len() == 0 { | ||
if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(self_ty.span) { | ||
diag.note(format!( | ||
"desired associated item not found in trait `{}` if you want to use such one", |
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.
I'm confused by this wording. It also seems redundant given the note that already exists: "no function or associated item named has
found for trait object dyn HasNot
in the current scope"
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.
This wording says that there is no direct associated item in this trait, and the dyn HasNot
in the existing note causes confusion (even though dyn HasNot
also contains associated item of HasNot
)
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.
I'm not sure if I understand what you mean by this, and I still think that this note is not adding any new information over the existing note.
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.
How about this: "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 comment
The reason will be displayed to describe this comment to others. Learn more.
The "trait object dyn HasNot
" in the existing note will confuse users.
@@ -3680,6 +3680,19 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { | |||
Applicability::MachineApplicable, | |||
); | |||
} | |||
// note if the user wants to use associated items of a trait directly | |||
if in_path && res.len() == 0 { |
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()
(I'm on mobile) could this use translatable diagnostics? |
I browsed this page about translation, but could not find such directory How do I use translatable diagnostics? Do I need to do anything other than add a new entry in |
| ^^^ | ||
| ^^^ 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 comment
The 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 <dyn A as B>::something
and dyn A: B
does not hold. Because in that case we are certain that the user didn't want A::something
to mean <dyn A as B>::something
.
This PR is not enough. I think we should improve E0782 instead and open a topic on internals |
Fixes #111312
Furthermore, bare trait objects have been denied after edition 2021. We could not treat traits without
dyn
as bare trait objects. For such cases, there is no need to use bare trait objects asrecv_ty/self_ty
(while usingNone
directly). This will lead to stop resolving early but it may require a bit more works to resolve compatibility issues.