-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
When encountering move error on an Option
, suggest using as_ref
#61147
Conversation
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
r? @oli-obk |
Does this correctly handle |
Perhaps this should support |
@czipperz adding
Could you expand? |
I don't know if this is possible, but it would be nice if it suggested |
original_path.ty(self.mir, self.infcx.tcx).ty, | ||
); | ||
let snippet = self.infcx.tcx.sess.source_map().span_to_snippet(span).unwrap(); | ||
let is_option = orig_path_ty.starts_with("std::option::Option"); |
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 do you feel about waiting a bit with merging this PR (a bit being until #60966 is merged)? Then you can annotate Option
and Result
with #[rustc_diagnostic_item = "option"]
and "result"
respectively and then check for these items via
if let Some(adt) = original_path.ty(self.mir, self.infcx.tcx).adt_def() {
if self.infcx.tcx.is_diagnostic_item(adt.did, sym::option) {
...
}
}
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.
There are a couple of places where we're already doing string comparisons like this, so I love the fact that we'll be able to get rid of them soon!
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.
Hmm... or we can just merge this and fix it up later, doesn't seem like a big deal in fact.
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 fine either way
@czipperz suggesting both is bit heavy, but can be done. I'm a bit ambivalent on whether it is worth it. On one hand, it teaches the API surface nicely, on the other hand it is verbose and might confuse newcomers. |
My vote is for just suggesting |
Should I just remove the last commit or are there any further changes needed (beyond #60966)? |
r=me with last commit removed. I agree with your assessment that we'd be overwhelming users for little gain |
@bors r=oli-obk |
📌 Commit 1cc42ea has been approved by |
☀️ Test successful - checks-travis, status-appveyor |
Fix #61109, cc #15457.