-
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
Invalid suggestion to introduce as_ref()
for Option
used in a place expression
#99426
Comments
I've seen a PR fixing something similar (#96537), but it was closed due to inactivity. |
Right, originally this was an issue for wrong placement of `as_ref` which is still a bug on stable but has been fixed in nightly at some point, so I left this report as just a wrong as_ref ^^
18 Jul 2022 20:46:40 Vadim Petrochenkov ***@***.***>:
… I've seen a PR fixing something similar (#96537), but it was closed due to inactivity.
--
Reply to this email directly or view it on GitHub:
#99426 (comment)
You are receiving this because you authored the thread.
Message ID: ***@***.***>
|
Yeah, I fixed the
I looked into this, but couldn't find out from the borrowck diagnostic machinery how to tell whether a place is being accessed mutably or not. I can take another look at this though. @rustbot claim |
Worst case I could just change it to say " |
Ah, so I didn’t mean to imply that the relevant code knows this. A reasonable rule of thumb would be to see what context this expression is in. If it is a part of a place expression on the lhs of an assignment, |
Consider the following code
Here the diagnostic suggests to add
as_ref
as such:This suggestion is incorrect –
as_ref
will never (AFAIK) produce a mutable reference necessary for the assignment. We should suggestas_mut
where we know that a mutable reference will be required, instead.The text was updated successfully, but these errors were encountered: