From d8bd5336c90764ca90e0e6f0df5bb309167e872c Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Fri, 25 May 2018 12:36:58 +0200 Subject: [PATCH] rust-lang/rust#51025: improve test robustness so that they work under NLL too. --- ...k-report-with-custom-diagnostic.nll.stderr | 48 ++++++++++++++----- .../borrowck-report-with-custom-diagnostic.rs | 9 ++++ ...rowck-report-with-custom-diagnostic.stderr | 10 ++-- .../mut-borrow-outside-loop.nll.stderr | 32 ++++++++----- .../ui/borrowck/mut-borrow-outside-loop.rs | 6 +++ .../borrowck/mut-borrow-outside-loop.stderr | 3 +- .../ui/codemap_tests/issue-11715.nll.stderr | 18 +++---- src/test/ui/codemap_tests/issue-11715.rs | 5 ++ src/test/ui/codemap_tests/issue-11715.stderr | 1 + .../dropck-eyepatch-extern-crate.nll.stderr | 21 ++++---- .../ui/dropck/dropck-eyepatch-extern-crate.rs | 28 +++++++---- .../dropck-eyepatch-extern-crate.stderr | 48 ++++++++++++++----- .../dropck/dropck-eyepatch-reorder.nll.stderr | 21 ++++---- src/test/ui/dropck/dropck-eyepatch-reorder.rs | 28 +++++++---- .../ui/dropck/dropck-eyepatch-reorder.stderr | 48 ++++++++++++++----- src/test/ui/dropck/dropck-eyepatch.nll.stderr | 21 ++++---- src/test/ui/dropck/dropck-eyepatch.rs | 29 +++++++---- src/test/ui/dropck/dropck-eyepatch.stderr | 48 ++++++++++++++----- src/test/ui/error-codes/E0499.nll.stderr | 18 +++---- src/test/ui/error-codes/E0499.rs | 9 +++- src/test/ui/error-codes/E0499.stderr | 1 + src/test/ui/error-codes/E0502.nll.stderr | 14 ++++-- src/test/ui/error-codes/E0502.rs | 8 +++- src/test/ui/error-codes/E0502.stderr | 1 + src/test/ui/error-codes/E0503.nll.stderr | 17 +++---- src/test/ui/error-codes/E0503.rs | 8 +++- src/test/ui/error-codes/E0505.nll.stderr | 19 ++++---- src/test/ui/error-codes/E0505.rs | 8 +++- src/test/ui/error-codes/E0597.nll.stderr | 20 ++++---- src/test/ui/error-codes/E0597.rs | 6 ++- src/test/ui/generator/dropck.nll.stderr | 14 +++++- src/test/ui/generator/dropck.rs | 2 +- .../ui/generator/pattern-borrow.nll.stderr | 11 +++-- src/test/ui/generator/pattern-borrow.rs | 8 +++- .../fields-numeric-borrowck.nll.stderr | 19 ++++---- .../ui/hygiene/fields-numeric-borrowck.rs | 9 +++- .../ui/hygiene/fields-numeric-borrowck.stderr | 2 +- src/test/ui/issue-25793.nll.stderr | 17 +++++-- src/test/ui/issue-25793.rs | 7 ++- src/test/ui/issue-25793.stderr | 8 ++-- src/test/ui/issue-42106.nll.stderr | 13 +++-- src/test/ui/issue-42106.rs | 8 +++- src/test/ui/issue-42106.stderr | 1 + .../ex3-both-anon-regions-2.nll.stderr | 20 ++++---- .../ex3-both-anon-regions-2.rs | 4 +- .../ex3-both-anon-regions-2.stderr | 10 ++-- .../borrowck-let-suggestion.nll.stderr | 17 ++++--- .../ui/lifetimes/borrowck-let-suggestion.rs | 10 ++-- .../lifetimes/borrowck-let-suggestion.stderr | 11 +++-- ...orrowck-let-suggestion-suffixes.nll.stderr | 40 +++++++++++++--- .../span/borrowck-let-suggestion-suffixes.rs | 7 ++- src/test/ui/span/issue-36537.nll.stderr | 19 ++++---- src/test/ui/span/issue-36537.rs | 18 +++++-- src/test/ui/span/issue-36537.stderr | 15 +++--- .../span/mut-ptr-cant-outlive-ref.nll.stderr | 20 ++++---- src/test/ui/span/mut-ptr-cant-outlive-ref.rs | 8 +++- .../ui/span/mut-ptr-cant-outlive-ref.stderr | 2 +- src/test/ui/span/range-2.nll.stderr | 33 ++++++++----- src/test/ui/span/range-2.rs | 4 ++ ...ionck-unboxed-closure-lifetimes.nll.stderr | 20 ++++---- .../regionck-unboxed-closure-lifetimes.rs | 4 ++ .../regionck-unboxed-closure-lifetimes.stderr | 1 + .../send-is-not-static-std-sync.nll.stderr | 32 +++++++++++-- .../ui/span/send-is-not-static-std-sync.rs | 6 +++ .../span/send-is-not-static-std-sync.stderr | 14 +++--- src/test/ui/span/slice-borrow.nll.stderr | 22 +++++---- src/test/ui/span/slice-borrow.rs | 8 +++- src/test/ui/span/slice-borrow.stderr | 1 + .../vec_refs_data_with_early_death.nll.stderr | 35 +++++++++----- .../ui/span/vec_refs_data_with_early_death.rs | 34 ++++++++----- 70 files changed, 725 insertions(+), 362 deletions(-) diff --git a/src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.nll.stderr b/src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.nll.stderr index 951907876b9ca..fa600f0559f17 100644 --- a/src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.nll.stderr +++ b/src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.nll.stderr @@ -1,14 +1,40 @@ -error: compilation successful - --> $DIR/borrowck-report-with-custom-diagnostic.rs:12:1 +error[E0502]: cannot borrow `x` as immutable because it is also borrowed as mutable + --> $DIR/borrowck-report-with-custom-diagnostic.rs:17:13 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | // Original borrow ends at end of function -LL | | let mut x = 1; -LL | | let y = &mut x; -... | -LL | | //~^ immutable borrow occurs here -LL | | } - | |_^ +LL | let y = &mut x; + | ------ mutable borrow occurs here +LL | //~^ mutable borrow occurs here +LL | let z = &x; //~ ERROR cannot borrow + | ^^ immutable borrow occurs here +... +LL | y.use_mut(); + | - borrow later used here -error: aborting due to previous error +error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable + --> $DIR/borrowck-report-with-custom-diagnostic.rs:30:21 + | +LL | let y = &x; + | -- immutable borrow occurs here +LL | //~^ immutable borrow occurs here +LL | let z = &mut x; //~ ERROR cannot borrow + | ^^^^^^ mutable borrow occurs here +... +LL | y.use_ref(); + | - borrow later used here + +error[E0499]: cannot borrow `x` as mutable more than once at a time + --> $DIR/borrowck-report-with-custom-diagnostic.rs:45:17 + | +LL | let y = &mut x; + | ------ first mutable borrow occurs here +LL | //~^ first mutable borrow occurs here +LL | let z = &mut x; //~ ERROR cannot borrow + | ^^^^^^ second mutable borrow occurs here +... +LL | y.use_mut(); + | - borrow later used here + +error: aborting due to 3 previous errors +Some errors occurred: E0499, E0502. +For more information about an error, try `rustc --explain E0499`. diff --git a/src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.rs b/src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.rs index cdfee2e8a7049..2bc65287982af 100644 --- a/src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.rs +++ b/src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.rs @@ -16,6 +16,8 @@ fn main() { #![rustc_error] // rust-lang/rust#49855 //~^ mutable borrow occurs here let z = &x; //~ ERROR cannot borrow //~^ immutable borrow occurs here + z.use_ref(); + y.use_mut(); } fn foo() { @@ -27,6 +29,8 @@ fn foo() { //~^ immutable borrow occurs here let z = &mut x; //~ ERROR cannot borrow //~^ mutable borrow occurs here + z.use_mut(); + y.use_ref(); } false => () } @@ -40,5 +44,10 @@ fn bar() { //~^ first mutable borrow occurs here let z = &mut x; //~ ERROR cannot borrow //~^ second mutable borrow occurs here + z.use_mut(); + y.use_mut(); }; } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.stderr b/src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.stderr index 648ee1dff7851..1fe052cef7111 100644 --- a/src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.stderr +++ b/src/test/ui/borrowck/borrowck-report-with-custom-diagnostic.stderr @@ -6,31 +6,31 @@ LL | let y = &mut x; LL | //~^ mutable borrow occurs here LL | let z = &x; //~ ERROR cannot borrow | ^ immutable borrow occurs here -LL | //~^ immutable borrow occurs here +... LL | } | - mutable borrow ends here error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable - --> $DIR/borrowck-report-with-custom-diagnostic.rs:28:26 + --> $DIR/borrowck-report-with-custom-diagnostic.rs:30:26 | LL | let y = &x; | - immutable borrow occurs here LL | //~^ immutable borrow occurs here LL | let z = &mut x; //~ ERROR cannot borrow | ^ mutable borrow occurs here -LL | //~^ mutable borrow occurs here +... LL | } | - immutable borrow ends here error[E0499]: cannot borrow `x` as mutable more than once at a time - --> $DIR/borrowck-report-with-custom-diagnostic.rs:41:22 + --> $DIR/borrowck-report-with-custom-diagnostic.rs:45:22 | LL | let y = &mut x; | - first mutable borrow occurs here LL | //~^ first mutable borrow occurs here LL | let z = &mut x; //~ ERROR cannot borrow | ^ second mutable borrow occurs here -LL | //~^ second mutable borrow occurs here +... LL | }; | - first borrow ends here diff --git a/src/test/ui/borrowck/mut-borrow-outside-loop.nll.stderr b/src/test/ui/borrowck/mut-borrow-outside-loop.nll.stderr index dab769820a685..55f57e97ba4fa 100644 --- a/src/test/ui/borrowck/mut-borrow-outside-loop.nll.stderr +++ b/src/test/ui/borrowck/mut-borrow-outside-loop.nll.stderr @@ -1,14 +1,24 @@ -error: compilation successful - --> $DIR/mut-borrow-outside-loop.rs:13:1 +error[E0499]: cannot borrow `void` as mutable more than once at a time + --> $DIR/mut-borrow-outside-loop.rs:17:18 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let mut void = (); -LL | | -LL | | let first = &mut void; -... | -LL | | } -LL | | } - | |_^ +LL | let first = &mut void; + | --------- first mutable borrow occurs here +LL | let second = &mut void; //~ ERROR cannot borrow + | ^^^^^^^^^ second mutable borrow occurs here +LL | first.use_mut(); + | ----- borrow later used here -error: aborting due to previous error +error[E0499]: cannot borrow `inner_void` as mutable more than once at a time + --> $DIR/mut-borrow-outside-loop.rs:25:28 + | +LL | let inner_first = &mut inner_void; + | --------------- first mutable borrow occurs here +LL | let inner_second = &mut inner_void; //~ ERROR cannot borrow + | ^^^^^^^^^^^^^^^ second mutable borrow occurs here +LL | inner_second.use_mut(); +LL | inner_first.use_mut(); + | ----------- borrow later used here + +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0499`. diff --git a/src/test/ui/borrowck/mut-borrow-outside-loop.rs b/src/test/ui/borrowck/mut-borrow-outside-loop.rs index edc877718ad0a..aba520bd864d2 100644 --- a/src/test/ui/borrowck/mut-borrow-outside-loop.rs +++ b/src/test/ui/borrowck/mut-borrow-outside-loop.rs @@ -15,12 +15,18 @@ fn main() { #![rustc_error] // rust-lang/rust#49855 let first = &mut void; let second = &mut void; //~ ERROR cannot borrow + first.use_mut(); + second.use_mut(); loop { let mut inner_void = (); let inner_first = &mut inner_void; let inner_second = &mut inner_void; //~ ERROR cannot borrow + inner_second.use_mut(); + inner_first.use_mut(); } } +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/borrowck/mut-borrow-outside-loop.stderr b/src/test/ui/borrowck/mut-borrow-outside-loop.stderr index 80a3ba4493c5b..95e9fa19129be 100644 --- a/src/test/ui/borrowck/mut-borrow-outside-loop.stderr +++ b/src/test/ui/borrowck/mut-borrow-outside-loop.stderr @@ -10,12 +10,13 @@ LL | } | - first borrow ends here error[E0499]: cannot borrow `inner_void` as mutable more than once at a time - --> $DIR/mut-borrow-outside-loop.rs:23:33 + --> $DIR/mut-borrow-outside-loop.rs:25:33 | LL | let inner_first = &mut inner_void; | ---------- first mutable borrow occurs here LL | let inner_second = &mut inner_void; //~ ERROR cannot borrow | ^^^^^^^^^^ second mutable borrow occurs here +... LL | } | - first borrow ends here diff --git a/src/test/ui/codemap_tests/issue-11715.nll.stderr b/src/test/ui/codemap_tests/issue-11715.nll.stderr index 952ccdb98dae9..c0eeb63447d55 100644 --- a/src/test/ui/codemap_tests/issue-11715.nll.stderr +++ b/src/test/ui/codemap_tests/issue-11715.nll.stderr @@ -1,12 +1,14 @@ -error: compilation successful - --> $DIR/issue-11715.rs:97:1 +error[E0499]: cannot borrow `x` as mutable more than once at a time + --> $DIR/issue-11715.rs:100:13 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let mut x = "foo"; -LL | | let y = &mut x; -LL | | let z = &mut x; //~ ERROR cannot borrow -LL | | } - | |_^ +LL | let y = &mut x; + | ------ first mutable borrow occurs here +LL | let z = &mut x; //~ ERROR cannot borrow + | ^^^^^^ second mutable borrow occurs here +LL | z.use_mut(); +LL | y.use_mut(); + | - borrow later used here error: aborting due to previous error +For more information about this error, try `rustc --explain E0499`. diff --git a/src/test/ui/codemap_tests/issue-11715.rs b/src/test/ui/codemap_tests/issue-11715.rs index 03c85fbfcd773..415aa3687083b 100644 --- a/src/test/ui/codemap_tests/issue-11715.rs +++ b/src/test/ui/codemap_tests/issue-11715.rs @@ -98,4 +98,9 @@ fn main() { #![rustc_error] // rust-lang/rust#49855 let mut x = "foo"; let y = &mut x; let z = &mut x; //~ ERROR cannot borrow + z.use_mut(); + y.use_mut(); } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/codemap_tests/issue-11715.stderr b/src/test/ui/codemap_tests/issue-11715.stderr index d9551d7918a9f..eb73c69c5dcf0 100644 --- a/src/test/ui/codemap_tests/issue-11715.stderr +++ b/src/test/ui/codemap_tests/issue-11715.stderr @@ -5,6 +5,7 @@ LL | let y = &mut x; | - first mutable borrow occurs here LL | let z = &mut x; //~ ERROR cannot borrow | ^ second mutable borrow occurs here +... LL | } | - first borrow ends here diff --git a/src/test/ui/dropck/dropck-eyepatch-extern-crate.nll.stderr b/src/test/ui/dropck/dropck-eyepatch-extern-crate.nll.stderr index 692f697e889bc..008ecfeabcb14 100644 --- a/src/test/ui/dropck/dropck-eyepatch-extern-crate.nll.stderr +++ b/src/test/ui/dropck/dropck-eyepatch-extern-crate.nll.stderr @@ -1,14 +1,15 @@ -error: compilation successful - --> $DIR/dropck-eyepatch-extern-crate.rs:27:1 +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch-extern-crate.rs:47:19 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | use std::cell::Cell; -LL | | let c_long; -LL | | let (c, mut dt, mut dr, mut pt, mut pr, st, sr) -... | -LL | | println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0)); -LL | | } - | |_^ +LL | dt = Dt("dt", &c_shortest); + | ^^^^^^^^^^^ borrowed value does not live long enough +... +LL | } + | - + | | + | borrowed value only lives until here + | borrow later used here, when `dt` is dropped error: aborting due to previous error +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/dropck/dropck-eyepatch-extern-crate.rs b/src/test/ui/dropck/dropck-eyepatch-extern-crate.rs index e06b47a8d79dc..3e531d9fd6011 100644 --- a/src/test/ui/dropck/dropck-eyepatch-extern-crate.rs +++ b/src/test/ui/dropck/dropck-eyepatch-extern-crate.rs @@ -27,33 +27,41 @@ use other::{Dt,Dr,Pt,Pr,St,Sr}; fn main() { #![rustc_error] // rust-lang/rust#49855 use std::cell::Cell; let c_long; - let (c, mut dt, mut dr, mut pt, mut pr, st, sr) - : (Cell<_>, Dt<_>, Dr<_>, Pt<_, _>, Pr<_>, St<_>, Sr<_>); + let (c, mut dt, mut dr, mut pt, mut pr, st, sr, c_shortest) + : (Cell<_>, Dt<_>, Dr<_>, Pt<_, _>, Pr<_>, St<_>, Sr<_>, Cell<_>); c_long = Cell::new(1); c = Cell::new(1); + c_shortest = Cell::new(1); // No error: sufficiently long-lived state can be referenced in dtors dt = Dt("dt", &c_long); dr = Dr("dr", &c_long); + // Error: destructor order imprecisely modelled dt = Dt("dt", &c); //~^ ERROR `c` does not live long enough dr = Dr("dr", &c); //~^ ERROR `c` does not live long enough + // Error: `c_shortest` dies too soon for the references in dtors to be valid. + dt = Dt("dt", &c_shortest); + //~^ ERROR `c_shortest` does not live long enough + dr = Dr("dr", &c_shortest); + //~^ ERROR `c_shortest` does not live long enough + // No error: Drop impl asserts .1 (A and &'a _) are not accessed - pt = Pt("pt", &c, &c_long); - pr = Pr("pr", &c, &c_long); + pt = Pt("pt", &c_shortest, &c_long); + pr = Pr("pr", &c_shortest, &c_long); // Error: Drop impl's assertion does not apply to `B` nor `&'b _` - pt = Pt("pt", &c_long, &c); - //~^ ERROR `c` does not live long enough - pr = Pr("pr", &c_long, &c); - //~^ ERROR `c` does not live long enough + pt = Pt("pt", &c_long, &c_shortest); + //~^ ERROR `c_shortest` does not live long enough + pr = Pr("pr", &c_long, &c_shortest); + //~^ ERROR `c_shortest` does not live long enough // No error: St and Sr have no destructor. - st = St("st", &c); - sr = Sr("sr", &c); + st = St("st", &c_shortest); + sr = Sr("sr", &c_shortest); println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0)); } diff --git a/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr b/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr index 668fbf9521b17..35db46f4faeb1 100644 --- a/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr +++ b/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr @@ -1,5 +1,5 @@ error[E0597]: `c` does not live long enough - --> $DIR/dropck-eyepatch-extern-crate.rs:39:20 + --> $DIR/dropck-eyepatch-extern-crate.rs:41:20 | LL | dt = Dt("dt", &c); | ^ borrowed value does not live long enough @@ -10,7 +10,7 @@ LL | } = note: values in a scope are dropped in the opposite order they are created error[E0597]: `c` does not live long enough - --> $DIR/dropck-eyepatch-extern-crate.rs:41:20 + --> $DIR/dropck-eyepatch-extern-crate.rs:43:20 | LL | dr = Dr("dr", &c); | ^ borrowed value does not live long enough @@ -20,28 +20,50 @@ LL | } | = note: values in a scope are dropped in the opposite order they are created -error[E0597]: `c` does not live long enough - --> $DIR/dropck-eyepatch-extern-crate.rs:49:29 +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch-extern-crate.rs:47:20 | -LL | pt = Pt("pt", &c_long, &c); - | ^ borrowed value does not live long enough +LL | dt = Dt("dt", &c_shortest); + | ^^^^^^^^^^ borrowed value does not live long enough ... LL | } - | - `c` dropped here while still borrowed + | - `c_shortest` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created -error[E0597]: `c` does not live long enough - --> $DIR/dropck-eyepatch-extern-crate.rs:51:29 +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch-extern-crate.rs:49:20 | -LL | pr = Pr("pr", &c_long, &c); - | ^ borrowed value does not live long enough +LL | dr = Dr("dr", &c_shortest); + | ^^^^^^^^^^ borrowed value does not live long enough ... LL | } - | - `c` dropped here while still borrowed + | - `c_shortest` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch-extern-crate.rs:57:29 + | +LL | pt = Pt("pt", &c_long, &c_shortest); + | ^^^^^^^^^^ borrowed value does not live long enough +... +LL | } + | - `c_shortest` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch-extern-crate.rs:59:29 + | +LL | pr = Pr("pr", &c_long, &c_shortest); + | ^^^^^^^^^^ borrowed value does not live long enough +... +LL | } + | - `c_shortest` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created -error: aborting due to 4 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/dropck/dropck-eyepatch-reorder.nll.stderr b/src/test/ui/dropck/dropck-eyepatch-reorder.nll.stderr index f50168fd5862d..233ff198af48b 100644 --- a/src/test/ui/dropck/dropck-eyepatch-reorder.nll.stderr +++ b/src/test/ui/dropck/dropck-eyepatch-reorder.nll.stderr @@ -1,14 +1,15 @@ -error: compilation successful - --> $DIR/dropck-eyepatch-reorder.rs:44:1 +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch-reorder.rs:64:19 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | use std::cell::Cell; -LL | | let c_long; -LL | | let (c, mut dt, mut dr, mut pt, mut pr, st, sr) -... | -LL | | println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0)); -LL | | } - | |_^ +LL | dt = Dt("dt", &c_shortest); + | ^^^^^^^^^^^ borrowed value does not live long enough +... +LL | } + | - + | | + | borrowed value only lives until here + | borrow later used here, when `dt` is dropped error: aborting due to previous error +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/dropck/dropck-eyepatch-reorder.rs b/src/test/ui/dropck/dropck-eyepatch-reorder.rs index 832eeacbec54a..1806dc7142452 100644 --- a/src/test/ui/dropck/dropck-eyepatch-reorder.rs +++ b/src/test/ui/dropck/dropck-eyepatch-reorder.rs @@ -44,33 +44,41 @@ unsafe impl<'b, #[may_dangle] 'a, B: fmt::Debug> Drop for Pr<'a, 'b, B> { fn main() { #![rustc_error] // rust-lang/rust#49855 use std::cell::Cell; let c_long; - let (c, mut dt, mut dr, mut pt, mut pr, st, sr) - : (Cell<_>, Dt<_>, Dr<_>, Pt<_, _>, Pr<_>, St<_>, Sr<_>); + let (c, mut dt, mut dr, mut pt, mut pr, st, sr, c_shortest) + : (Cell<_>, Dt<_>, Dr<_>, Pt<_, _>, Pr<_>, St<_>, Sr<_>, Cell<_>); c_long = Cell::new(1); c = Cell::new(1); + c_shortest = Cell::new(1); // No error: sufficiently long-lived state can be referenced in dtors dt = Dt("dt", &c_long); dr = Dr("dr", &c_long); + // Error: destructor order imprecisely modelled dt = Dt("dt", &c); //~^ ERROR `c` does not live long enough dr = Dr("dr", &c); //~^ ERROR `c` does not live long enough + // Error: `c_shortest` dies too soon for the references in dtors to be valid. + dt = Dt("dt", &c_shortest); + //~^ ERROR `c_shortest` does not live long enough + dr = Dr("dr", &c_shortest); + //~^ ERROR `c_shortest` does not live long enough + // No error: Drop impl asserts .1 (A and &'a _) are not accessed - pt = Pt("pt", &c, &c_long); - pr = Pr("pr", &c, &c_long); + pt = Pt("pt", &c_shortest, &c_long); + pr = Pr("pr", &c_shortest, &c_long); // Error: Drop impl's assertion does not apply to `B` nor `&'b _` - pt = Pt("pt", &c_long, &c); - //~^ ERROR `c` does not live long enough - pr = Pr("pr", &c_long, &c); - //~^ ERROR `c` does not live long enough + pt = Pt("pt", &c_long, &c_shortest); + //~^ ERROR `c_shortest` does not live long enough + pr = Pr("pr", &c_long, &c_shortest); + //~^ ERROR `c_shortest` does not live long enough // No error: St and Sr have no destructor. - st = St("st", &c); - sr = Sr("sr", &c); + st = St("st", &c_shortest); + sr = Sr("sr", &c_shortest); println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0)); } diff --git a/src/test/ui/dropck/dropck-eyepatch-reorder.stderr b/src/test/ui/dropck/dropck-eyepatch-reorder.stderr index 1a35996a0cadb..9984a7b9409c4 100644 --- a/src/test/ui/dropck/dropck-eyepatch-reorder.stderr +++ b/src/test/ui/dropck/dropck-eyepatch-reorder.stderr @@ -1,5 +1,5 @@ error[E0597]: `c` does not live long enough - --> $DIR/dropck-eyepatch-reorder.rs:56:20 + --> $DIR/dropck-eyepatch-reorder.rs:58:20 | LL | dt = Dt("dt", &c); | ^ borrowed value does not live long enough @@ -10,7 +10,7 @@ LL | } = note: values in a scope are dropped in the opposite order they are created error[E0597]: `c` does not live long enough - --> $DIR/dropck-eyepatch-reorder.rs:58:20 + --> $DIR/dropck-eyepatch-reorder.rs:60:20 | LL | dr = Dr("dr", &c); | ^ borrowed value does not live long enough @@ -20,28 +20,50 @@ LL | } | = note: values in a scope are dropped in the opposite order they are created -error[E0597]: `c` does not live long enough - --> $DIR/dropck-eyepatch-reorder.rs:66:29 +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch-reorder.rs:64:20 | -LL | pt = Pt("pt", &c_long, &c); - | ^ borrowed value does not live long enough +LL | dt = Dt("dt", &c_shortest); + | ^^^^^^^^^^ borrowed value does not live long enough ... LL | } - | - `c` dropped here while still borrowed + | - `c_shortest` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created -error[E0597]: `c` does not live long enough - --> $DIR/dropck-eyepatch-reorder.rs:68:29 +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch-reorder.rs:66:20 | -LL | pr = Pr("pr", &c_long, &c); - | ^ borrowed value does not live long enough +LL | dr = Dr("dr", &c_shortest); + | ^^^^^^^^^^ borrowed value does not live long enough ... LL | } - | - `c` dropped here while still borrowed + | - `c_shortest` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch-reorder.rs:74:29 + | +LL | pt = Pt("pt", &c_long, &c_shortest); + | ^^^^^^^^^^ borrowed value does not live long enough +... +LL | } + | - `c_shortest` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch-reorder.rs:76:29 + | +LL | pr = Pr("pr", &c_long, &c_shortest); + | ^^^^^^^^^^ borrowed value does not live long enough +... +LL | } + | - `c_shortest` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created -error: aborting due to 4 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/dropck/dropck-eyepatch.nll.stderr b/src/test/ui/dropck/dropck-eyepatch.nll.stderr index 8c55fdbc0b86b..7b27ff01f924a 100644 --- a/src/test/ui/dropck/dropck-eyepatch.nll.stderr +++ b/src/test/ui/dropck/dropck-eyepatch.nll.stderr @@ -1,14 +1,15 @@ -error: compilation successful - --> $DIR/dropck-eyepatch.rs:67:1 +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch.rs:87:19 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | use std::cell::Cell; -LL | | let c_long; -LL | | let (c, mut dt, mut dr, mut pt, mut pr, st, sr) -... | -LL | | println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0)); -LL | | } - | |_^ +LL | dt = Dt("dt", &c_shortest); + | ^^^^^^^^^^^ borrowed value does not live long enough +... +LL | } + | - + | | + | borrowed value only lives until here + | borrow later used here, when `dt` is dropped error: aborting due to previous error +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/dropck/dropck-eyepatch.rs b/src/test/ui/dropck/dropck-eyepatch.rs index cfa67837485e5..40d3ff050e2aa 100644 --- a/src/test/ui/dropck/dropck-eyepatch.rs +++ b/src/test/ui/dropck/dropck-eyepatch.rs @@ -67,33 +67,42 @@ unsafe impl<#[may_dangle] 'a, 'b, B: fmt::Debug> Drop for Pr<'a, 'b, B> { fn main() { #![rustc_error] // rust-lang/rust#49855 use std::cell::Cell; let c_long; - let (c, mut dt, mut dr, mut pt, mut pr, st, sr) - : (Cell<_>, Dt<_>, Dr<_>, Pt<_, _>, Pr<_>, St<_>, Sr<_>); + let (c, mut dt, mut dr, mut pt, mut pr, st, sr, c_shortest) + : (Cell<_>, Dt<_>, Dr<_>, Pt<_, _>, Pr<_>, St<_>, Sr<_>, Cell<_>); c_long = Cell::new(1); c = Cell::new(1); + c_shortest = Cell::new(1); // No error: sufficiently long-lived state can be referenced in dtors dt = Dt("dt", &c_long); dr = Dr("dr", &c_long); + // Error: destructor order imprecisely modelled dt = Dt("dt", &c); //~^ ERROR `c` does not live long enough dr = Dr("dr", &c); //~^ ERROR `c` does not live long enough + // Error: `c_shortest` dies too soon for the references in dtors to be valid. + dt = Dt("dt", &c_shortest); + //~^ ERROR `c_shortest` does not live long enough + dr = Dr("dr", &c_shortest); + //~^ ERROR `c_shortest` does not live long enough + + // No error: Drop impl asserts .1 (A and &'a _) are not accessed - pt = Pt("pt", &c, &c_long); - pr = Pr("pr", &c, &c_long); + pt = Pt("pt", &c_shortest, &c_long); + pr = Pr("pr", &c_shortest, &c_long); // Error: Drop impl's assertion does not apply to `B` nor `&'b _` - pt = Pt("pt", &c_long, &c); - //~^ ERROR `c` does not live long enough - pr = Pr("pr", &c_long, &c); - //~^ ERROR `c` does not live long enough + pt = Pt("pt", &c_long, &c_shortest); + //~^ ERROR `c_shortest` does not live long enough + pr = Pr("pr", &c_long, &c_shortest); + //~^ ERROR `c_shortest` does not live long enough // No error: St and Sr have no destructor. - st = St("st", &c); - sr = Sr("sr", &c); + st = St("st", &c_shortest); + sr = Sr("sr", &c_shortest); println!("{:?}", (dt.0, dr.0, pt.0, pr.0, st.0, sr.0)); } diff --git a/src/test/ui/dropck/dropck-eyepatch.stderr b/src/test/ui/dropck/dropck-eyepatch.stderr index 4d29164202293..7cdf645941d09 100644 --- a/src/test/ui/dropck/dropck-eyepatch.stderr +++ b/src/test/ui/dropck/dropck-eyepatch.stderr @@ -1,5 +1,5 @@ error[E0597]: `c` does not live long enough - --> $DIR/dropck-eyepatch.rs:79:20 + --> $DIR/dropck-eyepatch.rs:81:20 | LL | dt = Dt("dt", &c); | ^ borrowed value does not live long enough @@ -10,7 +10,7 @@ LL | } = note: values in a scope are dropped in the opposite order they are created error[E0597]: `c` does not live long enough - --> $DIR/dropck-eyepatch.rs:81:20 + --> $DIR/dropck-eyepatch.rs:83:20 | LL | dr = Dr("dr", &c); | ^ borrowed value does not live long enough @@ -20,28 +20,50 @@ LL | } | = note: values in a scope are dropped in the opposite order they are created -error[E0597]: `c` does not live long enough - --> $DIR/dropck-eyepatch.rs:89:29 +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch.rs:87:20 | -LL | pt = Pt("pt", &c_long, &c); - | ^ borrowed value does not live long enough +LL | dt = Dt("dt", &c_shortest); + | ^^^^^^^^^^ borrowed value does not live long enough ... LL | } - | - `c` dropped here while still borrowed + | - `c_shortest` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created -error[E0597]: `c` does not live long enough - --> $DIR/dropck-eyepatch.rs:91:29 +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch.rs:89:20 | -LL | pr = Pr("pr", &c_long, &c); - | ^ borrowed value does not live long enough +LL | dr = Dr("dr", &c_shortest); + | ^^^^^^^^^^ borrowed value does not live long enough ... LL | } - | - `c` dropped here while still borrowed + | - `c_shortest` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch.rs:98:29 + | +LL | pt = Pt("pt", &c_long, &c_shortest); + | ^^^^^^^^^^ borrowed value does not live long enough +... +LL | } + | - `c_shortest` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error[E0597]: `c_shortest` does not live long enough + --> $DIR/dropck-eyepatch.rs:100:29 + | +LL | pr = Pr("pr", &c_long, &c_shortest); + | ^^^^^^^^^^ borrowed value does not live long enough +... +LL | } + | - `c_shortest` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created -error: aborting due to 4 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/error-codes/E0499.nll.stderr b/src/test/ui/error-codes/E0499.nll.stderr index 27a71df147e1d..89801693b763c 100644 --- a/src/test/ui/error-codes/E0499.nll.stderr +++ b/src/test/ui/error-codes/E0499.nll.stderr @@ -1,12 +1,14 @@ -error: compilation successful - --> $DIR/E0499.rs:11:1 +error[E0499]: cannot borrow `i` as mutable more than once at a time + --> $DIR/E0499.rs:14:17 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let mut i = 0; -LL | | let mut x = &mut i; -LL | | let mut a = &mut i; //~ ERROR E0499 -LL | | } - | |_^ +LL | let mut x = &mut i; + | ------ first mutable borrow occurs here +LL | let mut a = &mut i; //~ ERROR E0499 + | ^^^^^^ second mutable borrow occurs here +LL | a.use_mut(); +LL | x.use_mut(); + | - borrow later used here error: aborting due to previous error +For more information about this error, try `rustc --explain E0499`. diff --git a/src/test/ui/error-codes/E0499.rs b/src/test/ui/error-codes/E0499.rs index c39972369347a..9fb235eccdd31 100644 --- a/src/test/ui/error-codes/E0499.rs +++ b/src/test/ui/error-codes/E0499.rs @@ -7,9 +7,14 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_attrs)] -fn main() { #![rustc_error] // rust-lang/rust#49855 + +fn main() { let mut i = 0; let mut x = &mut i; let mut a = &mut i; //~ ERROR E0499 + a.use_mut(); + x.use_mut(); } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/error-codes/E0499.stderr b/src/test/ui/error-codes/E0499.stderr index dcb477ab1cb85..8f4fd445fc2a5 100644 --- a/src/test/ui/error-codes/E0499.stderr +++ b/src/test/ui/error-codes/E0499.stderr @@ -5,6 +5,7 @@ LL | let mut x = &mut i; | - first mutable borrow occurs here LL | let mut a = &mut i; //~ ERROR E0499 | ^ second mutable borrow occurs here +... LL | } | - first borrow ends here diff --git a/src/test/ui/error-codes/E0502.nll.stderr b/src/test/ui/error-codes/E0502.nll.stderr index 67a08661040cf..565f73616b9fe 100644 --- a/src/test/ui/error-codes/E0502.nll.stderr +++ b/src/test/ui/error-codes/E0502.nll.stderr @@ -1,9 +1,13 @@ -error: compilation successful - --> $DIR/E0502.rs:17:1 +error[E0502]: cannot borrow `*a` as mutable because it is also borrowed as immutable + --> $DIR/E0502.rs:14:5 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | } - | |_^ +LL | let ref y = a; + | ----- immutable borrow occurs here +LL | bar(a); //~ ERROR E0502 + | ^^^^^^ mutable borrow occurs here +LL | y.use_ref(); + | - borrow later used here error: aborting due to previous error +For more information about this error, try `rustc --explain E0502`. diff --git a/src/test/ui/error-codes/E0502.rs b/src/test/ui/error-codes/E0502.rs index 9c126bdcde84b..86d9c130d873d 100644 --- a/src/test/ui/error-codes/E0502.rs +++ b/src/test/ui/error-codes/E0502.rs @@ -7,12 +7,16 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_attrs)] + fn bar(x: &mut i32) {} fn foo(a: &mut i32) { let ref y = a; bar(a); //~ ERROR E0502 + y.use_ref(); } -fn main() { #![rustc_error] // rust-lang/rust#49855 +fn main() { } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/error-codes/E0502.stderr b/src/test/ui/error-codes/E0502.stderr index d377fa883dd83..8f0335c066268 100644 --- a/src/test/ui/error-codes/E0502.stderr +++ b/src/test/ui/error-codes/E0502.stderr @@ -5,6 +5,7 @@ LL | let ref y = a; | ----- immutable borrow occurs here LL | bar(a); //~ ERROR E0502 | ^ mutable borrow occurs here +LL | y.use_ref(); LL | } | - immutable borrow ends here diff --git a/src/test/ui/error-codes/E0503.nll.stderr b/src/test/ui/error-codes/E0503.nll.stderr index 6c5e99d876904..54e2bdacfa9b3 100644 --- a/src/test/ui/error-codes/E0503.nll.stderr +++ b/src/test/ui/error-codes/E0503.nll.stderr @@ -1,12 +1,13 @@ -error: compilation successful - --> $DIR/E0503.rs:11:1 +error[E0503]: cannot use `value` because it was mutably borrowed + --> $DIR/E0503.rs:14:16 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let mut value = 3; -LL | | let _borrow = &mut value; -LL | | let _sum = value + 1; //~ ERROR E0503 -LL | | } - | |_^ +LL | let _borrow = &mut value; + | ---------- borrow of `value` occurs here +LL | let _sum = value + 1; //~ ERROR E0503 + | ^^^^^ use of borrowed `value` +LL | _borrow.use_mut(); + | ------- borrow later used here error: aborting due to previous error +For more information about this error, try `rustc --explain E0503`. diff --git a/src/test/ui/error-codes/E0503.rs b/src/test/ui/error-codes/E0503.rs index 1822a8925d3cd..eacf510414575 100644 --- a/src/test/ui/error-codes/E0503.rs +++ b/src/test/ui/error-codes/E0503.rs @@ -7,9 +7,13 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_attrs)] -fn main() { #![rustc_error] // rust-lang/rust#49855 + +fn main() { let mut value = 3; let _borrow = &mut value; let _sum = value + 1; //~ ERROR E0503 + _borrow.use_mut(); } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/error-codes/E0505.nll.stderr b/src/test/ui/error-codes/E0505.nll.stderr index 556e0c73d1af6..94624cb96992b 100644 --- a/src/test/ui/error-codes/E0505.nll.stderr +++ b/src/test/ui/error-codes/E0505.nll.stderr @@ -1,14 +1,13 @@ -error: compilation successful - --> $DIR/E0505.rs:15:1 +error[E0505]: cannot move out of `x` because it is borrowed + --> $DIR/E0505.rs:19:13 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let x = Value{}; -LL | | { -LL | | let _ref_to_val: &Value = &x; -LL | | eat(x); //~ ERROR E0505 -LL | | } -LL | | } - | |_^ +LL | let _ref_to_val: &Value = &x; + | -- borrow of `x` occurs here +LL | eat(x); //~ ERROR E0505 + | ^ move out of `x` occurs here +LL | _ref_to_val.use_ref(); + | ----------- borrow later used here error: aborting due to previous error +For more information about this error, try `rustc --explain E0505`. diff --git a/src/test/ui/error-codes/E0505.rs b/src/test/ui/error-codes/E0505.rs index dd2980936c0b2..2ec4ac44b6ef6 100644 --- a/src/test/ui/error-codes/E0505.rs +++ b/src/test/ui/error-codes/E0505.rs @@ -7,15 +7,19 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_attrs)] + struct Value {} fn eat(val: Value) {} -fn main() { #![rustc_error] // rust-lang/rust#49855 +fn main() { let x = Value{}; { let _ref_to_val: &Value = &x; eat(x); //~ ERROR E0505 + _ref_to_val.use_ref(); } } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/error-codes/E0597.nll.stderr b/src/test/ui/error-codes/E0597.nll.stderr index 56119e4226e60..459de1bc00b0f 100644 --- a/src/test/ui/error-codes/E0597.nll.stderr +++ b/src/test/ui/error-codes/E0597.nll.stderr @@ -1,13 +1,15 @@ -error: compilation successful - --> $DIR/E0597.rs:15:1 +error[E0597]: `y` does not live long enough + --> $DIR/E0597.rs:18:16 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let mut x = Foo { x: None }; -LL | | let y = 0; -LL | | x.x = Some(&y); -LL | | //~^ `y` does not live long enough [E0597] -LL | | } - | |_^ +LL | x.x = Some(&y); + | ^^ borrowed value does not live long enough +LL | //~^ `y` does not live long enough [E0597] +LL | } + | - + | | + | borrowed value only lives until here + | borrow later used here, when `x` is dropped error: aborting due to previous error +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/error-codes/E0597.rs b/src/test/ui/error-codes/E0597.rs index 74178a6944404..e70213e19c34c 100644 --- a/src/test/ui/error-codes/E0597.rs +++ b/src/test/ui/error-codes/E0597.rs @@ -7,14 +7,16 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_attrs)] + struct Foo<'a> { x: Option<&'a u32>, } -fn main() { #![rustc_error] // rust-lang/rust#49855 +fn main() { let mut x = Foo { x: None }; let y = 0; x.x = Some(&y); //~^ `y` does not live long enough [E0597] } + +impl<'a> Drop for Foo<'a> { fn drop(&mut self) { } } diff --git a/src/test/ui/generator/dropck.nll.stderr b/src/test/ui/generator/dropck.nll.stderr index c352fd6a62f28..7b68c167d4acb 100644 --- a/src/test/ui/generator/dropck.nll.stderr +++ b/src/test/ui/generator/dropck.nll.stderr @@ -1,3 +1,15 @@ +error[E0597]: `*cell` does not live long enough + --> $DIR/dropck.rs:19:40 + | +LL | let ref_ = Box::leak(Box::new(Some(cell.borrow_mut()))); + | ^^^^ borrowed value does not live long enough +... +LL | } + | - + | | + | borrowed value only lives until here + | borrow later used here, when `gen` is dropped + error[E0597]: `ref_` does not live long enough --> $DIR/dropck.rs:22:11 | @@ -15,6 +27,6 @@ LL | } | borrowed value only lives until here | borrow later used here, when `gen` is dropped -error: aborting due to previous error +error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/generator/dropck.rs b/src/test/ui/generator/dropck.rs index 857288818c67c..992a31a732083 100644 --- a/src/test/ui/generator/dropck.rs +++ b/src/test/ui/generator/dropck.rs @@ -14,7 +14,7 @@ use std::cell::RefCell; use std::ops::Generator; fn main() { - let (cell, mut gen); + let (mut gen, cell); cell = Box::new(RefCell::new(0)); let ref_ = Box::leak(Box::new(Some(cell.borrow_mut()))); //~^ ERROR `*cell` does not live long enough [E0597] diff --git a/src/test/ui/generator/pattern-borrow.nll.stderr b/src/test/ui/generator/pattern-borrow.nll.stderr index ec8adf9d37c46..48f23486a317c 100644 --- a/src/test/ui/generator/pattern-borrow.nll.stderr +++ b/src/test/ui/generator/pattern-borrow.nll.stderr @@ -1,8 +1,11 @@ -error: compilation successful - --> $DIR/pattern-borrow.rs:15:1 +error[E0626]: borrow may still be in use when generator yields + --> $DIR/pattern-borrow.rs:19:24 | -LL | fn main() { #![rustc_error] } // rust-lang/rust#49855 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | if let Test::A(ref _a) = test { //~ ERROR borrow may still be in use when generator yields + | ^^^^^^ +LL | yield (); + | -------- possible yield occurs here error: aborting due to previous error +For more information about this error, try `rustc --explain E0626`. diff --git a/src/test/ui/generator/pattern-borrow.rs b/src/test/ui/generator/pattern-borrow.rs index dd63b9eaa5b1c..2c4c682d8cca9 100644 --- a/src/test/ui/generator/pattern-borrow.rs +++ b/src/test/ui/generator/pattern-borrow.rs @@ -8,16 +8,20 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(generators, rustc_attrs)] +#![feature(generators)] enum Test { A(i32), B, } -fn main() { #![rustc_error] } // rust-lang/rust#49855 +fn main() { } fn fun(test: Test) { move || { if let Test::A(ref _a) = test { //~ ERROR borrow may still be in use when generator yields yield (); + _a.use_ref(); } }; } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/hygiene/fields-numeric-borrowck.nll.stderr b/src/test/ui/hygiene/fields-numeric-borrowck.nll.stderr index 3a0a6f66d61c3..56dfee1fe33c1 100644 --- a/src/test/ui/hygiene/fields-numeric-borrowck.nll.stderr +++ b/src/test/ui/hygiene/fields-numeric-borrowck.nll.stderr @@ -1,13 +1,14 @@ -error: compilation successful - --> $DIR/fields-numeric-borrowck.rs:13:1 +error[E0499]: cannot borrow `s.0` as mutable more than once at a time + --> $DIR/fields-numeric-borrowck.rs:16:16 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let mut s = S(0); -LL | | let borrow1 = &mut s.0; -LL | | let S { 0: ref mut borrow2 } = s; -LL | | //~^ ERROR cannot borrow `s.0` as mutable more than once at a time -LL | | } - | |_^ +LL | let borrow1 = &mut s.0; + | -------- first mutable borrow occurs here +LL | let S { 0: ref mut borrow2 } = s; + | ^^^^^^^^^^^^^^^ second mutable borrow occurs here +... +LL | borrow1.use_mut(); + | ------- borrow later used here error: aborting due to previous error +For more information about this error, try `rustc --explain E0499`. diff --git a/src/test/ui/hygiene/fields-numeric-borrowck.rs b/src/test/ui/hygiene/fields-numeric-borrowck.rs index 975684fbd41bb..7e14c811a30a1 100644 --- a/src/test/ui/hygiene/fields-numeric-borrowck.rs +++ b/src/test/ui/hygiene/fields-numeric-borrowck.rs @@ -7,12 +7,17 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_attrs)] + struct S(u8); -fn main() { #![rustc_error] // rust-lang/rust#49855 +fn main() { let mut s = S(0); let borrow1 = &mut s.0; let S { 0: ref mut borrow2 } = s; //~^ ERROR cannot borrow `s.0` as mutable more than once at a time + borrow2.use_mut(); + borrow1.use_mut(); } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/hygiene/fields-numeric-borrowck.stderr b/src/test/ui/hygiene/fields-numeric-borrowck.stderr index ccd898fff27b7..d0156cfa671b5 100644 --- a/src/test/ui/hygiene/fields-numeric-borrowck.stderr +++ b/src/test/ui/hygiene/fields-numeric-borrowck.stderr @@ -5,7 +5,7 @@ LL | let borrow1 = &mut s.0; | --- first mutable borrow occurs here LL | let S { 0: ref mut borrow2 } = s; | ^^^^^^^^^^^^^^^ second mutable borrow occurs here -LL | //~^ ERROR cannot borrow `s.0` as mutable more than once at a time +... LL | } | - first borrow ends here diff --git a/src/test/ui/issue-25793.nll.stderr b/src/test/ui/issue-25793.nll.stderr index 05ba186c6bb6a..bd48d0eeb7c42 100644 --- a/src/test/ui/issue-25793.nll.stderr +++ b/src/test/ui/issue-25793.nll.stderr @@ -1,8 +1,17 @@ -error: compilation successful - --> $DIR/issue-25793.rs:32:1 +error[E0503]: cannot use `self.width` because it was mutably borrowed + --> $DIR/issue-25793.rs:13:9 | -LL | fn main() { #![rustc_error] } // rust-lang/rust#49855 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | $this.width.unwrap() + | ^^^^^^^^^^^ use of borrowed `*self` +... +LL | let r = &mut *self; + | ---------- borrow of `*self` occurs here +LL | r.get_size(width!(self)) + | ------------------------ + | | | + | | in this macro invocation + | borrow later used here error: aborting due to previous error +For more information about this error, try `rustc --explain E0503`. diff --git a/src/test/ui/issue-25793.rs b/src/test/ui/issue-25793.rs index 8624527145c2a..2939646342aac 100644 --- a/src/test/ui/issue-25793.rs +++ b/src/test/ui/issue-25793.rs @@ -25,8 +25,11 @@ impl HasInfo { } fn get_other(&mut self) -> usize { - self.get_size(width!(self)) + let r = &mut *self; + r.get_size(width!(self)) } + // Above is like `self.get_size(width!(self))`, but it + // deliberately avoids NLL's two phase borrow feature. } -fn main() { #![rustc_error] } // rust-lang/rust#49855 +fn main() { } diff --git a/src/test/ui/issue-25793.stderr b/src/test/ui/issue-25793.stderr index 926a744f69e86..fb83d767c5069 100644 --- a/src/test/ui/issue-25793.stderr +++ b/src/test/ui/issue-25793.stderr @@ -4,10 +4,10 @@ error[E0503]: cannot use `self.width` because it was mutably borrowed LL | $this.width.unwrap() | ^^^^^^^^^^^ use of borrowed `*self` ... -LL | self.get_size(width!(self)) - | ---- ------------ in this macro invocation - | | - | borrow of `*self` occurs here +LL | let r = &mut *self; + | ----- borrow of `*self` occurs here +LL | r.get_size(width!(self)) + | ------------ in this macro invocation error: aborting due to previous error diff --git a/src/test/ui/issue-42106.nll.stderr b/src/test/ui/issue-42106.nll.stderr index cae04aaedfdf3..39e3c218f4089 100644 --- a/src/test/ui/issue-42106.nll.stderr +++ b/src/test/ui/issue-42106.nll.stderr @@ -1,8 +1,13 @@ -error: compilation successful - --> $DIR/issue-42106.rs:16:1 +error[E0502]: cannot borrow `*collection` as mutable because it is also borrowed as immutable + --> $DIR/issue-42106.rs:13:5 | -LL | fn main() { #![rustc_error] } // rust-lang/rust#49855 - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | let _a = &collection; + | ----------- immutable borrow occurs here +LL | collection.swap(1, 2); //~ ERROR also borrowed as immutable + | ^^^^^^^^^^ mutable borrow occurs here +LL | _a.use_ref(); + | -- borrow later used here error: aborting due to previous error +For more information about this error, try `rustc --explain E0502`. diff --git a/src/test/ui/issue-42106.rs b/src/test/ui/issue-42106.rs index 96f410578ce5a..b177a14af333c 100644 --- a/src/test/ui/issue-42106.rs +++ b/src/test/ui/issue-42106.rs @@ -7,10 +7,14 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_attrs)] + fn do_something(collection: &mut Vec) { let _a = &collection; collection.swap(1, 2); //~ ERROR also borrowed as immutable + _a.use_ref(); } -fn main() { #![rustc_error] } // rust-lang/rust#49855 +fn main() { } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/issue-42106.stderr b/src/test/ui/issue-42106.stderr index b8944bb242390..d77ff315ce7fc 100644 --- a/src/test/ui/issue-42106.stderr +++ b/src/test/ui/issue-42106.stderr @@ -5,6 +5,7 @@ LL | let _a = &collection; | ---------- immutable borrow occurs here LL | collection.swap(1, 2); //~ ERROR also borrowed as immutable | ^^^^^^^^^^ mutable borrow occurs here +LL | _a.use_ref(); LL | } | - immutable borrow ends here diff --git a/src/test/ui/lifetime-errors/ex3-both-anon-regions-2.nll.stderr b/src/test/ui/lifetime-errors/ex3-both-anon-regions-2.nll.stderr index 871a0b109b4aa..da171577e2d8b 100644 --- a/src/test/ui/lifetime-errors/ex3-both-anon-regions-2.nll.stderr +++ b/src/test/ui/lifetime-errors/ex3-both-anon-regions-2.nll.stderr @@ -1,17 +1,17 @@ warning: not reporting region error due to nll - --> $DIR/ex3-both-anon-regions-2.rs:12:9 + --> $DIR/ex3-both-anon-regions-2.rs:12:10 | -LL | v = x; //~ ERROR lifetime mismatch - | ^ +LL | *v = x; //~ ERROR lifetime mismatch + | ^ -error[E0384]: cannot assign twice to immutable variable `v` - --> $DIR/ex3-both-anon-regions-2.rs:12:5 +error[E0623]: lifetime mismatch + --> $DIR/ex3-both-anon-regions-2.rs:11:14 | -LL | fn foo((v, w): (&u8, &u8), x: &u8) { - | - first assignment to `v` -LL | v = x; //~ ERROR lifetime mismatch - | ^^^^^ cannot assign twice to immutable variable +LL | fn foo(&mut (ref mut v, w): &mut (&u8, &u8), x: &u8) { + | ^^^^^^^^^ --- --- these two types are declared with different lifetimes... + | | + | ...but data from `x` flows here error: aborting due to previous error -For more information about this error, try `rustc --explain E0384`. +For more information about this error, try `rustc --explain E0623`. diff --git a/src/test/ui/lifetime-errors/ex3-both-anon-regions-2.rs b/src/test/ui/lifetime-errors/ex3-both-anon-regions-2.rs index 5d490824d02f9..62d7d56f9f703 100644 --- a/src/test/ui/lifetime-errors/ex3-both-anon-regions-2.rs +++ b/src/test/ui/lifetime-errors/ex3-both-anon-regions-2.rs @@ -8,8 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -fn foo((v, w): (&u8, &u8), x: &u8) { - v = x; //~ ERROR lifetime mismatch +fn foo(&mut (ref mut v, w): &mut (&u8, &u8), x: &u8) { + *v = x; //~ ERROR lifetime mismatch } fn main() { } diff --git a/src/test/ui/lifetime-errors/ex3-both-anon-regions-2.stderr b/src/test/ui/lifetime-errors/ex3-both-anon-regions-2.stderr index f3716c307035e..5e110b43fb4a8 100644 --- a/src/test/ui/lifetime-errors/ex3-both-anon-regions-2.stderr +++ b/src/test/ui/lifetime-errors/ex3-both-anon-regions-2.stderr @@ -1,10 +1,10 @@ error[E0623]: lifetime mismatch - --> $DIR/ex3-both-anon-regions-2.rs:12:9 + --> $DIR/ex3-both-anon-regions-2.rs:12:10 | -LL | fn foo((v, w): (&u8, &u8), x: &u8) { - | --- --- these two types are declared with different lifetimes... -LL | v = x; //~ ERROR lifetime mismatch - | ^ ...but data from `x` flows here +LL | fn foo(&mut (ref mut v, w): &mut (&u8, &u8), x: &u8) { + | --- --- these two types are declared with different lifetimes... +LL | *v = x; //~ ERROR lifetime mismatch + | ^ ...but data from `x` flows here error: aborting due to previous error diff --git a/src/test/ui/lifetimes/borrowck-let-suggestion.nll.stderr b/src/test/ui/lifetimes/borrowck-let-suggestion.nll.stderr index d13f9ccc37da2..7b7302ae58214 100644 --- a/src/test/ui/lifetimes/borrowck-let-suggestion.nll.stderr +++ b/src/test/ui/lifetimes/borrowck-let-suggestion.nll.stderr @@ -1,10 +1,15 @@ -error: compilation successful - --> $DIR/borrowck-let-suggestion.rs:15:1 +error[E0597]: borrowed value does not live long enough + --> $DIR/borrowck-let-suggestion.rs:12:17 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | f(); -LL | | } - | |_^ +LL | let mut x = vec![1].iter(); + | ^^^^^^^ - temporary value only lives until here + | | + | temporary value does not live long enough +LL | x.use_mut(); + | - borrow later used here + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to previous error +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/lifetimes/borrowck-let-suggestion.rs b/src/test/ui/lifetimes/borrowck-let-suggestion.rs index a7a7d5c503518..51a2a1fc88353 100644 --- a/src/test/ui/lifetimes/borrowck-let-suggestion.rs +++ b/src/test/ui/lifetimes/borrowck-let-suggestion.rs @@ -7,11 +7,15 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_attrs)] + fn f() { - let x = vec![1].iter(); + let mut x = vec![1].iter(); + x.use_mut(); } -fn main() { #![rustc_error] // rust-lang/rust#49855 +fn main() { f(); } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/lifetimes/borrowck-let-suggestion.stderr b/src/test/ui/lifetimes/borrowck-let-suggestion.stderr index c78b09a86a49d..32fdb9df96f25 100644 --- a/src/test/ui/lifetimes/borrowck-let-suggestion.stderr +++ b/src/test/ui/lifetimes/borrowck-let-suggestion.stderr @@ -1,10 +1,11 @@ error[E0597]: borrowed value does not live long enough - --> $DIR/borrowck-let-suggestion.rs:12:13 + --> $DIR/borrowck-let-suggestion.rs:12:17 | -LL | let x = vec![1].iter(); - | ^^^^^^^ - temporary value dropped here while still borrowed - | | - | temporary value does not live long enough +LL | let mut x = vec![1].iter(); + | ^^^^^^^ - temporary value dropped here while still borrowed + | | + | temporary value does not live long enough +LL | x.use_mut(); LL | } | - temporary value needs to live until here | diff --git a/src/test/ui/span/borrowck-let-suggestion-suffixes.nll.stderr b/src/test/ui/span/borrowck-let-suggestion-suffixes.nll.stderr index d02f70ea292f2..79cfee2d01fd5 100644 --- a/src/test/ui/span/borrowck-let-suggestion-suffixes.nll.stderr +++ b/src/test/ui/span/borrowck-let-suggestion-suffixes.nll.stderr @@ -1,10 +1,36 @@ -error: compilation successful - --> $DIR/borrowck-let-suggestion-suffixes.rs:61:1 +error[E0597]: borrowed value does not live long enough + --> $DIR/borrowck-let-suggestion-suffixes.rs:28:14 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | f(); -LL | | } - | |_^ +LL | v3.push(&id('x')); // statement 6 + | ^^^^^^^ - temporary value only lives until here + | | + | temporary value does not live long enough +... +LL | (v1, v2, v3, /* v4 is above. */ v5).use_ref(); + | -- borrow later used here -error: aborting due to previous error +error[E0597]: borrowed value does not live long enough + --> $DIR/borrowck-let-suggestion-suffixes.rs:38:18 + | +LL | v4.push(&id('y')); + | ^^^^^^^ - temporary value only lives until here + | | + | temporary value does not live long enough +... +LL | v4.use_ref(); + | -- borrow later used here + +error[E0597]: borrowed value does not live long enough + --> $DIR/borrowck-let-suggestion-suffixes.rs:49:14 + | +LL | v5.push(&id('z')); + | ^^^^^^^ - temporary value only lives until here + | | + | temporary value does not live long enough +... +LL | (v1, v2, v3, /* v4 is above. */ v5).use_ref(); + | -- borrow later used here + +error: aborting due to 3 previous errors +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/span/borrowck-let-suggestion-suffixes.rs b/src/test/ui/span/borrowck-let-suggestion-suffixes.rs index 60e6c6e298938..b19a0b4c2c233 100644 --- a/src/test/ui/span/borrowck-let-suggestion-suffixes.rs +++ b/src/test/ui/span/borrowck-let-suggestion-suffixes.rs @@ -40,7 +40,7 @@ fn f() { //~| NOTE temporary value does not live long enough //~| NOTE temporary value dropped here while still borrowed //~| NOTE consider using a `let` binding to increase its lifetime - + v4.use_ref(); } // (statement 7) //~^ NOTE temporary value needs to live until here @@ -53,6 +53,8 @@ fn f() { //~| NOTE consider using a `let` binding to increase its lifetime v1.push(&old[0]); + + (v1, v2, v3, /* v4 is above. */ v5).use_ref(); } //~^ NOTE `young[..]` dropped here while still borrowed //~| NOTE temporary value needs to live until here @@ -61,3 +63,6 @@ fn f() { fn main() { #![rustc_error] // rust-lang/rust#49855 f(); } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/span/issue-36537.nll.stderr b/src/test/ui/span/issue-36537.nll.stderr index 5802bac04b1c7..a3b8a3e766bbf 100644 --- a/src/test/ui/span/issue-36537.nll.stderr +++ b/src/test/ui/span/issue-36537.nll.stderr @@ -1,13 +1,14 @@ -error: compilation successful - --> $DIR/issue-36537.rs:11:1 +error[E0597]: `a` does not live long enough + --> $DIR/issue-36537.rs:15:9 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let p; -LL | | let a = 42; -LL | | p = &a; -LL | | //~^ ERROR `a` does not live long enough -LL | | } - | |_^ +LL | p = &a; + | ^^^^^^ borrowed value does not live long enough +... +LL | } + | - borrowed value only lives until here +LL | p.use_ref(); + | - borrow later used here error: aborting due to previous error +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/span/issue-36537.rs b/src/test/ui/span/issue-36537.rs index ca04101cf568a..6f1647c9ebb26 100644 --- a/src/test/ui/span/issue-36537.rs +++ b/src/test/ui/span/issue-36537.rs @@ -7,10 +7,18 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_attrs)] -fn main() { #![rustc_error] // rust-lang/rust#49855 + +fn main() { let p; - let a = 42; - p = &a; - //~^ ERROR `a` does not live long enough + { + let a = 42; + p = &a; + //~^ ERROR `a` does not live long enough + + } + p.use_ref(); + } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/span/issue-36537.stderr b/src/test/ui/span/issue-36537.stderr index 73a0cf63c949e..c090ae6318d3e 100644 --- a/src/test/ui/span/issue-36537.stderr +++ b/src/test/ui/span/issue-36537.stderr @@ -1,13 +1,14 @@ error[E0597]: `a` does not live long enough - --> $DIR/issue-36537.rs:14:10 + --> $DIR/issue-36537.rs:15:14 | -LL | p = &a; - | ^ borrowed value does not live long enough -LL | //~^ ERROR `a` does not live long enough +LL | p = &a; + | ^ borrowed value does not live long enough +... +LL | } + | - `a` dropped here while still borrowed +... LL | } - | - `a` dropped here while still borrowed - | - = note: values in a scope are dropped in the opposite order they are created + | - borrowed value needs to live until here error: aborting due to previous error diff --git a/src/test/ui/span/mut-ptr-cant-outlive-ref.nll.stderr b/src/test/ui/span/mut-ptr-cant-outlive-ref.nll.stderr index 3cad23a3c03af..a99ff9e272619 100644 --- a/src/test/ui/span/mut-ptr-cant-outlive-ref.nll.stderr +++ b/src/test/ui/span/mut-ptr-cant-outlive-ref.nll.stderr @@ -1,14 +1,14 @@ -error: compilation successful - --> $DIR/mut-ptr-cant-outlive-ref.rs:13:1 +error[E0597]: `b` does not live long enough + --> $DIR/mut-ptr-cant-outlive-ref.rs:18:15 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let m = RefCell::new(0); -LL | | let p; -LL | | { -... | -LL | | //~^^ ERROR `b` does not live long enough -LL | | } - | |_^ +LL | p = &*b; + | ^ borrowed value does not live long enough +LL | } + | - borrowed value only lives until here +LL | //~^^ ERROR `b` does not live long enough +LL | p.use_ref(); + | - borrow later used here error: aborting due to previous error +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/span/mut-ptr-cant-outlive-ref.rs b/src/test/ui/span/mut-ptr-cant-outlive-ref.rs index 9774303197c59..6cd2cf1e6734d 100644 --- a/src/test/ui/span/mut-ptr-cant-outlive-ref.rs +++ b/src/test/ui/span/mut-ptr-cant-outlive-ref.rs @@ -7,10 +7,10 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_attrs)] + use std::cell::RefCell; -fn main() { #![rustc_error] // rust-lang/rust#49855 +fn main() { let m = RefCell::new(0); let p; { @@ -18,4 +18,8 @@ fn main() { #![rustc_error] // rust-lang/rust#49855 p = &*b; } //~^^ ERROR `b` does not live long enough + p.use_ref(); } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/span/mut-ptr-cant-outlive-ref.stderr b/src/test/ui/span/mut-ptr-cant-outlive-ref.stderr index 7898b066acd49..34fcc9ef96292 100644 --- a/src/test/ui/span/mut-ptr-cant-outlive-ref.stderr +++ b/src/test/ui/span/mut-ptr-cant-outlive-ref.stderr @@ -5,7 +5,7 @@ LL | p = &*b; | ^ borrowed value does not live long enough LL | } | - `b` dropped here while still borrowed -LL | //~^^ ERROR `b` does not live long enough +... LL | } | - borrowed value needs to live until here diff --git a/src/test/ui/span/range-2.nll.stderr b/src/test/ui/span/range-2.nll.stderr index afb319b57d421..aff1fededbb3c 100644 --- a/src/test/ui/span/range-2.nll.stderr +++ b/src/test/ui/span/range-2.nll.stderr @@ -1,14 +1,25 @@ -error: compilation successful - --> $DIR/range-2.rs:13:1 +error[E0597]: `b` does not live long enough + --> $DIR/range-2.rs:17:13 | -LL | / pub fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let r = { -LL | | let a = 42; -LL | | let b = 42; -... | -LL | | //~| ERROR `b` does not live long enough -LL | | } - | |_^ +LL | &a..&b + | ^^ borrowed value does not live long enough +LL | }; + | - borrowed value only lives until here +... +LL | r.use_ref(); + | - borrow later used here -error: aborting due to previous error +error[E0597]: `a` does not live long enough + --> $DIR/range-2.rs:17:9 + | +LL | &a..&b + | ^^ borrowed value does not live long enough +LL | }; + | - borrowed value only lives until here +... +LL | r.use_ref(); + | - borrow later used here + +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/span/range-2.rs b/src/test/ui/span/range-2.rs index a1ed9bc6aa84b..6d2cd85fb666c 100644 --- a/src/test/ui/span/range-2.rs +++ b/src/test/ui/span/range-2.rs @@ -18,4 +18,8 @@ pub fn main() { #![rustc_error] // rust-lang/rust#49855 }; //~^^ ERROR `a` does not live long enough //~| ERROR `b` does not live long enough + r.use_ref(); } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/span/regionck-unboxed-closure-lifetimes.nll.stderr b/src/test/ui/span/regionck-unboxed-closure-lifetimes.nll.stderr index 3c918fdb1472a..71e02af1f845f 100644 --- a/src/test/ui/span/regionck-unboxed-closure-lifetimes.nll.stderr +++ b/src/test/ui/span/regionck-unboxed-closure-lifetimes.nll.stderr @@ -1,14 +1,14 @@ -error: compilation successful - --> $DIR/regionck-unboxed-closure-lifetimes.rs:13:1 +error[E0597]: `c` does not live long enough + --> $DIR/regionck-unboxed-closure-lifetimes.rs:17:21 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let mut f; -LL | | { -LL | | let c = 1; -... | -LL | | } -LL | | } - | |_^ +LL | let c_ref = &c; + | ^^ borrowed value does not live long enough +... +LL | } + | - borrowed value only lives until here +LL | f.use_mut(); + | - borrow later used here error: aborting due to previous error +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/span/regionck-unboxed-closure-lifetimes.rs b/src/test/ui/span/regionck-unboxed-closure-lifetimes.rs index c814941c81124..7595f03fd31d9 100644 --- a/src/test/ui/span/regionck-unboxed-closure-lifetimes.rs +++ b/src/test/ui/span/regionck-unboxed-closure-lifetimes.rs @@ -18,4 +18,8 @@ fn main() { #![rustc_error] // rust-lang/rust#49855 //~^ ERROR `c` does not live long enough f = move |a: isize, b: isize| { a + b + *c_ref }; } + f.use_mut(); } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/span/regionck-unboxed-closure-lifetimes.stderr b/src/test/ui/span/regionck-unboxed-closure-lifetimes.stderr index db47a9010e09d..8a1bb4a45e1b6 100644 --- a/src/test/ui/span/regionck-unboxed-closure-lifetimes.stderr +++ b/src/test/ui/span/regionck-unboxed-closure-lifetimes.stderr @@ -6,6 +6,7 @@ LL | let c_ref = &c; ... LL | } | - `c` dropped here while still borrowed +LL | f.use_mut(); LL | } | - borrowed value needs to live until here diff --git a/src/test/ui/span/send-is-not-static-std-sync.nll.stderr b/src/test/ui/span/send-is-not-static-std-sync.nll.stderr index 211433061104b..d411f0d26f4fb 100644 --- a/src/test/ui/span/send-is-not-static-std-sync.nll.stderr +++ b/src/test/ui/span/send-is-not-static-std-sync.nll.stderr @@ -9,8 +9,19 @@ LL | drop(y); //~ ERROR cannot move out LL | *lock.lock().unwrap() = &z; | ---- borrow later used here +error[E0597]: `z` does not live long enough + --> $DIR/send-is-not-static-std-sync.rs:26:33 + | +LL | *lock.lock().unwrap() = &z; + | ^^ borrowed value does not live long enough +LL | } + | - borrowed value only lives until here +LL | //~^^ ERROR `z` does not live long enough +LL | lock.use_ref(); // (Mutex is #[may_dangle] so its dtor does not use `z` => needs explicit use) + | ---- borrow later used here + error[E0505]: cannot move out of `y` because it is borrowed - --> $DIR/send-is-not-static-std-sync.rs:36:10 + --> $DIR/send-is-not-static-std-sync.rs:37:10 | LL | *lock.write().unwrap() = &*y; | --- borrow of `*y` occurs here @@ -20,8 +31,19 @@ LL | drop(y); //~ ERROR cannot move out LL | *lock.write().unwrap() = &z; | ---- borrow later used here +error[E0597]: `z` does not live long enough + --> $DIR/send-is-not-static-std-sync.rs:40:34 + | +LL | *lock.write().unwrap() = &z; + | ^^ borrowed value does not live long enough +LL | } + | - borrowed value only lives until here +LL | //~^^ ERROR `z` does not live long enough +LL | lock.use_ref(); // (RwLock is #[may_dangle] so its dtor does not use `z` => needs explicit use) + | ---- borrow later used here + error[E0505]: cannot move out of `y` because it is borrowed - --> $DIR/send-is-not-static-std-sync.rs:51:10 + --> $DIR/send-is-not-static-std-sync.rs:53:10 | LL | tx.send(&*y); | --- borrow of `*y` occurs here @@ -32,17 +54,17 @@ LL | tx.send(&z).unwrap(); | -- borrow later used here error[E0597]: `z` does not live long enough - --> $DIR/send-is-not-static-std-sync.rs:54:17 + --> $DIR/send-is-not-static-std-sync.rs:56:17 | LL | tx.send(&z).unwrap(); | ^^ borrowed value does not live long enough LL | } | - borrowed value only lives until here -LL | //~^^ ERROR `z` does not live long enough +... LL | } | - borrow later used here, when `tx` is dropped -error: aborting due to 4 previous errors +error: aborting due to 6 previous errors Some errors occurred: E0505, E0597. For more information about an error, try `rustc --explain E0505`. diff --git a/src/test/ui/span/send-is-not-static-std-sync.rs b/src/test/ui/span/send-is-not-static-std-sync.rs index 4cf36e00a6fe8..08718ffc864b8 100644 --- a/src/test/ui/span/send-is-not-static-std-sync.rs +++ b/src/test/ui/span/send-is-not-static-std-sync.rs @@ -26,6 +26,7 @@ fn mutex() { *lock.lock().unwrap() = &z; } //~^^ ERROR `z` does not live long enough + lock.use_ref(); // (Mutex is #[may_dangle] so its dtor does not use `z` => needs explicit use) } fn rwlock() { @@ -39,6 +40,7 @@ fn rwlock() { *lock.write().unwrap() = &z; } //~^^ ERROR `z` does not live long enough + lock.use_ref(); // (RwLock is #[may_dangle] so its dtor does not use `z` => needs explicit use) } fn channel() { @@ -54,6 +56,10 @@ fn channel() { tx.send(&z).unwrap(); } //~^^ ERROR `z` does not live long enough + // (channels lack #[may_dangle], thus their dtors are implicit uses of `z`) } fn main() {} + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/span/send-is-not-static-std-sync.stderr b/src/test/ui/span/send-is-not-static-std-sync.stderr index 066715cd5b5f6..efcd1312da8e9 100644 --- a/src/test/ui/span/send-is-not-static-std-sync.stderr +++ b/src/test/ui/span/send-is-not-static-std-sync.stderr @@ -5,7 +5,7 @@ LL | *lock.lock().unwrap() = &z; | ^ borrowed value does not live long enough LL | } | - `z` dropped here while still borrowed -LL | //~^^ ERROR `z` does not live long enough +... LL | } | - borrowed value needs to live until here @@ -18,18 +18,18 @@ LL | drop(y); //~ ERROR cannot move out | ^ move out of `y` occurs here error[E0597]: `z` does not live long enough - --> $DIR/send-is-not-static-std-sync.rs:39:35 + --> $DIR/send-is-not-static-std-sync.rs:40:35 | LL | *lock.write().unwrap() = &z; | ^ borrowed value does not live long enough LL | } | - `z` dropped here while still borrowed -LL | //~^^ ERROR `z` does not live long enough +... LL | } | - borrowed value needs to live until here error[E0505]: cannot move out of `y` because it is borrowed - --> $DIR/send-is-not-static-std-sync.rs:36:10 + --> $DIR/send-is-not-static-std-sync.rs:37:10 | LL | *lock.write().unwrap() = &*y; | -- borrow of `*y` occurs here @@ -37,18 +37,18 @@ LL | drop(y); //~ ERROR cannot move out | ^ move out of `y` occurs here error[E0597]: `z` does not live long enough - --> $DIR/send-is-not-static-std-sync.rs:54:18 + --> $DIR/send-is-not-static-std-sync.rs:56:18 | LL | tx.send(&z).unwrap(); | ^ borrowed value does not live long enough LL | } | - `z` dropped here while still borrowed -LL | //~^^ ERROR `z` does not live long enough +... LL | } | - borrowed value needs to live until here error[E0505]: cannot move out of `y` because it is borrowed - --> $DIR/send-is-not-static-std-sync.rs:51:10 + --> $DIR/send-is-not-static-std-sync.rs:53:10 | LL | tx.send(&*y); | -- borrow of `*y` occurs here diff --git a/src/test/ui/span/slice-borrow.nll.stderr b/src/test/ui/span/slice-borrow.nll.stderr index 52ca125f8b62e..35838184e3399 100644 --- a/src/test/ui/span/slice-borrow.nll.stderr +++ b/src/test/ui/span/slice-borrow.nll.stderr @@ -1,14 +1,16 @@ -error: compilation successful - --> $DIR/slice-borrow.rs:13:1 +error[E0597]: borrowed value does not live long enough + --> $DIR/slice-borrow.rs:16:28 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let y; -LL | | { -LL | | let x: &[isize] = &vec![1, 2, 3, 4, 5]; -LL | | y = &x[1..]; -LL | | } -LL | | } - | |_^ +LL | let x: &[isize] = &vec![1, 2, 3, 4, 5]; + | ^^^^^^^^^^^^^^^^^^^ temporary value does not live long enough +LL | y = &x[1..]; +LL | } + | - temporary value only lives until here +LL | y.use_ref(); + | - borrow later used here + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) error: aborting due to previous error +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/span/slice-borrow.rs b/src/test/ui/span/slice-borrow.rs index 45dff62672bef..2d9b49d89b806 100644 --- a/src/test/ui/span/slice-borrow.rs +++ b/src/test/ui/span/slice-borrow.rs @@ -7,13 +7,17 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -#![feature(rustc_attrs)] + // Test slicing expressions doesn't defeat the borrow checker. -fn main() { #![rustc_error] // rust-lang/rust#49855 +fn main() { let y; { let x: &[isize] = &vec![1, 2, 3, 4, 5]; y = &x[1..]; } + y.use_ref(); } + +trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { } } +impl Fake for T { } diff --git a/src/test/ui/span/slice-borrow.stderr b/src/test/ui/span/slice-borrow.stderr index 503d1f72c3544..cb17064889168 100644 --- a/src/test/ui/span/slice-borrow.stderr +++ b/src/test/ui/span/slice-borrow.stderr @@ -6,6 +6,7 @@ LL | let x: &[isize] = &vec![1, 2, 3, 4, 5]; LL | y = &x[1..]; LL | } | - temporary value dropped here while still borrowed +LL | y.use_ref(); LL | } | - temporary value needs to live until here | diff --git a/src/test/ui/span/vec_refs_data_with_early_death.nll.stderr b/src/test/ui/span/vec_refs_data_with_early_death.nll.stderr index 09ecc666cbc01..6074199b89a15 100644 --- a/src/test/ui/span/vec_refs_data_with_early_death.nll.stderr +++ b/src/test/ui/span/vec_refs_data_with_early_death.nll.stderr @@ -1,14 +1,27 @@ -error: compilation successful - --> $DIR/vec_refs_data_with_early_death.rs:21:1 +error[E0597]: `y` does not live long enough + --> $DIR/vec_refs_data_with_early_death.rs:29:12 | -LL | / fn main() { #![rustc_error] // rust-lang/rust#49855 -LL | | let mut v = Vec::new(); -LL | | -LL | | let x: i8 = 3; -... | -LL | | assert_eq!(v, [&3, &4]); -LL | | } - | |_^ +LL | v.push(&y); + | ^^ borrowed value does not live long enough +... +LL | } + | - + | | + | borrowed value only lives until here + | borrow later used here, when `v` is dropped -error: aborting due to previous error +error[E0597]: `x` does not live long enough + --> $DIR/vec_refs_data_with_early_death.rs:27:12 + | +LL | v.push(&x); + | ^^ borrowed value does not live long enough +... +LL | } + | - + | | + | borrowed value only lives until here + | borrow later used here, when `v` is dropped + +error: aborting due to 2 previous errors +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/span/vec_refs_data_with_early_death.rs b/src/test/ui/span/vec_refs_data_with_early_death.rs index a3532d919bc09..9febeaaee4675 100644 --- a/src/test/ui/span/vec_refs_data_with_early_death.rs +++ b/src/test/ui/span/vec_refs_data_with_early_death.rs @@ -9,17 +9,17 @@ // except according to those terms. // This test is a simple example of code that violates the dropck -// rules: it pushes `&x` and `&y` into `v`, but the referenced data -// will be dropped before the vector itself is. - -// (In principle we know that `Vec` does not reference the data it -// owns from within its drop code, apart from calling drop on each -// element it owns; thus, for data like this, it seems like we could -// loosen the restrictions here if we wanted. But it also is not -// clear whether such loosening is terribly important.) -#![feature(rustc_attrs)] -fn main() { #![rustc_error] // rust-lang/rust#49855 - let mut v = Vec::new(); +// rules: it pushes `&x` and `&y` into a bag (with dtor), but the +// referenced data will be dropped before the bag is. + + + + + + + +fn main() { + let mut v = Bag::new(); let x: i8 = 3; let y: i8 = 4; @@ -29,5 +29,15 @@ fn main() { #![rustc_error] // rust-lang/rust#49855 v.push(&y); //~^ ERROR `y` does not live long enough - assert_eq!(v, [&3, &4]); + assert_eq!(v.0, [&3, &4]); +} + +//`Vec` is #[may_dangle] w.r.t. `T`; putting a bag over its head +// forces borrowck to treat dropping the bag as a potential use. +struct Bag(Vec); +impl Drop for Bag { fn drop(&mut self) { } } + +impl Bag { + fn new() -> Self { Bag(Vec::new()) } + fn push(&mut self, t: T) { self.0.push(t); } }