-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Matching on a place in borrowed context should no longer suggest ref
#52423
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
Comments
cc @ashtneoi |
Yeah, I can probably tackle this. |
For something like this...
...should it suggest changing the type, the pattern (which might be tricky, idk), or neither? |
@ashtneoi My personal goal is to have the compiler never mention fn bar<T>(MyStruct { x: _a }: &MyStruct<T>) ...but I have no idea how hard that might be. |
...Can we lint against top-level type declarations like that? It's really confusing trying to figure out the type of |
Oh, one more question (sorry): In a lot of cases, NLL already has better suggestions. Should I bother fixing the non-NLL suggestions or just focus on NLL assuming it'll land sometime soon? |
Oh, good point; I didn't try NLL. Only fixing the NLL ones sounds like a smart plan. |
It took a ton of reading (which is why I'm only now figuring it out), but I managed to put each binding's top-level pattern span into the |
For move errors, suggest match ergonomics instead of `ref` Partially fixes issue #52423. Also makes errors and suggestions more consistent between move-from-place and move-from-value errors. Limitations: - Only the first pattern in a match arm can have a "consider removing this borrow operator" suggestion. - Suggestions don't always compile as-is (see the TODOs in the test for details). Sorry for the really long test. I wanted to make sure I handled every case I could think of, and it turned out there were a lot of them. Questions: - Is there any particular applicability I should set on those suggestions? - Are the notes about the `Copy` trait excessive?
Current output:
|
This looks great! Thanks @ashtneoi! |
https://play.rust-lang.org/?gist=a88b996b2d1c86d1f6d32eee66c70cd4&version=stable&mode=debug&edition=2015
This suggests using
ref
:With match ergonomics now stable, it would be better to instead suggest borrowing the field:
To help people move away from needing to know that
ref
exists.(Context that lead me to open this: https://discordapp.com/channels/273534239310479360/274215136414400513/468303728986816512)
The text was updated successfully, but these errors were encountered: