Skip to content
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

First attempt at removing DropAndReplace #104488

Closed
wants to merge 13 commits into from

Conversation

zeegomo
Copy link
Contributor

@zeegomo zeegomo commented Nov 16, 2022

First attempt at removing the DropAndReplace terminator which complicates things a bit in some cases.
Based on zulip/drop-to-drop-if

Eventually, I re-introduced a flag in the Drop terminator to indicate whether this drop is from a drop and replace operation. This is used mainly for better diagnostic and to check some invariants.

Failing UI Tests

  • Diagnostic underline whole assignment instead of just the left value

ex:

71	LL |     *ap0 = ap1;
-	   |     ^^^^ assignment requires that `'2` must outlive `'1`
+	   |     ^^^^^^^^^^ assignment requires that `'2` must outlive `'1`
73	   |

[ui] src/test/ui/borrowck/borrowck-field-sensitivity.rs
[ui] src/test/ui/borrowck/borrowck-issue-48962.rs
[ui] src/test/ui/borrowck/borrowck-loan-of-static-data-issue-27616.rs
[ui] src/test/ui/borrowck/borrowck-partial-reinit-1.rs
[ui] src/test/ui/borrowck/borrowck-partial-reinit-2.rs
[ui] src/test/ui/borrowck/borrowck-partial-reinit-4.rs
[ui] src/test/ui/borrowck/borrowck-vec-pattern-nesting.rs
[ui] src/test/ui/borrowck/index-mut-help.rs
[ui] src/test/ui/borrowck/issue-45199.rs
[ui] src/test/ui/c-variadic/variadic-ffi-4.rs
[ui] src/test/ui/closures/2229_closure_analysis/diagnostics/box.rs
[ui] src/test/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs
[ui] src/test/ui/nll/issue-27868.rs
[ui] src/test/ui/object-lifetime/object-lifetime-default-from-box-error.rs
[ui] src/test/ui/regions/regions-infer-paramd-indirect.rs
[ui] src/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-1.rs

  • Replace kills loans on previous value

12	LL |     println!("thread result: {:?}", res);
13	   |                                     --- borrow later used here
14	
-	error[E0505]: cannot move out of `greeting` because it is borrowed
-	  --> $DIR/issue-58776-borrowck-scans-children.rs:7:10
-	   |
-	LL |     let res = (|| (|| &greeting)())();
-	   |                --      -------- borrow occurs due to use in closure
-	   |                |
-	   |                borrow of `greeting` occurs here
-	...
-	LL |     drop(greeting);
-	   |          ^^^^^^^^ move out of `greeting` occurs here
-	...
-	LL |     println!("thread result: {:?}", res);
-	   |                                     --- borrow later used here
+	error: aborting due to previous error
28	
-	error: aborting due to 2 previous errors
-	
-	Some errors have detailed explanations: E0505, E0506.
-	For more information about an error, try `rustc --explain E0505`.
+	For more information about this error, try `rustc --explain E0506`.
33	

destructured assignment from drop and replace now kills loans. I don't think it's too big of an issue as the assignment should already trigger the borrowck, but the compiler now reports fewer errors in some cases
[ui] src/test/ui/borrowck/issue-58776-borrowck-scans-children.rs

Also fixes #70919 but I didn't add any regression tests for it, might borrow them from #102078 in a separate PR once this lands

@rustbot
Copy link
Collaborator

rustbot commented Nov 16, 2022

r? @compiler-errors

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 16, 2022
@zeegomo zeegomo force-pushed the drop-elab branch 3 times, most recently from 8fdcab4 to aec002f Compare November 16, 2022 14:47
@rust-log-analyzer

This comment has been minimized.

@compiler-errors
Copy link
Member

r? @nikomatsakis since I think he wrote the MCP.

@bors
Copy link
Contributor

bors commented Nov 17, 2022

☔ The latest upstream changes (presumably #103138) made this pull request unmergeable. Please resolve the merge conflicts.

@zeegomo
Copy link
Contributor Author

zeegomo commented Dec 27, 2022

Figured out what the problem with the future size was.
The desugaring of a = b; in drop(a); assign(a, b) at MIR creation might create dead MIR blocks on the unwind path, because the drop is a no-op (e.g. the variable is certainly dead at this stage) or can't unwind.
During drop elaboration, we run some dataflow analyses to track the initialization state of the variables to drop and here's the problem.
For some reason (would love some insight), we push all MIR blocks in the dataflow work queue and process them, even thought they might not be reachable from the start (just talking about forward analyses).
In this case, this cause processing of dead blocks which propagate incorrect values for liveness analysis.
My solution was to change the fixpoint alg to only consider blocks reachable from the start.
For backwards compatibility this can be tweaked with a flag, might be useful for other analyses as well.

Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial round of comments

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs Outdated Show resolved Hide resolved
compiler/rustc_borrowck/src/invalidation.rs Outdated Show resolved Hide resolved
compiler/rustc_borrowck/src/invalidation.rs Outdated Show resolved Hide resolved
compiler/rustc_borrowck/src/lib.rs Outdated Show resolved Hide resolved
compiler/rustc_borrowck/src/used_muts.rs Outdated Show resolved Hide resolved
compiler/rustc_const_eval/src/transform/validate.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_build/src/build/scope.rs Show resolved Hide resolved
compiler/rustc_mir_dataflow/src/framework/engine.rs Outdated Show resolved Hide resolved
compiler/rustc_mir_transform/src/dest_prop.rs Outdated Show resolved Hide resolved
Some(Option::unwrap_or(unwind, resume_block))
},
is_replace,
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't follow this logic

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's this case here

// drop and replace behind a pointer/array/whatever. The location
, will add a better comment

@zeegomo zeegomo marked this pull request as ready for review January 1, 2023 21:09
@rustbot
Copy link
Collaborator

rustbot commented Jan 1, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

This PR changes MIR

cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

@zeegomo
Copy link
Contributor Author

zeegomo commented Jan 1, 2023

Some of the changes here like 114c696 could be moved to a separate independent PR.
Not sure of what's your preference on this, didn't want to split the discussion in too many places

some changes merged separately in #106451

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Jan 5, 2023

☔ The latest upstream changes (presumably #106472) made this pull request unmergeable. Please resolve the merge conflicts.

@zeegomo zeegomo force-pushed the drop-elab branch 2 times, most recently from 2303e04 to 54adf94 Compare January 5, 2023 09:35
@rust-log-analyzer

This comment has been minimized.

* document is_replace field in Drop terminator
* clarify drop and replace of untracked value
Add DesugaringKind::Replace to emit better diagnostic messages.
At the moment it is used for drop and replaces and only the
spans that actually contain a `Drop` terminator are marked as such.
As there are no explicit drop correspondents in the HIR,
marking happens during MIR build.
@zeegomo
Copy link
Contributor Author

zeegomo commented Jan 10, 2023

@oli-obk suggestion to use https://doc.rust-lang.org/nightly/nightly-rustc/rustc_span/struct.Span.html#method.mark_with_reason seems to be very promising.
I was able to remove is_replace entirely and retain all the checks in the borrowck.
There are now a few additional changes in ui tests but are still regarding the assignment span, which I believe should be ok.

@rust-log-analyzer

This comment has been minimized.

DesugaringKind::Replace is added at MIR build and does not show
up in the HIR. Remove the desugaring from the span when walking
down the HIR in diagnostic so that the span from the HIR correctly
matches the span from MIR.
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-13 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
............................................................i........................... 880/14144
........................................................................i............... 968/14144
........................................................................................ 1056/14144
........................................................................................ 1144/14144
..................................F..................F........F..F...................... 1232/14144
..............F..........F...F...F...............................................F...... 1320/14144
......F.................F..................F..................................i......... 1408/14144
.......................................................................................F 1496/14144
.....................................................................F.................. 1672/14144
........................................................................................ 1760/14144
........................................................................................ 1848/14144
.i...................i...........ii..................................................... 1936/14144
---

---- [ui] checkout/tests/ui/borrowck/borrowck-field-sensitivity.rs stdout ----
diff of stderr:

134 LL |     let mut x: A;
135    |         ----- binding declared here but left uninitialized
136 LL |     x.b = Box::new(1);
-    |     ^^^ `x` partially assigned here but it isn't fully initialized
+    |     ^^^^^^^^^^^^^^^^^ `x` partially assigned here but it isn't fully initialized
138    |
139    = help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-field-sensitivity/borrowck-field-sensitivity.stderr
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-field-sensitivity/borrowck-field-sensitivity.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args borrowck/borrowck-field-sensitivity.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/borrowck-field-sensitivity.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-field-sensitivity" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-field-sensitivity/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0382]: use of moved value: `x.b`
   |
LL |     drop(x.b);
   |          --- value moved here
   |          --- value moved here
LL |     drop(*x.b); //~ ERROR use of moved value: `x.b`
   |          ^^^^ value used here after move
   |
   = note: move occurs because `x.b` has type `Box<isize>`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `x.b`
  --> /checkout/tests/ui/borrowck/borrowck-field-sensitivity.rs:14:10
   |
   |
LL |     let y = A { a: 3, .. x };
   |             ---------------- value moved here
LL |     drop(*x.b); //~ ERROR use of moved value: `x.b`
   |          ^^^^ value used here after move
   |
   = note: move occurs because `x.b` has type `Box<isize>`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `x.b`
  --> /checkout/tests/ui/borrowck/borrowck-field-sensitivity.rs:20:13
   |
LL |     drop(x.b);
LL |     drop(x.b);
   |          --- value moved here
LL |     let p = &x.b; //~ ERROR borrow of moved value: `x.b`
   |
   |
   = note: move occurs because `x.b` has type `Box<isize>`, which does not implement the `Copy` trait
error[E0382]: borrow of moved value: `x.b`
  --> /checkout/tests/ui/borrowck/borrowck-field-sensitivity.rs:27:13
   |
   |
LL |     let _y = A { a: 3, .. x };
   |              ---------------- value moved here
LL |     let p = &x.b; //~ ERROR borrow of moved value: `x.b`
   |
   |
   = note: move occurs because `x.b` has type `Box<isize>`, which does not implement the `Copy` trait

error[E0505]: cannot move out of `x.b` because it is borrowed
   |
   |
LL |     let p = &x.b;
   |             ---- borrow of `x.b` occurs here
LL |     drop(x.b); //~ ERROR cannot move out of `x.b` because it is borrowed
   |          ^^^ move out of `x.b` occurs here
LL |     drop(**p);


error[E0505]: cannot move out of `x.b` because it is borrowed
   |
   |
LL |     let p = &x.b;
   |             ---- borrow of `x.b` occurs here
LL |     let _y = A { a: 3, .. x }; //~ ERROR cannot move out of `x.b` because it is borrowed
   |              ^^^^^^^^^^^^^^^^ move out of `x.b` occurs here
LL |     drop(**p);


error[E0499]: cannot borrow `x.a` as mutable more than once at a time
   |
LL |     let p = &mut x.a;
   |             -------- first mutable borrow occurs here
   |             -------- first mutable borrow occurs here
LL |     let q = &mut x.a; //~ ERROR cannot borrow `x.a` as mutable more than once at a time
   |             ^^^^^^^^ second mutable borrow occurs here
LL |     drop(*p);

error[E0382]: use of moved value: `x.b`
  --> /checkout/tests/ui/borrowck/borrowck-field-sensitivity.rs:56:10
   |
   |
LL |     drop(x.b);
   |          --- value moved here
LL |     drop(x.b);  //~ ERROR use of moved value: `x.b`
   |          ^^^ value used here after move
   |
   = note: move occurs because `x.b` has type `Box<isize>`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `x.b`
  --> /checkout/tests/ui/borrowck/borrowck-field-sensitivity.rs:62:10
   |
   |
LL |     let _y = A { a: 3, .. x };
   |              ---------------- value moved here
LL |     drop(x.b);  //~ ERROR use of moved value: `x.b`
   |          ^^^ value used here after move
   |
   = note: move occurs because `x.b` has type `Box<isize>`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `x.b`
  --> /checkout/tests/ui/borrowck/borrowck-field-sensitivity.rs:68:14
   |
LL |     drop(x.b);
LL |     drop(x.b);
   |          --- value moved here
LL |     let _z = A { a: 3, .. x };  //~ ERROR use of moved value: `x.b`
   |              ^^^^^^^^^^^^^^^^ value used here after move
   |
   = note: move occurs because `x.b` has type `Box<isize>`, which does not implement the `Copy` trait
error[E0382]: use of moved value: `x.b`
  --> /checkout/tests/ui/borrowck/borrowck-field-sensitivity.rs:74:14
   |
   |
LL |     let _y = A { a: 3, .. x };
   |              ---------------- value moved here
LL |     let _z = A { a: 4, .. x };  //~ ERROR use of moved value: `x.b`
   |              ^^^^^^^^^^^^^^^^ value used here after move
   |
   = note: move occurs because `x.b` has type `Box<isize>`, which does not implement the `Copy` trait

error[E0381]: partially assigned binding `x` isn't fully initialized
   |
LL |     let mut x: A;
LL |     let mut x: A;
   |         ----- binding declared here but left uninitialized
LL |     x.a = 1; //~ ERROR E0381
   |     ^^^^^^^ `x` partially assigned here but it isn't fully initialized
   |
   = help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`

error[E0381]: partially assigned binding `x` isn't fully initialized
   |
LL |     let mut x: A;
LL |     let mut x: A;
   |         ----- binding declared here but left uninitialized
LL |     x.a = 1; //~ ERROR E0381
   |     ^^^^^^^ `x` partially assigned here but it isn't fully initialized
   |
   = help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`

error[E0381]: partially assigned binding `x` isn't fully initialized
   |
LL |     let mut x: A;
LL |     let mut x: A;
   |         ----- binding declared here but left uninitialized
LL |     x.b = Box::new(1); //~ ERROR E0381
   |     ^^^^^^^^^^^^^^^^^ `x` partially assigned here but it isn't fully initialized
   |
   = help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to 14 previous errors

Some errors have detailed explanations: E0381, E0382, E0499, E0505.
For more information about an error, try `rustc --explain E0381`.
---
To only update this specific test, also pass `--test-args borrowck/borrowck-issue-48962.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/borrowck-issue-48962.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-issue-48962" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-issue-48962/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0382]: use of moved value: `src`
   |
LL |     let mut src = &mut node;
LL |     let mut src = &mut node;
   |         ------- move occurs because `src` has type `&mut Node`, which does not implement the `Copy` trait
LL |     {src};
   |      --- value moved here
LL |     src.next = None; //~ ERROR use of moved value: `src` [E0382]
   |     ^^^^^^^^^^^^^^^ value used here after move
error[E0382]: use of moved value: `src`
  --> /checkout/tests/ui/borrowck/borrowck-issue-48962.rs:20:5
   |
   |
LL |     let mut src = &mut (22, 44);
   |         ------- move occurs because `src` has type `&mut (i32, i32)`, which does not implement the `Copy` trait
LL |     {src};
   |      --- value moved here
LL |     src.0 = 66; //~ ERROR use of moved value: `src` [E0382]
   |     ^^^^^^^^^^ value used here after move
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0382`.
------------------------------------------
------------------------------------------


---- [ui] checkout/tests/ui/borrowck/borrowck-lend-flow-loop.rs stdout ----
diff of stderr:

8    |                ^^^ immutable borrow occurs here
9 LL |     }
10 LL |     *x = Box::new(5);
-    |     -- mutable borrow later used here
+    |     ---------------- mutable borrow later used here
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
Some tests failed in compiletest suite=ui mode=ui host=x86_64-unknown-linux-gnu target=x86_64-unknown-linux-gnu
13 error[E0502]: cannot borrow `*v` as immutable because it is also borrowed as mutable


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-lend-flow-loop/borrowck-lend-flow-loop.stderr
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-lend-flow-loop/borrowck-lend-flow-loop.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args borrowck/borrowck-lend-flow-loop.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/borrowck-lend-flow-loop.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-lend-flow-loop" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-lend-flow-loop/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0502]: cannot borrow `*v` as immutable because it is also borrowed as mutable
   |
LL |     let mut x = &mut v;
LL |     let mut x = &mut v;
   |                 ------ mutable borrow occurs here
LL |     for _ in 0..3 {
LL |         borrow(&*v); //~ ERROR cannot borrow
   |                ^^^ immutable borrow occurs here
LL |     }
LL |     *x = Box::new(5);
   |     ---------------- mutable borrow later used here

error[E0502]: cannot borrow `*v` as immutable because it is also borrowed as mutable
   |
   |
LL |         **x += 1;
   |         -------- mutable borrow later used here
LL |         borrow(&*v); //~ ERROR cannot borrow
   |                ^^^ immutable borrow occurs here
LL |         if cond2 {
LL |             x = &mut v; // OK
   |                 ------ mutable borrow occurs here
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0502`.
------------------------------------------
------------------------------------------


---- [ui] checkout/tests/ui/borrowck/borrowck-loan-of-static-data-issue-27616.rs stdout ----
diff of stderr:

7    |                type annotation requires that `*s` is borrowed for `'static`
9 LL |     *s = String::new();
9 LL |     *s = String::new();
-    |     ^^ assignment to borrowed `*s` occurs here
+    |     ^^^^^^^^^^^^^^^^^^ assignment to borrowed `*s` occurs here
12 error: aborting due to previous error
13 



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-loan-of-static-data-issue-27616/borrowck-loan-of-static-data-issue-27616.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args borrowck/borrowck-loan-of-static-data-issue-27616.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/borrowck-loan-of-static-data-issue-27616.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-loan-of-static-data-issue-27616" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-loan-of-static-data-issue-27616/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0506]: cannot assign to `*s` because it is borrowed
   |
LL |     let alias: &'static mut String = s;
LL |     let alias: &'static mut String = s;
   |                -------------------   - borrow of `*s` occurs here
   |                |
   |                type annotation requires that `*s` is borrowed for `'static`
...
LL |     *s = String::new(); //~ ERROR cannot assign
   |     ^^^^^^^^^^^^^^^^^^ assignment to borrowed `*s` occurs here
error: aborting due to previous error

For more information about this error, try `rustc --explain E0506`.
------------------------------------------
------------------------------------------


---- [ui] checkout/tests/ui/borrowck/borrowck-no-cycle-in-exchange-heap.rs stdout ----
diff of stderr:

4 LL |       Cycle::Node(ref mut y) => {
5    |                   --------- borrow of `x.0` occurs here
6 LL |         y.a = x;
-    |         ---   ^ move out of `x` occurs here
+    |         ------^
+    |         |     |
+    |         |     |
+    |         |     move out of `x` occurs here
10 
11 error: aborting due to previous error



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-no-cycle-in-exchange-heap/borrowck-no-cycle-in-exchange-heap.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args borrowck/borrowck-no-cycle-in-exchange-heap.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/borrowck-no-cycle-in-exchange-heap.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-no-cycle-in-exchange-heap" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-no-cycle-in-exchange-heap/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0505]: cannot move out of `x` because it is borrowed
   |
   |
LL |       Cycle::Node(ref mut y) => {
   |                   --------- borrow of `x.0` occurs here
LL |         y.a = x; //~ ERROR cannot move out of
   |         |     |
   |         |     |
   |         |     move out of `x` occurs here

error: aborting due to previous error

For more information about this error, try `rustc --explain E0505`.
---
diff of stderr:

7 LL |     drop(t);
8    |          - value moved here
9 LL |     t.b = Some(u);
+    |     ^^^^^^^^^^^^^ value assigned here after move
11 
12 error[E0382]: assign of moved value: `t`
13   --> $DIR/borrowck-partial-reinit-1.rs:33:5
13   --> $DIR/borrowck-partial-reinit-1.rs:33:5

18 LL |     drop(t);
19    |          - value moved here
20 LL |     t.0 = Some(u);
+    |     ^^^^^^^^^^^^^ value assigned here after move
22 
23 error: aborting due to 2 previous errors
24 
24 


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-partial-reinit-1/borrowck-partial-reinit-1.stderr
To only update this specific test, also pass `--test-args borrowck/borrowck-partial-reinit-1.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/borrowck-partial-reinit-1.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-partial-reinit-1" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-partial-reinit-1/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0382]: assign of moved value: `t`
   |
   |
LL |     let mut t = Test2 { b: None };
   |         ----- move occurs because `t` has type `Test2`, which does not implement the `Copy` trait
LL |     let u = Test;
LL |     drop(t);
   |          - value moved here
LL |     t.b = Some(u);

error[E0382]: assign of moved value: `t`
  --> /checkout/tests/ui/borrowck/borrowck-partial-reinit-1.rs:33:5
   |
   |
LL |     let mut t = Test3(None);
   |         ----- move occurs because `t` has type `Test3`, which does not implement the `Copy` trait
LL |     let u = Test;
LL |     drop(t);
   |          - value moved here
LL |     t.0 = Some(u);

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0382`.
For more information about this error, try `rustc --explain E0382`.
------------------------------------------


---- [ui] checkout/tests/ui/borrowck/borrowck-partial-reinit-4.rs stdout ----
diff of stderr:

4 LL |     let mut x : (Test2, Test2);
5    |         ----- binding declared here but left uninitialized
6 LL |     (x.0).0 = Some(Test);
-    |     ^^^^^^^ `x.0` assigned here but it isn't fully initialized
+    |     ^^^^^^^^^^^^^^^^^^^^ `x.0` assigned here but it isn't fully initialized
8    |
9    = help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`


The actual stderr differed from the expected stderr.
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-partial-reinit-4/borrowck-partial-reinit-4.stderr
To only update this specific test, also pass `--test-args borrowck/borrowck-partial-reinit-4.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/borrowck-partial-reinit-4.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-partial-reinit-4" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-partial-reinit-4/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0381]: assigned binding `x.0` isn't fully initialized
   |
   |
LL |     let mut x : (Test2, Test2);
   |         ----- binding declared here but left uninitialized
LL |     (x.0).0 = Some(Test); //~ ERROR E0381
   |     ^^^^^^^^^^^^^^^^^^^^ `x.0` assigned here but it isn't fully initialized
   |
   = help: partial initialization isn't supported, fully initialize the binding with a default value and mutate it, or use `std::mem::MaybeUninit`
error: aborting due to previous error

For more information about this error, try `rustc --explain E0381`.
------------------------------------------
------------------------------------------


---- [ui] checkout/tests/ui/borrowck/borrowck-partial-reinit-2.rs stdout ----
diff of stderr:

6 LL |     let mut u = Test { a: 2, b: Some(Box::new(t))};
7    |                                               - value moved here
8 LL |     t.b = Some(Box::new(u));
+    |     ^^^^^^^^^^^^^^^^^^^^^^^ value assigned here after move
10 
11 error: aborting due to previous error
12 
12 


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-partial-reinit-2/borrowck-partial-reinit-2.stderr
To only update this specific test, also pass `--test-args borrowck/borrowck-partial-reinit-2.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/borrowck-partial-reinit-2.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-partial-reinit-2" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-partial-reinit-2/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0382]: assign of moved value: `t`
   |
   |
LL |     let mut t = Test { a: 1, b: None};
   |         ----- move occurs because `t` has type `Test`, which does not implement the `Copy` trait
LL |     let mut u = Test { a: 2, b: Some(Box::new(t))};
   |                                               - value moved here
LL |     t.b = Some(Box::new(u));

error: aborting due to previous error

For more information about this error, try `rustc --explain E0382`.
For more information about this error, try `rustc --explain E0382`.
------------------------------------------


---- [ui] checkout/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs stdout ----
diff of stderr:

5    |              ------ borrow of `vec[_]` occurs here
6 LL |
7 LL |             vec[0] = Box::new(4);
-    |             ^^^^^^ assignment to borrowed `vec[_]` occurs here
+    |             ^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `vec[_]` occurs here
9 LL |
10 LL |             _a.use_ref();


17    |               ------ borrow of `vec[_]` occurs here
18 LL |
19 LL |             vec[0] = Box::new(4);
-    |             ^^^^^^ assignment to borrowed `vec[_]` occurs here
+    |             ^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `vec[_]` occurs here
21 LL |
22 LL |             _b.use_ref();


The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-vec-pattern-nesting/borrowck-vec-pattern-nesting.stderr
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-vec-pattern-nesting/borrowck-vec-pattern-nesting.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args borrowck/borrowck-vec-pattern-nesting.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/borrowck-vec-pattern-nesting.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-vec-pattern-nesting" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/borrowck-vec-pattern-nesting/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0506]: cannot assign to `vec[_]` because it is borrowed
   |
   |
LL |         [box ref _a, _, _] => {
   |              ------ borrow of `vec[_]` occurs here
LL |         //~^ NOTE borrow of `vec[_]` occurs here
LL |             vec[0] = Box::new(4); //~ ERROR cannot assign
   |             ^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `vec[_]` occurs here
LL |             //~^ NOTE assignment to borrowed `vec[_]` occurs here
LL |             _a.use_ref();


error[E0506]: cannot assign to `vec[_]` because it is borrowed
   |
   |
LL |         &mut [ref _b @ ..] => {
   |               ------ borrow of `vec[_]` occurs here
LL |         //~^ borrow of `vec[_]` occurs here
LL |             vec[0] = Box::new(4); //~ ERROR cannot assign
   |             ^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `vec[_]` occurs here
LL |             //~^ NOTE assignment to borrowed `vec[_]` occurs here
LL |             _b.use_ref();


error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
   |
LL |     match vec {
   |           ^^^ cannot move out of here
...
...
LL |         &mut [_a,
   |               --
   |               |
   |               data moved here
   |               move occurs because `_a` has type `Box<isize>`, which does not implement the `Copy` trait
help: consider removing the mutable borrow
   |
LL -         &mut [_a,
LL +         [_a,
LL +         [_a,
   |

error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
   |
   |
LL |     let a = vec[0]; //~ ERROR cannot move out
   |             |
   |             cannot move out of here
   |             cannot move out of here
   |             move occurs because `vec[_]` has type `Box<isize>`, which does not implement the `Copy` trait
help: consider borrowing here
   |
   |
LL |     let a = &vec[0]; //~ ERROR cannot move out


error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
   |
LL |     match vec {
   |           ^^^ cannot move out of here
...
...
LL |          _b] => {}
   |          |
   |          data moved here
   |          data moved here
   |          move occurs because `_b` has type `Box<isize>`, which does not implement the `Copy` trait
help: consider removing the mutable borrow
   |
LL -         &mut [
LL +         [
LL +         [
   |

error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
   |
   |
LL |     let a = vec[0]; //~ ERROR cannot move out
   |             |
   |             cannot move out of here
   |             cannot move out of here
   |             move occurs because `vec[_]` has type `Box<isize>`, which does not implement the `Copy` trait
help: consider borrowing here
   |
   |
LL |     let a = &vec[0]; //~ ERROR cannot move out


error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
   |
LL |     match vec {
   |           ^^^ cannot move out of here
...
...
LL |         &mut [_a, _b, _c] => {}
   |               --  --  -- ...and here
   |               |   |
   |               |   ...and here
   |               data moved here
   = note: move occurs because these variables have types that don't implement the `Copy` trait
help: consider removing the mutable borrow
   |
   |
LL -         &mut [_a, _b, _c] => {}
LL +         [_a, _b, _c] => {}


error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
   |
   |
LL |     let a = vec[0]; //~ ERROR cannot move out
   |             |
   |             cannot move out of here
   |             cannot move out of here
   |             move occurs because `vec[_]` has type `Box<isize>`, which does not implement the `Copy` trait
help: consider borrowing here
   |
   |
LL |     let a = &vec[0]; //~ ERROR cannot move out

error: aborting due to 8 previous errors

Some errors have detailed explanations: E0506, E0508.
---
diff of stderr:

14   --> $DIR/index-mut-help.rs:11:5
15    |
16 LL |     map["peter"] = "0".to_string();
+    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot assign
18    |
18    |
19    = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<&str, String>`
20 help: to modify a `HashMap<&str, String>`, use `.get_mut()`, `.insert()` or the entry API

The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/index-mut-help/index-mut-help.stderr
To update references, rerun the tests and pass the `--bless` flag
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args borrowck/index-mut-help.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/index-mut-help.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/index-mut-help" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/index-mut-help/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0596]: cannot borrow data in an index of `HashMap<&str, String>` as mutable
   |
   |
LL |     map["peter"].clear();           //~ ERROR
   |     ^^^^^^^^^^^^^^^^^^^^ cannot borrow as mutable
   |
   = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<&str, String>`
help: to modify a `HashMap<&str, String>` use `.get_mut()`
   |
LL |     map.get_mut("peter").map(|val| val.clear());           //~ ERROR


error[E0594]: cannot assign to data in an index of `HashMap<&str, String>`
   |
   |
LL |     map["peter"] = "0".to_string(); //~ ERROR
   |
   |
   = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<&str, String>`
help: to modify a `HashMap<&str, String>`, use `.get_mut()`, `.insert()` or the entry API
   |
LL |     map.insert("peter", "0".to_string()); //~ ERROR
   |        ~~~~~~~~       ~                +
LL |     map.get_mut("peter").map(|val| { *val = "0".to_string(); }); //~ ERROR
   |        ~~~~~~~~~       ~~~~~~~~~~~~~~~~~~                  ++++
LL |     let val = map.entry("peter").or_insert("0".to_string()); //~ ERROR


error[E0596]: cannot borrow data in an index of `HashMap<&str, String>` as mutable
   |
   |
LL |     let _ = &mut map["peter"];      //~ ERROR
   |             ^^^^^^^^^^^^^^^^^ cannot borrow as mutable
   |
   = help: trait `IndexMut` is required to modify indexed content, but it is not implemented for `HashMap<&str, String>`
   = help: to modify a `HashMap<&str, String>`, use `.get_mut()`, `.insert()` or the entry API
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0594, E0596.
For more information about an error, try `rustc --explain E0594`.
---
diff of stderr:

5    |         - help: consider making this binding mutable: `mut b`
6 ...
7 LL |     b = Box::new(1);
-    |     - first assignment to `b`
+    |     --------------- first assignment to `b`
9 LL |     b = Box::new(2);
-    |     ^ cannot assign twice to immutable variable
+    |     ^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
12 error[E0384]: cannot assign twice to immutable variable `b`
13   --> $DIR/issue-45199.rs:14:5

19    |         help: consider making this binding mutable: `mut b`
19    |         help: consider making this binding mutable: `mut b`
20 ...
21 LL |     b = Box::new(2);
-    |     ^ cannot assign twice to immutable variable
+    |     ^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
24 error[E0384]: cannot assign to immutable argument `b`
25   --> $DIR/issue-45199.rs:20:5

28    |              - help: consider making this binding mutable: `mut b`
28    |              - help: consider making this binding mutable: `mut b`
29 LL |
30 LL |     b = Box::new(2);
-    |     ^ cannot assign to immutable argument
+    |     ^^^^^^^^^^^^^^^ cannot assign to immutable argument
33 error: aborting due to 3 previous errors
34 



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/issue-45199/issue-45199.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args borrowck/issue-45199.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/issue-45199.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/issue-45199" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/issue-45199/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0384]: cannot assign twice to immutable variable `b`
   |
   |
LL |     let b: Box<isize>;
   |         - help: consider making this binding mutable: `mut b`
...
LL |     b = Box::new(1);    //~ NOTE first assignment
   |     --------------- first assignment to `b`
LL |     b = Box::new(2);    //~ ERROR cannot assign twice to immutable variable `b`
   |     ^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
error[E0384]: cannot assign twice to immutable variable `b`
  --> /checkout/tests/ui/borrowck/issue-45199.rs:14:5
   |
   |
LL |     let b = Box::new(1);    //~ NOTE first assignment
   |         |
   |         first assignment to `b`
   |         help: consider making this binding mutable: `mut b`
...
...
LL |     b = Box::new(2);        //~ ERROR cannot assign twice to immutable variable `b`
   |     ^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
error[E0384]: cannot assign to immutable argument `b`
  --> /checkout/tests/ui/borrowck/issue-45199.rs:20:5
   |
   |
LL | fn test_args(b: Box<i32>) {  //~ HELP consider making this binding mutable
   |              - help: consider making this binding mutable: `mut b`
LL |                                 //~| SUGGESTION mut b
LL |     b = Box::new(2);            //~ ERROR cannot assign to immutable argument `b`
   |     ^^^^^^^^^^^^^^^ cannot assign to immutable argument
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0384`.
------------------------------------------
------------------------------------------


---- [ui] checkout/tests/ui/borrowck/issue-58776-borrowck-scans-children.rs stdout ----
diff of stderr:

7    |                borrow of `greeting` occurs here
8 LL |
9 LL |     greeting = "DEALLOCATED".to_string();
-    |     ^^^^^^^^ assignment to borrowed `greeting` occurs here
+    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `greeting` occurs here
11 ...
12 LL |     println!("thread result: {:?}", res);

14 
14 
- error[E0505]: cannot move out of `greeting` because it is borrowed
-   --> $DIR/issue-58776-borrowck-scans-children.rs:7:10
-    |
- LL |     let res = (|| (|| &greeting)())();
-    |                --      -------- borrow occurs due to use in closure
-    |                |
-    |                borrow of `greeting` occurs here
- ...
- LL |     drop(greeting);
-    |          ^^^^^^^^ move out of `greeting` occurs here
- ...
- LL |     println!("thread result: {:?}", res);
+ error: aborting due to previous error
28 
- error: aborting due to 2 previous errors
- 
---
To only update this specific test, also pass `--test-args borrowck/issue-58776-borrowck-scans-children.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/borrowck/issue-58776-borrowck-scans-children.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/issue-58776-borrowck-scans-children" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/borrowck/issue-58776-borrowck-scans-children/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0506]: cannot assign to `greeting` because it is borrowed
   |
   |
LL |     let res = (|| (|| &greeting)())();
   |                --      -------- borrow occurs due to use in closure
   |                |
   |                borrow of `greeting` occurs here
LL |
LL |     greeting = "DEALLOCATED".to_string();
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `greeting` occurs here
...
LL |     println!("thread result: {:?}", res);

error: aborting due to previous error

For more information about this error, try `rustc --explain E0506`.
For more information about this error, try `rustc --explain E0506`.
------------------------------------------


---- [ui] checkout/tests/ui/c-variadic/variadic-ffi-4.rs stdout ----
diff of stderr:

55    |                                               |
56    |                                               has type `&mut VaListImpl<'1>`
57 LL |     *ap0 = ap1;
-    |     ^^^^ assignment requires that `'1` must outlive `'2`
+    |     ^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
59    |
60    = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
61    = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
69    |                                               |
70    |                                               has type `&mut VaListImpl<'1>`
71 LL |     *ap0 = ap1;
71 LL |     *ap0 = ap1;
-    |     ^^^^ assignment requires that `'2` must outlive `'1`
+    |     ^^^^^^^^^^ assignment requires that `'2` must outlive `'1`
73    |
74    = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
75    = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`

The actual stderr differed from the expected stderr.
The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/c-variadic/variadic-ffi-4/variadic-ffi-4.stderr
To only update this specific test, also pass `--test-args c-variadic/variadic-ffi-4.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/c-variadic/variadic-ffi-4.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/c-variadic/variadic-ffi-4" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/c-variadic/variadic-ffi-4/auxiliary"
stdout: none
--- stderr -------------------------------
error: lifetime may not live long enough
   |
   |
LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> {
   |                                     --            -- has type `VaListImpl<'1>`
   |                                     |
   |                                     lifetime `'f` defined here
LL |     ap
   |     ^^ function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'f`
   |
   = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
   = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
   = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
  --> /checkout/tests/ui/c-variadic/variadic-ffi-4.rs:8:5
   |
   |
LL | pub unsafe extern "C" fn no_escape0<'f>(_: usize, ap: ...) -> VaListImpl<'f> {
   |                                     --            -- has type `VaListImpl<'1>`
   |                                     |
   |                                     lifetime `'f` defined here
LL |     ap
   |     ^^ function was supposed to return data with lifetime `'f` but it is returning data with lifetime `'1`
   |
   = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
   = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
   = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
  --> /checkout/tests/ui/c-variadic/variadic-ffi-4.rs:14:5
   |
   |
LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaListImpl<'static> {
   |                                               -- has type `VaListImpl<'1>`
LL |     ap //~ ERROR: lifetime may not live long enough
   |     ^^ returning this value requires that `'1` must outlive `'static`
   |
   = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
   = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
   = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
  --> /checkout/tests/ui/c-variadic/variadic-ffi-4.rs:18:31
   |
   |
LL |     let _ = ap.with_copy(|ap| ap); //~ ERROR: lifetime may not live long enough
   |                           --- ^^ returning this value requires that `'1` must outlive `'2`
   |                           | |
   |                           | return type of closure is VaList<'2, '_>
   |                           has type `VaList<'1, '_>`
error: lifetime may not live long enough
  --> /checkout/tests/ui/c-variadic/variadic-ffi-4.rs:22:5
   |
   |
LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
   |                                               -------                   ------- has type `VaListImpl<'2>`
   |                                               has type `&mut VaListImpl<'1>`
LL |     *ap0 = ap1;
LL |     *ap0 = ap1;
   |     ^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
   |
   = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
   = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
   = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
  --> /checkout/tests/ui/c-variadic/variadic-ffi-4.rs:22:5
   |
   |
LL | pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
   |                                               -------                   ------- has type `VaListImpl<'2>`
   |                                               has type `&mut VaListImpl<'1>`
LL |     *ap0 = ap1;
LL |     *ap0 = ap1;
   |     ^^^^^^^^^^ assignment requires that `'2` must outlive `'1`
   |
   = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
   = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
   = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
  --> /checkout/tests/ui/c-variadic/variadic-ffi-4.rs:28:5
   |
   |
LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
   |                                               -------                   ------- has type `VaListImpl<'2>`
   |                                               has type `&mut VaListImpl<'1>`
   |                                               has type `&mut VaListImpl<'1>`
LL |     ap0 = &mut ap1;
   |     ^^^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2`
   |
   = note: requirement occurs because of a mutable reference to `VaListImpl<'_>`
   = note: mutable references are invariant over their type parameter
   = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
  --> /checkout/tests/ui/c-variadic/variadic-ffi-4.rs:28:5
   |
   |
LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
   |                                               -------                   ------- has type `VaListImpl<'2>`
   |                                               has type `&mut VaListImpl<'1>`
   |                                               has type `&mut VaListImpl<'1>`
LL |     ap0 = &mut ap1;
   |     ^^^^^^^^^^^^^^ assignment requires that `'2` must outlive `'1`
   |
   = note: requirement occurs because of a mutable reference to `VaListImpl<'_>`
   = note: mutable references are invariant over their type parameter
   = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance

error[E0597]: `ap1` does not live long enough
   |
   |
LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
   |                                                        - let's call the lifetime of this reference `'3`
LL |     ap0 = &mut ap1;
   |     |     |
   |     |     borrowed value does not live long enough
   |     |     borrowed value does not live long enough
   |     assignment requires that `ap1` is borrowed for `'3`
LL | }
LL | }
   | - `ap1` dropped here while still borrowed
error: lifetime may not live long enough
  --> /checkout/tests/ui/c-variadic/variadic-ffi-4.rs:35:12
   |
   |
LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
   |                                               -------                   ------- has type `VaListImpl<'2>`
   |                                               has type `&mut VaListImpl<'1>`
   |                                               has type `&mut VaListImpl<'1>`
LL |     *ap0 = ap1.clone();
   |            ^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
   |
   = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
   = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
   = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
  --> /checkout/tests/ui/c-variadic/variadic-ffi-4.rs:35:12
   |
   |
LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
   |                                               -------                   ------- has type `VaListImpl<'2>`
   |                                               has type `&mut VaListImpl<'1>`
   |                                               has type `&mut VaListImpl<'1>`
LL |     *ap0 = ap1.clone();
   |            ^^^^^^^^^^^ argument requires that `'2` must outlive `'1`
   |
   = note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
   = note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
   = help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 11 previous errors

For more information about this error, try `rustc --explain E0597`.
------------------------------------------
------------------------------------------


---- [ui] checkout/tests/ui/closures/2229_closure_analysis/diagnostics/box.rs stdout ----
diff of stderr:

7    |         --------- borrow occurs due to use in closure
8 ...
9 LL |     e.0.0.m.x = format!("not-x");
-    |     ^^^^^^^^^ assignment to borrowed `e.0.0.m.x` occurs here
+    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `e.0.0.m.x` occurs here
12 LL |     c();
13    |     - borrow later used here

37    |                        --------- borrow occurs due to use in closure
37    |                        --------- borrow occurs due to use in closure
38 ...
39 LL |     e.0.0.m.x = format!("not-x");
-    |     ^^^^^^^^^ assignment to borrowed `e.0.0.m.x` occurs here
+    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `e.0.0.m.x` occurs here
42 LL |     c();
43    |     - borrow later used here



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/closures/2229_closure_analysis/diagnostics/box/box.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args closures/2229_closure_analysis/diagnostics/box.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/closures/2229_closure_analysis/diagnostics/box.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/closures/2229_closure_analysis/diagnostics/box" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/closures/2229_closure_analysis/diagnostics/box/auxiliary" "--edition=2021"
stdout: none
--- stderr -------------------------------
error[E0506]: cannot assign to `e.0.0.m.x` because it is borrowed
   |
LL |     let mut c = || {
LL |     let mut c = || {
   |                 -- borrow of `e.0.0.m.x` occurs here
LL |         e.0.0.m.x = format!("not-x");
   |         --------- borrow occurs due to use in closure
...
LL |     e.0.0.m.x = format!("not-x");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `e.0.0.m.x` occurs here
LL |     //~^ ERROR: cannot assign to `e.0.0.m.x` because it is borrowed
LL |     c();


error[E0502]: cannot borrow `e.0.0.m.x` as immutable because it is also borrowed as mutable
   |
LL |     let mut c = || {
LL |     let mut c = || {
   |                 -- mutable borrow occurs here
LL |         e.0.0.m.x = format!("not-x");
   |         --------- first borrow occurs due to use of `e.0.0.m.x` in closure
...
LL |     println!("{}", e.0.0.m.x);
   |                    ^^^^^^^^^ immutable borrow occurs here
LL |     //~^ ERROR: cannot borrow `e.0.0.m.x` as immutable because it is also borrowed as mutable
LL |     c();
   |
   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)


error[E0506]: cannot assign to `e.0.0.m.x` because it is borrowed
   |
LL |     let c = || {
LL |     let c = || {
   |             -- borrow of `e.0.0.m.x` occurs here
LL |         println!("{}", e.0.0.m.x);
   |                        --------- borrow occurs due to use in closure
...
LL |     e.0.0.m.x = format!("not-x");
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `e.0.0.m.x` occurs here
LL |     //~^ ERROR: cannot assign to `e.0.0.m.x` because it is borrowed
LL |     c();

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0502, E0506.
---
diff of stderr:

2   --> $DIR/const_let.rs:16:32
3    |
4 LL | const Y: FakeNeedsDrop = { let mut x = FakeNeedsDrop; x = FakeNeedsDrop; x };
-    |                                ^^^^^                  - value is dropped here
+    |                                ^^^^^                  ----------------- value is dropped here
7    |                                the destructor for this type cannot be evaluated in constants
8 

10   --> $DIR/const_let.rs:20:33
10   --> $DIR/const_let.rs:20:33
11    |
12 LL | const Y2: FakeNeedsDrop = { let mut x; x = FakeNeedsDrop; x = FakeNeedsDrop; x };
-    |                                 ^^^^^                     - value is dropped here
+    |                                 ^^^^^                     ----------------- value is dropped here
15    |                                 the destructor for this type cannot be evaluated in constants
16 



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/const_let/const_let.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args consts/const-eval/const_let.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/consts/const-eval/const_let.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/const_let" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/const_let/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0493]: destructor of `FakeNeedsDrop` cannot be evaluated at compile-time
   |
   |
LL | const Y: FakeNeedsDrop = { let mut x = FakeNeedsDrop; x = FakeNeedsDrop; x };
   |                                ^^^^^                  ----------------- value is dropped here
   |                                the destructor for this type cannot be evaluated in constants


error[E0493]: destructor of `FakeNeedsDrop` cannot be evaluated at compile-time
   |
   |
LL | const Y2: FakeNeedsDrop = { let mut x; x = FakeNeedsDrop; x = FakeNeedsDrop; x };
   |                                 ^^^^^                     ----------------- value is dropped here
   |                                 the destructor for this type cannot be evaluated in constants


error[E0493]: destructor of `Option<FakeNeedsDrop>` cannot be evaluated at compile-time
   |
   |
LL | const Z: () = { let mut x = None; x = Some(FakeNeedsDrop); };
   |                     ^^^^^                                  - value is dropped here
   |                     the destructor for this type cannot be evaluated in constants


error[E0493]: destructor of `Option<FakeNeedsDrop>` cannot be evaluated at compile-time
   |
   |
LL | const Z2: () = { let mut x; x = None; x = Some(FakeNeedsDrop); };
   |                      ^^^^^                                     - value is dropped here
   |                      the destructor for this type cannot be evaluated in constants

error: aborting due to 4 previous errors

---
diff of stderr:

5    |         ^^^^^^^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants
6 ...
7 LL |         always_returned = never_returned;
-    |         --------------- value is dropped here
+    |         -------------------------------- value is dropped here
10 error: aborting due to previous error
11 



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/livedrop/livedrop.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args consts/const-eval/livedrop.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/consts/const-eval/livedrop.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/livedrop" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/consts/const-eval/livedrop/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0493]: destructor of `Option<Vec<i32>>` cannot be evaluated at compile-time
   |
   |
LL |     let mut always_returned = None; //~ ERROR destructor of
   |         ^^^^^^^^^^^^^^^^^^^ the destructor for this type cannot be evaluated in constants
LL |         always_returned = never_returned;
LL |         always_returned = never_returned;
   |         -------------------------------- value is dropped here
error: aborting due to previous error

For more information about this error, try `rustc --explain E0493`.
------------------------------------------
------------------------------------------


---- [ui] checkout/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs stdout ----
diff of stderr:

8    |         help: consider making this binding mutable: `mut b`
9 ...
10 LL |     b = Box::new(2);
-    |     ^ cannot assign twice to immutable variable
+    |     ^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
13 error: aborting due to previous error
14 



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop/liveness-assign-imm-local-with-drop.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/liveness/liveness-assign/liveness-assign-imm-local-with-drop/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0384]: cannot assign twice to immutable variable `b`
   |
   |
LL |     let b = Box::new(1); //~ NOTE first assignment
   |         |
   |         first assignment to `b`
   |         help: consider making this binding mutable: `mut b`
...
...
LL |     b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
   |     ^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
error: aborting due to previous error

For more information about this error, try `rustc --explain E0384`.
------------------------------------------
------------------------------------------


---- [ui] checkout/tests/ui/mir/drop-elaboration-after-borrowck-error.rs stdout ----
diff of stderr:

2   --> $DIR/drop-elaboration-after-borrowck-error.rs:7:5
3    |
4 LL |     a[0] = String::new();
+    |     ^^^^^^^^^^^^^^^^^^^^
6    |     |
7    |     the destructor for this type cannot be evaluated in statics
8    |     value is dropped here
8    |     value is dropped here

34   --> $DIR/drop-elaboration-after-borrowck-error.rs:18:9
35    |
36 LL |         self.0[0] = other;
+    |         ^^^^^^^^^^^^^^^^^
38    |         |
39    |         the destructor for this type cannot be evaluated in constant functions
40    |         value is dropped here
---
To only update this specific test, also pass `--test-args mir/drop-elaboration-after-borrowck-error.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/mir/drop-elaboration-after-borrowck-error.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/mir/drop-elaboration-after-borrowck-error" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/mir/drop-elaboration-after-borrowck-error/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0493]: destructor of `String` cannot be evaluated at compile-time
   |
   |
LL |     a[0] = String::new();
   |     |
   |     the destructor for this type cannot be evaluated in statics
   |     value is dropped here


error[E0493]: destructor of `[String; 1]` cannot be evaluated at compile-time
   |
   |
LL |     let a: [String; 1];
   |         ^ the destructor for this type cannot be evaluated in statics
LL | };
LL | };
   | - value is dropped here
error[E0381]: used binding `a` isn't initialized
  --> /checkout/tests/ui/mir/drop-elaboration-after-borrowck-error.rs:7:5
   |
   |
LL |     let a: [String; 1];
   |         - binding declared here but left uninitialized
LL |     //~^ ERROR destructor of
LL |     a[0] = String::new();
   |     ^^^^ `a` used here but it isn't initialized
help: consider assigning a value
   |
   |
LL |     let a: [String; 1] = todo!();


error[E0493]: destructor of `T` cannot be evaluated at compile-time
   |
   |
LL |         self.0[0] = other;
   |         |
   |         the destructor for this type cannot be evaluated in constant functions
   |         value is dropped here


error[E0493]: destructor of `B<T>` cannot be evaluated at compile-time
   |
LL |         let _this = self;
   |             ^^^^^ the destructor for this type cannot be evaluated in constant functions
...
...
LL |     }
   |     - value is dropped here

error[E0382]: use of moved value: `self.0`
  --> /checkout/tests/ui/mir/drop-elaboration-after-borrowck-error.rs:18:9
   |
LL |     pub const fn f(mut self, other: T) -> Self {
   |                    -------- move occurs because `self` has type `B<T>`, which does not implement the `Copy` trait
LL |         let _this = self;
   |                     ---- value moved here
LL |         //~^ ERROR destructor of
LL |         self.0[0] = other;
   |         ^^^^^^^^^ value used here after move
error: aborting due to 6 previous errors

Some errors have detailed explanations: E0381, E0382, E0493.
For more information about an error, try `rustc --explain E0381`.
For more information about an error, try `rustc --explain E0381`.
------------------------------------------


---- [ui] checkout/tests/ui/nll/issue-27868.rs stdout ----
diff of stderr:

7    |  _____borrow of `vecvec` occurs here
8    | |
9 LL | |         vecvec = vec![];
-    | |         ^^^^^^ assignment to borrowed `vecvec` occurs here
+    | |         ^^^^^^^^^^^^^^^ assignment to borrowed `vecvec` occurs here
11 LL | |
12 LL | |         0
13 LL | |     };

The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/nll/issue-27868/issue-27868.stderr
To update references, rerun the tests and pass the `--bless` flag
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args nll/issue-27868.rs`
error: 1 errors occurred comparing output.
status: exit status: 1
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/nll/issue-27868.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/nll/issue-27868" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/nll/issue-27868/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0506]: cannot assign to `vecvec` because it is borrowed
   |
   |
LL |       vecvec[0] += {
   |       |
   |       |
   |  _____borrow of `vecvec` occurs here
   | |
LL | |         vecvec = vec![];
   | |         ^^^^^^^^^^^^^^^ assignment to borrowed `vecvec` occurs here
LL | |         //~^ ERROR cannot assign to `vecvec` because it is borrowed [E0506]
LL | |         0
LL | |     };
   | |_____- borrow later used here
error: aborting due to previous error

For more information about this error, try `rustc --explain E0506`.
------------------------------------------
------------------------------------------


---- [ui] checkout/tests/ui/object-lifetime/object-lifetime-default-from-box-error.rs stdout ----
diff of stderr:

25    |                   --------------- help: add explicit lifetime `'b` to the type of `ss`: `&mut SomeStruct<'b>`
26 ...
27 LL |     ss.r = b;
-    |     ^^^^ lifetime `'b` required
+    |     ^^^^^^^^ lifetime `'b` required
30 error: aborting due to 3 previous errors
31 



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/object-lifetime/object-lifetime-default-from-box-error/object-lifetime-default-from-box-error.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args object-lifetime/object-lifetime-default-from-box-error.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/object-lifetime/object-lifetime-default-from-box-error.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/object-lifetime/object-lifetime-default-from-box-error" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/object-lifetime/object-lifetime-default-from-box-error/auxiliary"
stdout: none
--- stderr -------------------------------
error: lifetime may not live long enough
   |
   |
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait> {
   |         -- has type `&mut SomeStruct<'1>`
LL |     ss.r
LL |     ss.r
   |     ^^^^ returning this value requires that `'1` must outlive `'static`
   |
help: to declare that the trait object captures data from argument `ss`, you can add an explicit `'_` lifetime bound
   |
LL | fn load(ss: &mut SomeStruct) -> Box<dyn SomeTrait + '_> {


error[E0507]: cannot move out of `ss.r` which is behind a mutable reference
   |
LL |     ss.r
LL |     ss.r
   |     ^^^^ move occurs because `ss.r` has type `Box<dyn SomeTrait>`, which does not implement the `Copy` trait

error[E0621]: explicit lifetime required in the type of `ss`
   |
   |
LL | fn store1<'b>(ss: &mut SomeStruct, b: Box<dyn SomeTrait+'b>) {
   |                   --------------- help: add explicit lifetime `'b` to the type of `ss`: `&mut SomeStruct<'b>`
...
LL |     ss.r = b; //~ ERROR explicit lifetime required in the type of `ss` [E0621]
   |     ^^^^^^^^ lifetime `'b` required
error: aborting due to 3 previous errors

Some errors have detailed explanations: E0507, E0621.
For more information about an error, try `rustc --explain E0507`.
For more information about an error, try `rustc --explain E0507`.
------------------------------------------


---- [ui] checkout/tests/ui/regions/regions-infer-paramd-indirect.rs stdout ----
diff of stderr:

7 LL |     fn set_f_bad(&mut self, b: Box<B>) {
8    |                             - has type `Box<Box<&'1 isize>>`
9 LL |         self.f = b;
-    |         ^^^^^^ assignment requires that `'1` must outlive `'a`
+    |         ^^^^^^^^^^ assignment requires that `'1` must outlive `'a`
12 error: aborting due to previous error
13 



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/regions/regions-infer-paramd-indirect/regions-infer-paramd-indirect.stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args regions/regions-infer-paramd-indirect.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/regions/regions-infer-paramd-indirect.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/regions/regions-infer-paramd-indirect" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/regions/regions-infer-paramd-indirect/auxiliary"
stdout: none
--- stderr -------------------------------
error: lifetime may not live long enough
   |
   |
LL | impl<'a> SetF<'a> for C<'a> {
   |      -- lifetime `'a` defined here
...
LL |     fn set_f_bad(&mut self, b: Box<B>) {
   |                             - has type `Box<Box<&'1 isize>>`
LL |         self.f = b;
   |         ^^^^^^^^^^ assignment requires that `'1` must outlive `'a`
error: aborting due to previous error
------------------------------------------


---
23 LL |     factorial = Some(Box::new(f));
-    |     ^^^^^^^^^
+    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
25    |     |
26    |     assignment to borrowed `factorial` occurs here

52    |                 --------- borrow occurs due to use in closure
53 ...
54 LL |     factorial = Some(Box::new(f));
54 LL |     factorial = Some(Box::new(f));
-    |     ^^^^^^^^^ assignment to borrowed `factorial` occurs here
+    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `factorial` occurs here
57 error: aborting due to 4 previous errors
58 



The actual stderr differed from the expected stderr.
Actual stderr saved to /checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-1/unboxed-closures-failed-recursive-fn-1.stderr
To only update this specific test, also pass `--test-args unboxed-closures/unboxed-closures-failed-recursive-fn-1.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
status: exit status: 1
command: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-1.rs" "-Zthreads=1" "--target=x86_64-unknown-linux-gnu" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Zdeduplicate-diagnostics=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-1" "-A" "unused" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "-L" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-1/auxiliary"
stdout: none
--- stderr -------------------------------
error[E0597]: `factorial` does not live long enough
   |
   |
LL |     let f = |x: u32| -> u32 {
   |             --------------- value captured here
LL |         let g = factorial.as_ref().unwrap();
   |                 ^^^^^^^^^ borrowed value does not live long enough
LL | }
   | -
   | |
   | |
   | `factorial` dropped here while still borrowed
   | borrow might be used here, when `factorial` is dropped and runs the destructor for type `Option<Box<dyn Fn(u32) -> u32>>`

error[E0506]: cannot assign to `factorial` because it is borrowed
   |
   |
LL |     let f = |x: u32| -> u32 {
   |             --------------- borrow of `factorial` occurs here
LL |         let g = factorial.as_ref().unwrap();
   |                 --------- borrow occurs due to use in closure
LL |     factorial = Some(Box::new(f));
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |     |
   |     |
   |     assignment to borrowed `factorial` occurs here


error[E0597]: `factorial` does not live long enough
   |
   |
LL |     let mut factorial: Option<Box<dyn Fn(u32) -> u32 + 'static>> = None;
   |                        ----------------------------------------- type annotation requires that `factorial` is borrowed for `'static`
LL |
LL |     let f = |x: u32| -> u32 {
   |             --------------- value captured here
LL |         let g = factorial.as_ref().unwrap();
   |                 ^^^^^^^^^ borrowed value does not live long enough
LL | }
LL | }
   | - `factorial` dropped here while still borrowed

error[E0506]: cannot assign to `factorial` because it is borrowed
   |
   |
LL |     let mut factorial: Option<Box<dyn Fn(u32) -> u32 + 'static>> = None;
   |                        ----------------------------------------- type annotation requires that `factorial` is borrowed for `'static`
LL |
LL |     let f = |x: u32| -> u32 {
   |             --------------- borrow of `factorial` occurs here
LL |         let g = factorial.as_ref().unwrap();
   |                 --------- borrow occurs due to use in closure
LL |     factorial = Some(Box::new(f));
LL |     factorial = Some(Box::new(f));
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ assignment to borrowed `factorial` occurs here
error: aborting due to 4 previous errors

Some errors have detailed explanations: E0506, E0597.
For more information about an error, try `rustc --explain E0506`.

location: Location,
) {
if let mir::TerminatorKind::Drop { place, .. } = terminator.kind {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable shouldn't be considered initialized anymore but it's not handled by drop_flag_effects as it's not a move.
I think we can't rely on StorageDead because a drop could panic before reaching that location.

I discovered this problem in

let _v = (DropChecker(1), [panic; 0]);
.
The compiler moves panic into a temp variable, but since the array it's zero sized, that variable never gets moved anywere and it's immediately dropped.

_8 = move _3;                    // scope 2 at tests/ui/drop/repeat-drop.rs:105:36: 105:41
drop(_8) -> [return: bb1, unwind: bb9];

bb9 (cleanup): {
        drop(_8) -> bb10;                // scope 2 at tests/ui/drop/repeat-drop.rs:105:44: 105:45
    }

When this unwinds _8 is still considered initialized and drop elab does not remove the drop in bb9, which results in a double drop.

Now, not sure that this mir building is ideal (a panic in dropping a local shouldn't unwind to a block that drops the same local), but I think that what I said above about considering a variable uninitialized the moment it gets dropped still holds.

location: Location,
) {
if let mir::TerminatorKind::Drop { place, .. } = terminator.kind {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this change?

)
});
let source_info = this.source_info(span);
unpack!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason you changed build_drop_and_replace to only include the sad path replace?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially I removed all assigns and added the sad path one later. In the happy path you need the assign anyway at call site because you may not emit a replace if the type does not need a drop, so you can just add the assign regardless of whether you created a new block for a drop and replace or not.

Anyway, not a strong opinion, I'll revert to the original behavior

@apiraino
Copy link
Contributor

apiraino commented Feb 2, 2023

Switching to waiting on author until all comments are ticked ✔️ . Feel free to request a review with @rustbot ready, thanks!

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 2, 2023
@bors
Copy link
Contributor

bors commented Feb 6, 2023

☔ The latest upstream changes (presumably #107727) made this pull request unmergeable. Please resolve the merge conflicts.

@zeegomo
Copy link
Contributor Author

zeegomo commented Feb 7, 2023

Going to close this for now and split into smaller chunks like #107271

@zeegomo zeegomo closed this Feb 7, 2023
Dylan-DPC added a commit to Dylan-DPC/rust that referenced this pull request Feb 8, 2023
Treat Drop as a rmw operation

Previously, a Drop terminator was considered a move in MIR. This commit changes the behavior to only treat Drop as a mutable access to the dropped place.

In order for this change to be correct, we need to guarantee that

1.  A dropped value won't be used again
   2.  Places that appear in a drop won't be used again before a
     subsequent initialization.

We can ensure this to be correct at MIR construction because Drop will only be emitted when a variable goes out of scope, thus having:
*   (1) as there is no way of reaching the old value. drop-elaboration
     will also remove any uninitialized drop.
 * (2) as the place can't be named following the end of the scope.

However, the initialization status, previously tracked by moves, should also be tied to the execution of a Drop, hence the additional logic in the dataflow analyses.

From discussion in [this thread](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/.60DROP.60.20to.20.60DROP_IF.60.20compiler-team.23558), originating from rust-lang/compiler-team#558.
See also rust-lang#104488 (comment)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 8, 2023
Treat Drop as a rmw operation

Previously, a Drop terminator was considered a move in MIR. This commit changes the behavior to only treat Drop as a mutable access to the dropped place.

In order for this change to be correct, we need to guarantee that

1.  A dropped value won't be used again
   2.  Places that appear in a drop won't be used again before a
     subsequent initialization.

We can ensure this to be correct at MIR construction because Drop will only be emitted when a variable goes out of scope, thus having:
*   (1) as there is no way of reaching the old value. drop-elaboration
     will also remove any uninitialized drop.
 * (2) as the place can't be named following the end of the scope.

However, the initialization status, previously tracked by moves, should also be tied to the execution of a Drop, hence the additional logic in the dataflow analyses.

From discussion in [this thread](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/.60DROP.60.20to.20.60DROP_IF.60.20compiler-team.23558), originating from rust-lang/compiler-team#558.
See also rust-lang#104488 (comment)
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 8, 2023
Treat Drop as a rmw operation

Previously, a Drop terminator was considered a move in MIR. This commit changes the behavior to only treat Drop as a mutable access to the dropped place.

In order for this change to be correct, we need to guarantee that

1.  A dropped value won't be used again
   2.  Places that appear in a drop won't be used again before a
     subsequent initialization.

We can ensure this to be correct at MIR construction because Drop will only be emitted when a variable goes out of scope, thus having:
*   (1) as there is no way of reaching the old value. drop-elaboration
     will also remove any uninitialized drop.
 * (2) as the place can't be named following the end of the scope.

However, the initialization status, previously tracked by moves, should also be tied to the execution of a Drop, hence the additional logic in the dataflow analyses.

From discussion in [this thread](https://rust-lang.zulipchat.com/#narrow/stream/233931-t-compiler.2Fmajor-changes/topic/.60DROP.60.20to.20.60DROP_IF.60.20compiler-team.23558), originating from rust-lang/compiler-team#558.
See also rust-lang#104488 (comment)
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 5, 2023
Desugaring of drop and replace at MIR build

This commit desugars the drop and replace deriving from an
assignment at MIR build, avoiding the construction of the
`DropAndReplace` terminator (which will be removed in a following PR).

In order to retain the same error messages for replaces a new
`DesugaringKind::Replace` variant is introduced.

The changes in the borrowck are also useful for future work in moving drop elaboration
before borrowck, as no `DropAndReplace` would be present there anymore.

Notes on test diffs:
*  `tests/ui/borrowck/issue-58776-borrowck-scans-children`: the assignment deriving from the desugaring kills the borrow.
*  `tests/ui/async-await/async-fn-size-uninit-locals.rs`, `tests/mir-opt/issue_41110.test.ElaborateDrops.after.mir`,  `tests/mir-opt/issue_41888.main.ElaborateDrops.after.mir`:  drop elaboration generates (or reads from) a useless drop flag due to an issue with the dataflow analysis. Will be fixed independently by rust-lang#106430.

See rust-lang#104488 for more context
saethlin pushed a commit to saethlin/miri that referenced this pull request Mar 5, 2023
Desugaring of drop and replace at MIR build

This commit desugars the drop and replace deriving from an
assignment at MIR build, avoiding the construction of the
`DropAndReplace` terminator (which will be removed in a following PR).

In order to retain the same error messages for replaces a new
`DesugaringKind::Replace` variant is introduced.

The changes in the borrowck are also useful for future work in moving drop elaboration
before borrowck, as no `DropAndReplace` would be present there anymore.

Notes on test diffs:
*  `tests/ui/borrowck/issue-58776-borrowck-scans-children`: the assignment deriving from the desugaring kills the borrow.
*  `tests/ui/async-await/async-fn-size-uninit-locals.rs`, `tests/mir-opt/issue_41110.test.ElaborateDrops.after.mir`,  `tests/mir-opt/issue_41888.main.ElaborateDrops.after.mir`:  drop elaboration generates (or reads from) a useless drop flag due to an issue with the dataflow analysis. Will be fixed independently by rust-lang/rust#106430.

See rust-lang/rust#104488 for more context
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

spurious "borrow might be used .. when [variable] is dropped and runs the destructor"