Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPermit mutation of `&mut` pointers whose pointees have been borrowed #10520
Comments
This comment has been minimized.
This comment has been minimized.
|
cc me |
pnkfelix
referenced this issue
Nov 21, 2013
Closed
`&mut` references located in aliasable memory should be considered frozen #10445
nikomatsakis
referenced this issue
Jan 16, 2014
Closed
Allow reassigning a &mut to an inner pointer #11558
This comment has been minimized.
This comment has been minimized.
|
Issue #11558 includes another example. |
bill-myers
referenced this issue
Jan 19, 2014
Closed
Add a Mutex, AtomicU64, and deal with lots of related fallout #11610
This comment has been minimized.
This comment has been minimized.
|
Triage, no change that I know of. |
This comment has been minimized.
This comment has been minimized.
|
This may have become more important. As part of #20341, we started doing coercions on assignments of the form: x = yIf fn foo(mut vec: Vec<int>) {
let mut iter = vec.iter_mut();
let mut cur = iter.next().unwrap();
let mut next = iter.next().unwrap();
loop {
*next = 22; // ERROR cannot assign to `next` because it is borrowed
cur = next; // NOTE borrowed here
next = iter.next().unwrap();
}
}
fn main() {}This can be worked around by forcing a move using a dummy newtype: struct Dummy<T>(T);
fn foo(mut vec: Vec<isize>) {
let mut iter = vec.iter_mut();
let mut cur = Dummy(iter.next().unwrap());
let mut next = iter.next().unwrap();
loop {
*next = 22;
cur = Dummy(next);
next = iter.next().unwrap();
}
}
fn main() {}But that's awful! |
nikomatsakis
added
I-nominated
and removed
I-nominated
labels
Jan 9, 2015
This comment has been minimized.
This comment has been minimized.
|
Nominating because it may be worth trying to fix this for ergonomic reasons (or else maybe reverting the coercion change). |
nikomatsakis
referenced this issue
Feb 4, 2015
Closed
Borrow checking with loops, safe uninitailized variables, and conditional breaks. #19433
nikomatsakis
referenced this issue
Jun 17, 2015
Closed
Iterative mutable slicing doesn't work #18902
Gankro
added
the
A-borrow-checker
label
Jun 17, 2015
brson
added
the
I-wishlist
label
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Triage: closing. Old wishlist. Do RFC. |
brson
closed this
Jul 14, 2016
nikomatsakis
referenced this issue
Sep 18, 2016
Open
Permit mutation of `&mut` pointers whose pointees have been borrowed #1751
oli-obk
referenced this issue
Sep 6, 2017
Open
Meta issue for FIXMEs that reference closed issues #44366
nivkner
added a commit
to nivkner/rust
that referenced
this issue
Oct 7, 2017
This comment has been minimized.
This comment has been minimized.
|
Zombie revivification. The updated example is fn foo(mut vec: Vec<i32>) {
let mut iter = vec.iter_mut();
let mut cur = iter.next().unwrap();
let mut next = iter.next().unwrap();
loop {
*next = 22;
cur = next;
next = iter.next().unwrap();
}
}
fn main() {}And error:
This code now compiles with NLL enabled. |
nikomatsakis commentedNov 16, 2013
Now that the swap operator has been removed, I do not believe the
restriction against mutating
LVis needed, and in fact it preventssome useful patterns. For example, the following function will
fail to compile:
Note that this function -- which adjusts the slice
*xin place sothat it no longer contains the head element and then returns a
pointer to that element separately -- is perfectly valid. It is
currently implemented using unsafe code. I believe that now that
the swap operator is removed from the language, we could liberalize
the rules and make this function be accepted normally. The idea
would be to have the assignment to
*xkill the loans of*xandits subpaths -- after all, those subpaths are no longer accessible
through
*x, since it has been overwritten with a new value. Thusthose subpaths are only accessible through prior existing borrows
of
*x, if any. The danger of the swap operator was that itallowed
*xto be mutated without making the subpaths of*xinaccessible: worse, they became accessible through a new path (I
suppose that we could have supported a swap operator, too, if needed, by moving the loans over to the new path).