Skip to content

First attempt at removing DropAndReplace#104488

Closed
zeegomo wants to merge 13 commits intorust-lang:masterfrom
zeegomo:drop-elab
Closed

First attempt at removing DropAndReplace#104488
zeegomo wants to merge 13 commits intorust-lang:masterfrom
zeegomo:drop-elab

Conversation

@zeegomo
Copy link
Copy Markdown
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

Loading
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"