diff --git a/RELEASES.md b/RELEASES.md index 26dd5a5c7f6..758de62a848 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,27 @@ +Version 1.26.1 (2018-05-29) +========================== + +Tools +----- + +- [RLS now works on Windows][50646] +- [Rustfmt stopped badly formatting text in some cases][rustfmt/2695] + +Compatibility Notes +-------- + +- [`fn main() -> impl Trait` no longer works for non-Termination + trait][50656] + This reverts an accidental stabilization. +- [`NaN > NaN` no longer returns true in const-fn contexts][50812] +- [Prohibit using turbofish for `impl Trait` in method arguments][50950] + +[50646]: https://github.com/rust-lang/rust/issues/50646 +[50656]: https://github.com/rust-lang/rust/pull/50656 +[50812]: https://github.com/rust-lang/rust/pull/50812 +[50950]: https://github.com/rust-lang/rust/issues/50950 +[rustfmt/2695]: https://github.com/rust-lang-nursery/rustfmt/issues/2695 + Version 1.26.0 (2018-05-10) ========================== diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 1655ffd5c61..9452d2332cf 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3843,10 +3843,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let ctxt = BreakableCtxt { // cannot use break with a value from a while loop coerce: None, - may_break: true, + may_break: false, // Will get updated if/when we find a `break`. }; - self.with_breakable_ctxt(expr.id, ctxt, || { + let (ctxt, ()) = self.with_breakable_ctxt(expr.id, ctxt, || { self.check_expr_has_type_or_error(&cond, tcx.types.bool); let cond_diverging = self.diverges.get(); self.check_block_no_value(&body); @@ -3855,6 +3855,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.diverges.set(cond_diverging); }); + if ctxt.may_break { + // No way to know whether it's diverging because + // of a `break` or an outer `break` or `return`. + self.diverges.set(Diverges::Maybe); + } + self.tcx.mk_nil() } hir::ExprLoop(ref body, _, source) => { @@ -3873,7 +3879,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let ctxt = BreakableCtxt { coerce, - may_break: false, // will get updated if/when we find a `break` + may_break: false, // Will get updated if/when we find a `break`. }; let (ctxt, ()) = self.with_breakable_ctxt(expr.id, ctxt, || { @@ -3882,7 +3888,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if ctxt.may_break { // No way to know whether it's diverging because - // of a `break` or an outer `break` or `return. + // of a `break` or an outer `break` or `return`. self.diverges.set(Diverges::Maybe); } 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 951907876b9..fa600f0559f 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 cdfee2e8a70..2bc65287982 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 648ee1dff78..1fe052cef71 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 dab769820a6..55f57e97ba4 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 edc877718ad..aba520bd864 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 80a3ba4493c..95e9fa19129 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/break-while-condition.rs b/src/test/ui/break-while-condition.rs new file mode 100644 index 00000000000..050b479d485 --- /dev/null +++ b/src/test/ui/break-while-condition.rs @@ -0,0 +1,39 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(never_type)] + +fn main() { + // The `if false` expressions are simply to + // make sure we don't avoid checking everything + // simply because a few expressions are unreachable. + + if false { + let _: ! = { //~ ERROR mismatched types + 'a: while break 'a {}; + }; + } + + if false { + let _: ! = { + while false { //~ ERROR mismatched types + break + } + }; + } + + if false { + let _: ! = { + while false { //~ ERROR mismatched types + return + } + }; + } +} diff --git a/src/test/ui/break-while-condition.stderr b/src/test/ui/break-while-condition.stderr new file mode 100644 index 00000000000..c8f06db9603 --- /dev/null +++ b/src/test/ui/break-while-condition.stderr @@ -0,0 +1,43 @@ +error[E0308]: mismatched types + --> $DIR/break-while-condition.rs:19:20 + | +LL | let _: ! = { //~ ERROR mismatched types + | ____________________^ +LL | | 'a: while break 'a {}; +LL | | }; + | |_________^ expected !, found () + | + = note: expected type `!` + found type `()` + +error[E0308]: mismatched types + --> $DIR/break-while-condition.rs:26:13 + | +LL | fn main() { + | - expected `()` because of default return type +... +LL | / while false { //~ ERROR mismatched types +LL | | break +LL | | } + | |_____________^ expected !, found () + | + = note: expected type `!` + found type `()` + +error[E0308]: mismatched types + --> $DIR/break-while-condition.rs:34:13 + | +LL | fn main() { + | - expected `()` because of default return type +... +LL | / while false { //~ ERROR mismatched types +LL | | return +LL | | } + | |_____________^ expected !, found () + | + = note: expected type `!` + found type `()` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/codemap_tests/issue-11715.nll.stderr b/src/test/ui/codemap_tests/issue-11715.nll.stderr index 952ccdb98da..c0eeb63447d 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 03c85fbfcd7..415aa368708 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 d9551d7918a..eb73c69c5dc 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 692f697e889..008ecfeabcb 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 e06b47a8d79..3e531d9fd60 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 668fbf9521b..35db46f4fae 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: aborting due to 4 previous errors +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 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 f50168fd586..233ff198af4 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 832eeacbec5..1806dc71424 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 1a35996a0ca..9984a7b9409 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: aborting due to 4 previous errors +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 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 8c55fdbc0b8..7b27ff01f92 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 cfa67837485..40d3ff050e2 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 4d291642022..7cdf645941d 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: aborting due to 4 previous errors +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 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 27a71df147e..89801693b76 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 c3997236934..9fb235eccdd 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 dcb477ab1cb..8f4fd445fc2 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 67a08661040..565f73616b9 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 9c126bdcde8..86d9c130d87 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 d377fa883dd..8f0335c0662 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 6c5e99d8769..54e2bdacfa9 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 1822a8925d3..eacf5104145 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 556e0c73d1a..94624cb9699 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 dd2980936c0..2ec4ac44b6e 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 56119e4226e..459de1bc00b 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 74178a69444..e70213e19c3 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 c352fd6a62f..7b68c167d4a 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 857288818c6..992a31a7320 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 ec8adf9d37c..48f23486a31 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 dd63b9eaa5b..2c4c682d8cc 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 3a0a6f66d61..56dfee1fe33 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 975684fbd41..7e14c811a30 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 ccd898fff27..d0156cfa671 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 05ba186c6bb..bd48d0eeb7c 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 8624527145c..2939646342a 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 926a744f69e..fb83d767c50 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 cae04aaedfd..39e3c218f40 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 96f410578ce..b177a14af33 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 b8944bb2423..d77ff315ce7 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 871a0b109b4..da171577e2d 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 5d490824d02..62d7d56f9f7 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 f3716c30703..5e110b43fb4 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 d13f9ccc37d..7b7302ae582 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 a7a7d5c5035..51a2a1fc883 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 c78b09a86a4..32fdb9df96f 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 d02f70ea292..79cfee2d01f 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 60e6c6e2989..b19a0b4c2c2 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 5802bac04b1..a3b8a3e766b 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 ca04101cf56..6f1647c9ebb 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 73a0cf63c94..c090ae6318d 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 3cad23a3c03..a99ff9e2726 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 9774303197c..6cd2cf1e673 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 7898b066acd..34fcc9ef962 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 afb319b57d4..aff1fededbb 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 a1ed9bc6aa8..6d2cd85fb66 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 3c918fdb147..71e02af1f84 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 c814941c811..7595f03fd31 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 db47a9010e0..8a1bb4a45e1 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 21143306110..d411f0d26f4 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 4cf36e00a6f..08718ffc864 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 066715cd5b5..efcd1312da8 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 52ca125f8b6..35838184e33 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 45dff62672b..2d9b49d89b8 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 503d1f72c35..cb170648891 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 09ecc666cbc..6074199b89a 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 a3532d919bc..9febeaaee46 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. +// rules: it pushes `&x` and `&y` into a bag (with dtor), but the +// referenced data will be dropped before the bag 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(); + + + + + + +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); } }