-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Suggest dereferencing when Deref
is implemented.
#60155
Conversation
This commit adds a test that demonstrates the current behaviour where suggestions to add a dereference aren't given for non-references.
This commit suggests dereferencing a type when it implements `Deref` with the correct `Output` associated type.
src/librustc_typeck/check/demand.rs
Outdated
@@ -463,6 +463,57 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { | |||
} | |||
} | |||
} | |||
_ if sp == expr.span => { | |||
// If neither type is a reference, then check for `Deref` implementations by |
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.
Seems like a good place to refactor into function(s)?
General note: When I wrote the issue I hoped that we could deduplicate the logic on references with the new logic you wrote. References also implement |
I just tried this and I don't think it does, when I check if |
Maybe we need to try something different then. Check whether the type implements |
I have no idea what I was trying earlier, pushed a version that de-duplicates that logic. |
This commit makes the suggestion to dereference when a type implements `Deref` only apply if the dereference would succeed (ie. the type is `Copy`, otherwise a borrow check error would occur).
@bors r+ This is absolutely awesome! |
📌 Commit 7ab1bfd has been approved by |
☀️ Test successful - checks-travis, status-appveyor |
Fixes #59819.
r? @oli-obk
cc @estebank