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

NLL: Better Diagnostic When "Later" means "A Future Loop Iteration" #52948

Merged
merged 1 commit into from Aug 3, 2018

Conversation

Projects
None yet
4 participants
@davidtwco
Copy link
Member

davidtwco commented Aug 1, 2018

Part of #52663.

r? @pnkfelix

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Aug 1, 2018

This is officially awesome. Check out those diagnostics, especially for a case like

let mut acc = Counter{map: HashMap::new()};
for line in vec!["123456789".to_string(), "12345678".to_string()] {
let v: Vec<&str> = line.split_whitespace().collect();
//~^ ERROR `line` does not live long enough
println!("accumulator before add_assign {:?}", acc.map);
let mut map = HashMap::new();
for str_ref in v {
let e = map.entry(str_ref);
println!("entry: {:?}", e);
let count = e.or_insert(0);
*count += 1;
}
let cnt2 = Counter{map};
acc += cnt2;
println!("accumulator after add_assign {:?}", acc.map);
// line gets dropped here but references are kept in acc.map
}

which previously under AST-borrowck printed:

error[E0597]: `line` does not live long enough
--> $DIR/issue-52126-assign-op-invariance.rs:44:28
|
LL | let v: Vec<&str> = line.split_whitespace().collect();
| ^^^^ borrowed value does not live long enough
...
LL | }
| - `line` dropped here while still borrowed
LL | }
| - borrowed value needs to live until here

but with this PR prints:

error[E0597]: `line` does not live long enough
--> $DIR/issue-52126-assign-op-invariance.rs:44:28
|
LL | let v: Vec<&str> = line.split_whitespace().collect();
| ^^^^ borrowed value does not live long enough
LL | //~^ ERROR `line` does not live long enough
LL | println!("accumulator before add_assign {:?}", acc.map);
| ------- borrow used here in later iteration of loop
...
LL | }
| - `line` dropped here while still borrowed

@pnkfelix

This comment has been minimized.

Copy link
Member

pnkfelix commented Aug 1, 2018

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Aug 1, 2018

📌 Commit 1863cb7 has been approved by pnkfelix

cramertj added a commit to cramertj/rust that referenced this pull request Aug 2, 2018

Rollup merge of rust-lang#52948 - davidtwco:issue-52633-later-loop-it…
…eration, r=pnkfelix

NLL: Better Diagnostic When "Later" means "A Future Loop Iteration"

Part of rust-lang#52663.

r? @pnkfelix

cramertj added a commit to cramertj/rust that referenced this pull request Aug 2, 2018

Rollup merge of rust-lang#52948 - davidtwco:issue-52633-later-loop-it…
…eration, r=pnkfelix

NLL: Better Diagnostic When "Later" means "A Future Loop Iteration"

Part of rust-lang#52663.

r? @pnkfelix

bors added a commit that referenced this pull request Aug 2, 2018

Auto merge of #52989 - cramertj:rollup, r=cramertj
Rollup of 10 pull requests

Successful merges:

 - #52716 (Add lldb to the build)
 - #52782 ([NLL] Dangly paths for box)
 - #52886 (cleanup: Remove `Def::GlobalAsm`)
 - #52887 (Disable debug sections when optimization flags is set for LLD.)
 - #52925 (check_const: use the same ParamEnv as codegen for statics)
 - #52927 (Crate store cleanup)
 - #52940 (Align 6-week cycle check with beta promotion instead of stable release.)
 - #52948 (NLL: Better Diagnostic When "Later" means "A Future Loop Iteration")
 - #52952 (Update LLVM submodule)
 - #52973 (NLL mentions lifetimes that are not included in printed span(s).)

Failed merges:

r? @ghost
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Aug 3, 2018

⌛️ Testing commit 1863cb7 with merge e415b5e...

bors added a commit that referenced this pull request Aug 3, 2018

Auto merge of #52948 - davidtwco:issue-52633-later-loop-iteration, r=…
…pnkfelix

NLL: Better Diagnostic When "Later" means "A Future Loop Iteration"

Part of #52663.

r? @pnkfelix
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Aug 3, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: pnkfelix
Pushing e415b5e to master...

@bors bors merged commit 1863cb7 into rust-lang:master Aug 3, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@pnkfelix pnkfelix referenced this pull request Aug 3, 2018

Open

non-lexical lifetimes (NLL) tracking issue #43234

6 of 20 tasks complete

@davidtwco davidtwco deleted the davidtwco:issue-52633-later-loop-iteration branch Aug 6, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.