Skip to content

Issue #46589 - Kill borrows on a local variable whenever we assign ov… - #46752

Merged
bors merged 1 commit into
rust-lang:masterfrom
Yoric:nll
Dec 22, 2017
Merged

Issue #46589 - Kill borrows on a local variable whenever we assign ov…#46752
bors merged 1 commit into
rust-lang:masterfrom
Yoric:nll

Conversation

@Yoric

Copy link
Copy Markdown
Contributor

…er this variable

This is a first patch for the issue, handling the simple case while I figure out the data structures involved in the more complex cases.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @pnkfelix

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

@bjorn3

Copy link
Copy Markdown
Member

Issue #46589 (just to link it)

Could you add a test?

@pnkfelix

Copy link
Copy Markdown
Contributor

The code looks fine to me; just add a test and we should be good.

@pnkfelixpnkfelix added A-NLL Area: Non-lexical lifetimes (NLL) WG-compiler-nll S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 16, 2017
@Yoric

Yoric commented Dec 19, 2017

Copy link
Copy Markdown
ContributorAuthor

I have added the test of issue #46589 and much to my surprise, it still fails, although it looks like it should be covered by my patch. I must be missing something obvious:

error[E0506]: cannot assign to `list` because it is borrowed
--> /Users/david/Documents/Code/rust-nll/src/test/run-pass/nll-iterating-and-updating.rs:25:13
|
23 | result.push(&mut list.value);
| --------------- borrow of `list` occurs here
24 | ifletSome(n) = list.next.as_mut(){25 | list = n;
| ^^^^^^^^ assignment to borrowed `list` occurs here
error:aborting due to previous error

@Yoric

Yoric commented Dec 19, 2017

Copy link
Copy Markdown
ContributorAuthor

Note: problem appears even if we add a

letmut list = list;

so it's probably not caused by list being an argument.

@arielb1

arielb1 commented Dec 19, 2017

Copy link
Copy Markdown
Contributor

@Yoric

I think that's because you haven't fixed this:

StatementKind::Assign(ref lhs,ref rhs) => {
// NOTE: NLL RFC calls for *shallow* write; using Deep
// for short-term compat w/ AST-borrowck. Also, switch
// to shallow requires to dataflow: "if this is an
// assignment `place = <rvalue>`, then any loan for some
// path P of which `place` is a prefix is killed."
self.mutate_place(
ContextKind::AssignLhs.new(location),
(lhs, span),
Deep,
JustWrite,
flow_state,
);
self.consume_rvalue(
ContextKind::AssignRhs.new(location),
(rhs, span),
location,
flow_state,
);
}

@Yoric

Copy link
Copy Markdown
ContributorAuthor

Ok, thanks to @arielb1, this now seems to work.

@Yoric
Yoricforce-pushed the nll branch 2 times, most recently from a96ad49 to 5e0e633CompareDecember 19, 2017 18:36
@Yoric

Copy link
Copy Markdown
ContributorAuthor

(oops, forgot to remove the obsolete test, this should now be fixed)

@arielb1

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Dec 19, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 5e0e633 has been approved by arielb1

@kennytmkennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 20, 2017
@bors

bors commented Dec 20, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 5e0e633d1f780f865b4c8298f7116b274824994a with merge 627022b2338aeb9e7d416bb1c6fee34125d8ec32...

@bors

bors commented Dec 20, 2017

Copy link
Copy Markdown
Collaborator

💔 Test failed - status-appveyor

@Yoric

Copy link
Copy Markdown
ContributorAuthor

As far as I can tell, the single failure is a timeout, which I imagine is not caused by this PR.

@kennytm

kennytm commented Dec 21, 2017

Copy link
Copy Markdown
Member

@bors retry — 3 hour timeout.

Details
Build number1.0.55911.0.5765
make-prepare43.4949.60
pytest/bootstrap0.000.00
stage0-std112.40120.96
stage0-tidy6.557.46
bootstrap5.735.92
stage0-test11.2612.68
llvm557.90642.91
stage0-rustc1080.531471.46
stage1-std54.3075.27
stage1-test16.1821.58
stage1-rustc1357.722055.58
stage0-compiletest54.95103.39
test/ui73.17188.49
test/run-pass1380.911874.05
test/compile-fail573.45568.06
test/parse-fail26.4732.96
test/run-fail30.8437.61
test/run-pass-valgrind4.084.66
test/mir-opt19.0033.14
test/codegen9.0010.73
test/codegen-units12.8110.29
test/incremental81.9978.64
test/debuginfo31.4731.93
test/ui-fulldeps17.0932.71
test/run-pass-fulldeps223.00297.01
test/run-fail-fulldeps3.084.81
test/compile-fail-fulldeps69.1991.50
stage2-rustdoc228.74301.32
test/run-make144.75171.07
test/rustdoc121.66175.18
stage1-test-libstd178.30236.88
test/libstd790.40914.47
stage1-test-libtest12.4613.91
test/libtest13.8218.38
stage1-test-librustc309.59394.63
test/librustc314.23400.63
stage2-test-rustdoc45.4954.72
test/libtools46.4055.56
stage0-unstable-book-gen8.6010.47
stage0-rustbook177.15181.70
doc/std27.8736.66
doc/compiler1.423.33
stage2-error_index_generator22.2128.20
stage0-linkchecker2.512.92
test/linkchecker44.0248.44
test/docs241.15
stage2-test-error-index61.73

@Yoric

Copy link
Copy Markdown
ContributorAuthor

Fwiw, SYS_BITS=32, RUST_CONFIGURE_ARGS=--build=i686-pc-windows-gnu, SCRIPT=python x.py test, MINGW_URL=https://s3-us-west-1.amazonaws.com/rust-lang-ci2/rust-ci-mirror, MINGW_ARCHIVE=i686-6.3.0-release-posix-dwarf-rt_v5-rev2.7z, MINGW_DIR=mingw32 timed out after 3 hr

@bors

bors commented Dec 21, 2017

Copy link
Copy Markdown
Collaborator

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

@kennytmkennytm 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 21, 2017
@kennytm

Copy link
Copy Markdown
Member

@bors r=arielb1

@bors

bors commented Dec 21, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit fcb1090 has been approved by arielb1

@kennytmkennytm added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Dec 21, 2017
@bors

bors commented Dec 22, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit fcb1090 with merge 264af16...

bors added a commit that referenced this pull request Dec 22, 2017
Issue #46589 - Kill borrows on a local variable whenever we assign ov…
…er this variable
This is a first patch for the issue, handling the simple case while I figure out the data structures involved in the more complex cases.
@bors

bors commented Dec 22, 2017

Copy link
Copy Markdown
Collaborator

☀️ Test successful - status-appveyor, status-travis
Approved by: arielb1
Pushing 264af16 to master...

@bors
bors merged commit fcb1090 into rust-lang:masterDec 22, 2017
bors added a commit that referenced this pull request Dec 26, 2017
[MIR Borrowck] Moveck inline asm statements
Closes#45695
New behavior:
* Input operands to `asm!` are moved, direct output operands are initialized.
* Direct, non-read-write outputs match the assignment changes in #46752 (Shallow writes, end borrows).
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-NLLArea: Non-lexical lifetimes (NLL)S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants

@Yoric@rust-highfive@bjorn3@pnkfelix@arielb1@bors@kennytm