You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Compiler should hint to user to deref when doing reference assignment #33570
In the general case (i.e. for arbitrary expr: T and let mut opt: &mut T), can we know whether the intention was
opt = &mut expr;
or if it was
*opt = expr;
?
I would be a little cautious about unilaterally suggesting the latter when the former is potentially what was desired...
Update: after thinking on the matter more (see bottom of comment), I am less nervous about a unilateral suggestion.
(However, when opt is declared as non-mut, I'm a little more amenable towards suggesting *opt = expr...)
Update: of course in many cases suggesting opt = &mut expr; will be a bad idea. E.g. opt = &mut None; will almost certainly yield a "borrowed value does not live long enough" message. Maybe there's some smarter analysis of the expr that can figure out when to not bother suggesting the nonsensical one.
Activity
pnkfelix commentedon May 11, 2016
In the general case (i.e. for arbitrary
expr: Tandlet mut opt: &mut T), can we know whether the intention wasor if it was
?
I would be a little cautious about unilaterally suggesting the latter when the former is potentially what was desired...
(However, when
optis declared as non-mut, I'm a little more amenable towards suggesting*opt = expr...)Update: of course in many cases suggesting
opt = &mut expr;will be a bad idea. E.g.opt = &mut None;will almost certainly yield a "borrowed value does not live long enough" message. Maybe there's some smarter analysis of theexprthat can figure out when to not bother suggesting the nonsensical one.durka commentedon May 11, 2016
@pnkfelix if
optismutyou could suggest both, otherwise just the dereference.estebank commentedon Sep 21, 2017
The compiler now suggests:
The suggestion is not smart enough to also suggest
*opt = None.estebank commentedon May 22, 2019
Update:
Compiler still not smart enough to suggest
*opt = None.Rollup merge of rust-lang#61054 - estebank:mut-ref-reassign, r=zackmd…