-
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
Inconsistent evaluation order for assignment operations #27868
Comments
triage: P-medium Also fixed by MIR (almost a dup of #28160, but not quite)/ |
See this internals thread: https://internals.rust-lang.org/t/settling-execution-order-for/4253 |
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? |
Well, we're not yet running the borrowck on MIR, so I'm not sure. |
But certainly the example seems to work ok now. |
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. |
@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 |
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 |
…omatsakis [nll] add regression test for issue rust-lang#27868 Adds a test for rust-lang#27868 ``Inconsistent evaluation order for assignment operations`` apart of rust-lang#47366 ``tracking issue for bugs fixed by the MIR borrow checker or NLL`` r? @nikomatsakis
Rollup of 11 pull requests Successful merges: - #52858 (Implement Iterator::size_hint for Elaborator.) - #53321 (Fix usage of `wasm_target_feature`) - #53326 ([nll] add regression test for issue #27868) - #53347 (rustc_resolve: don't allow paths starting with `::crate`.) - #53349 ([nll] add tests for #48697 and #30104) - #53357 (Pretty print btreemap for GDB) - #53358 (`{to,from}_{ne,le,be}_bytes` for unsigned integer types) - #53406 (Do not suggest conversion method that is already there) - #53407 (make more ported compile fail tests more robust w.r.t. NLL) - #53413 (Warn that `#![feature(rust_2018_preview)]` is implied when the edition is set to Rust 2018.) - #53434 (wasm: Remove --strip-debug argument to LLD) Failed merges: r? @ghost
Apparently PR #53326 added the desired test here. So this is NLL-fixed-by-NLL now, I think. |
NLL (migrate mode) is enabled in all editions as of PR #59114. The only policy question is that, under migrate mode, we only emit a warning on this (unsound) test case. Therefore, I am not 100% sure whether we should close this until that warning has been turned into a hard-error under our (still in development) future-compatibility lint policy. |
…hewjasper Rust 2015: No longer downgrade NLL errors As per decision on a language team meeting as described in rust-lang#63565 (comment), in Rust 2015, we refuse to downgrade NLL errors, that AST borrowck accepts, into warnings and keep them as hard errors. The remaining work to throw out AST borrowck and adjust some tests still remains after this PR. Fixes rust-lang#38899 Fixes rust-lang#53432 Fixes rust-lang#45157 Fixes rust-lang#31567 Fixes rust-lang#27868 Fixes rust-lang#47366 r? @matthewjasper
…hewjasper Rust 2015: No longer downgrade NLL errors As per decision on a language team meeting as described in rust-lang#63565 (comment), in Rust 2015, we refuse to downgrade NLL errors, that AST borrowck accepts, into warnings and keep them as hard errors. The remaining work to throw out AST borrowck and adjust some tests still remains after this PR. Fixes rust-lang#38899 Fixes rust-lang#53432 Fixes rust-lang#45157 Fixes rust-lang#31567 Fixes rust-lang#27868 Fixes rust-lang#47366 r? @matthewjasper
…hewjasper Rust 2015: No longer downgrade NLL errors As per decision on a language team meeting as described in rust-lang#63565 (comment), in Rust 2015, we refuse to downgrade NLL errors, that AST borrowck accepts, into warnings and keep them as hard errors. The remaining work to throw out AST borrowck and adjust some tests still remains after this PR. Fixes rust-lang#38899 Fixes rust-lang#53432 Fixes rust-lang#45157 Fixes rust-lang#31567 Fixes rust-lang#27868 Fixes rust-lang#47366 r? @matthewjasper
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.The text was updated successfully, but these errors were encountered: