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 upInconsistent evaluation order for assignment operations #27868
Comments
eefriedman
referenced this issue
Aug 19, 2015
Closed
Primitive binops are translated wrong when the LHS is mutated #27054
bluss
added
the
I-wrong
label
Aug 19, 2015
eefriedman
referenced this issue
Sep 1, 2015
Open
Settle execution order uncertainty for `+=` #28160
This comment has been minimized.
This comment has been minimized.
|
triage: P-medium Also fixed by MIR (almost a dup of #28160, but not quite)/ |
rust-highfive
added
the
P-medium
label
Nov 19, 2015
brson
added
E-hard
A-lang
A-borrow-checker
labels
Aug 4, 2016
This comment has been minimized.
This comment has been minimized.
|
See this internals thread: https://internals.rust-lang.org/t/settling-execution-order-for/4253 |
steveklabnik
added
T-lang
and removed
A-lang
labels
Mar 24, 2017
This comment has been minimized.
This comment has been minimized.
|
So the internals thread says this: "before MIR, we were actually quite inconsistent here, in that borrowck and trans disagreed on some of the particulars. MIR eliminated that inconsistency, but there are still some matters that we should try to resolve -- and quick!" If that's the case, then this should be closed. @nikomatsakis Is this the case? |
This comment has been minimized.
This comment has been minimized.
|
Well, we're not yet running the borrowck on MIR, so I'm not sure. |
This comment has been minimized.
This comment has been minimized.
|
But certainly the example seems to work ok now. |
This comment has been minimized.
This comment has been minimized.
|
Assignment operators are still wrong, which can lead to use-after-free: use std::ops::AddAssign;
struct MyVec<T>(Vec<T>);
impl <T> Drop for MyVec<T> {
fn drop(&mut self) {
println!("Being dropped.");
}
}
impl<T> AddAssign<T> for MyVec<T> {
fn add_assign(&mut self, _elem: T) {
println!("In add_assign.");
}
}
fn main() {
let mut vec = MyVec(vec![0]);
let mut vecvec = vec![vec];
vecvec[0] += {
vecvec = vec![];
0
};
}Prints
Credit to @xfix for bringing this up in rust-lang/rfcs#2025 (comment), I just weaponized it. |
nikomatsakis
added
the
I-unsound 💥
label
Jun 15, 2017
Mark-Simulacrum
added
C-bug
and removed
I-wrong
labels
Jul 22, 2017
bstrie
referenced this issue
Sep 17, 2017
Open
borrowed referent of a `&T` sometimes incorrectly allowed #38899
pnkfelix
added
A-NLL
WG-compiler-nll
labels
Dec 21, 2017
This comment has been minimized.
This comment has been minimized.
|
@RalfJung's example gets an error with MIR borrowck enabled (as expected): https://play.rust-lang.org/?gist=761478ea89b3cd1df50ee274cb7a909d&version=nightly I am filing this under "bugs fixed by MIR borrowck" #47366 |
nikomatsakis
added
the
NLL-deferred
label
Apr 3, 2018
nikomatsakis
referenced this issue
Apr 3, 2018
Open
tracking issue for bugs fixed by the MIR borrow checker or NLL #47366
nikomatsakis
added
E-needstest
E-mentor
and removed
E-hard
labels
Apr 3, 2018
This comment has been minimized.
This comment has been minimized.
|
Marking as E-needstest and E-mentor: Since this code works now, what we need to do is add it to our test-suite. To do that, you would create a file in |
memoryruins
added a commit
to memoryruins/rust
that referenced
this issue
Aug 14, 2018
memoryruins
referenced this issue
Aug 14, 2018
Merged
[nll] add regression test for issue #27868 #53326
frewsxcv
added a commit
to frewsxcv/rust
that referenced
this issue
Aug 17, 2018
bors
added a commit
that referenced
this issue
Aug 17, 2018
nikomatsakis
removed
the
WG-compiler-nll
label
Aug 27, 2018
This comment has been minimized.
This comment has been minimized.
|
Apparently PR #53326 added the desired test here. So this is NLL-fixed-by-NLL now, I think. |
eefriedman commentedAug 17, 2015
•
edited by nikomatsakis
UPDATE: This is fixed by the MIR-based borrow checker and just needs a test. See the mentoring instructions below.
Currently, the borrow checker thinks that the RHS of
+=is evaluated before the LHS. trans thinks that the LHS is evaluated before the RHS. The disagreement leads to bad results.