From e85277596e11f3c7d0361f2b66be7eb21ae5fce3 Mon Sep 17 00:00:00 2001 From: Mikhail Modin Date: Fri, 14 Oct 2016 18:55:45 +0300 Subject: [PATCH] improve "Doesn't live long enough" error --- src/librustc_borrowck/borrowck/mod.rs | 30 +++++++-- .../dropck_tarena_cycle_checked.rs | 4 +- .../dropck_tarena_unsound_drop.rs | 5 +- .../dropck-eyepatch-extern-crate.stderr | 24 +++---- .../ui/dropck/dropck-eyepatch-reorder.stderr | 24 +++---- src/test/ui/dropck/dropck-eyepatch.stderr | 24 +++---- .../span}/borrowck-let-suggestion-suffixes.rs | 8 +-- .../borrowck-let-suggestion-suffixes.stderr | 52 ++++++++++++++ .../span}/dropck-object-cycle.rs | 6 +- src/test/ui/span/dropck-object-cycle.stderr | 13 ++++ .../span}/dropck_arr_cycle_checked.rs | 18 +++-- .../ui/span/dropck_arr_cycle_checked.stderr | 67 +++++++++++++++++++ .../span}/dropck_direct_cycle_with_drop.rs | 6 +- .../span/dropck_direct_cycle_with_drop.stderr | 23 +++++++ .../span}/dropck_misc_variants.rs | 4 +- src/test/ui/span/dropck_misc_variants.stderr | 23 +++++++ .../span}/dropck_vec_cycle_checked.rs | 18 +++-- .../ui/span/dropck_vec_cycle_checked.stderr | 67 +++++++++++++++++++ ...e-23338-locals-die-before-temps-of-body.rs | 3 +- ...338-locals-die-before-temps-of-body.stderr | 22 ++++++ ...24805-dropck-child-has-items-via-parent.rs | 3 +- ...5-dropck-child-has-items-via-parent.stderr | 13 ++++ .../issue-24805-dropck-trait-has-items.rs | 9 ++- .../issue-24805-dropck-trait-has-items.stderr | 32 +++++++++ .../span}/issue-24895-copy-clone-dropck.rs | 4 +- .../span/issue-24895-copy-clone-dropck.stderr | 12 ++++ .../{compile-fail => ui/span}/issue-25199.rs | 6 +- src/test/ui/span/issue-25199.stderr | 23 +++++++ .../{compile-fail => ui/span}/issue-26656.rs | 2 +- src/test/ui/span/issue-26656.stderr | 12 ++++ .../{compile-fail => ui/span}/issue-29106.rs | 8 +-- src/test/ui/span/issue-29106.stderr | 22 ++++++ src/test/ui/span/issue-36537.rs | 18 +++++ src/test/ui/span/issue-36537.stderr | 12 ++++ .../span}/issue28498-reject-ex1.rs | 4 +- src/test/ui/span/issue28498-reject-ex1.stderr | 23 +++++++ .../span}/issue28498-reject-lifetime-param.rs | 4 +- .../issue28498-reject-lifetime-param.stderr | 24 +++++++ .../span}/issue28498-reject-passed-to-fn.rs | 4 +- .../issue28498-reject-passed-to-fn.stderr | 24 +++++++ .../span}/issue28498-reject-trait-bound.rs | 4 +- .../span/issue28498-reject-trait-bound.stderr | 24 +++++++ .../impl-trait => ui/span}/loan-extend.rs | 9 +-- src/test/ui/span/loan-extend.stderr | 13 ++++ .../vec-must-not-hide-type-from-dropck.rs | 6 +- .../vec-must-not-hide-type-from-dropck.stderr | 23 +++++++ .../span}/vec_refs_data_with_early_death.rs | 6 +- .../vec_refs_data_with_early_death.stderr | 24 +++++++ 48 files changed, 711 insertions(+), 98 deletions(-) rename src/test/{compile-fail/borrowck => ui/span}/borrowck-let-suggestion-suffixes.rs (89%) create mode 100644 src/test/ui/span/borrowck-let-suggestion-suffixes.stderr rename src/test/{compile-fail => ui/span}/dropck-object-cycle.rs (89%) create mode 100644 src/test/ui/span/dropck-object-cycle.stderr rename src/test/{compile-fail => ui/span}/dropck_arr_cycle_checked.rs (84%) create mode 100644 src/test/ui/span/dropck_arr_cycle_checked.stderr rename src/test/{compile-fail => ui/span}/dropck_direct_cycle_with_drop.rs (92%) create mode 100644 src/test/ui/span/dropck_direct_cycle_with_drop.stderr rename src/test/{compile-fail => ui/span}/dropck_misc_variants.rs (92%) create mode 100644 src/test/ui/span/dropck_misc_variants.stderr rename src/test/{compile-fail => ui/span}/dropck_vec_cycle_checked.rs (85%) create mode 100644 src/test/ui/span/dropck_vec_cycle_checked.stderr rename src/test/{compile-fail => ui/span}/issue-23338-locals-die-before-temps-of-body.rs (94%) create mode 100644 src/test/ui/span/issue-23338-locals-die-before-temps-of-body.stderr rename src/test/{compile-fail => ui/span}/issue-24805-dropck-child-has-items-via-parent.rs (95%) create mode 100644 src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.stderr rename src/test/{compile-fail => ui/span}/issue-24805-dropck-trait-has-items.rs (88%) create mode 100644 src/test/ui/span/issue-24805-dropck-trait-has-items.stderr rename src/test/{compile-fail => ui/span}/issue-24895-copy-clone-dropck.rs (93%) create mode 100644 src/test/ui/span/issue-24895-copy-clone-dropck.stderr rename src/test/{compile-fail => ui/span}/issue-25199.rs (93%) create mode 100644 src/test/ui/span/issue-25199.stderr rename src/test/{compile-fail => ui/span}/issue-26656.rs (96%) create mode 100644 src/test/ui/span/issue-26656.stderr rename src/test/{compile-fail => ui/span}/issue-29106.rs (83%) create mode 100644 src/test/ui/span/issue-29106.stderr create mode 100644 src/test/ui/span/issue-36537.rs create mode 100644 src/test/ui/span/issue-36537.stderr rename src/test/{compile-fail => ui/span}/issue28498-reject-ex1.rs (93%) create mode 100644 src/test/ui/span/issue28498-reject-ex1.stderr rename src/test/{compile-fail => ui/span}/issue28498-reject-lifetime-param.rs (92%) create mode 100644 src/test/ui/span/issue28498-reject-lifetime-param.stderr rename src/test/{compile-fail => ui/span}/issue28498-reject-passed-to-fn.rs (93%) create mode 100644 src/test/ui/span/issue28498-reject-passed-to-fn.stderr rename src/test/{compile-fail => ui/span}/issue28498-reject-trait-bound.rs (92%) create mode 100644 src/test/ui/span/issue28498-reject-trait-bound.stderr rename src/test/{compile-fail/impl-trait => ui/span}/loan-extend.rs (76%) create mode 100644 src/test/ui/span/loan-extend.stderr rename src/test/{compile-fail => ui/span}/vec-must-not-hide-type-from-dropck.rs (96%) create mode 100644 src/test/ui/span/vec-must-not-hide-type-from-dropck.stderr rename src/test/{compile-fail => ui/span}/vec_refs_data_with_early_death.rs (90%) create mode 100644 src/test/ui/span/vec_refs_data_with_early_death.stderr diff --git a/src/librustc_borrowck/borrowck/mod.rs b/src/librustc_borrowck/borrowck/mod.rs index 5d62629b648..89b12e76c3c 100644 --- a/src/librustc_borrowck/borrowck/mod.rs +++ b/src/librustc_borrowck/borrowck/mod.rs @@ -1024,13 +1024,14 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { } err_out_of_scope(super_scope, sub_scope, cause) => { - let (value_kind, value_msg) = match err.cmt.cat { + let (value_kind, value_msg, is_temporary) = match err.cmt.cat { mc::Categorization::Rvalue(_) => - ("temporary value", "temporary value created here"), + ("temporary value", "temporary value created here", true), _ => - ("borrowed value", "does not live long enough") + ("borrowed value", "does not live long enough", false) }; - match cause { + + let is_closure = match cause { euv::ClosureCapture(s) => { // The primary span starts out as the closure creation point. // Change the primary span here to highlight the use of the variable @@ -1041,21 +1042,36 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> { db.span = MultiSpan::from_span(s); db.span_label(primary, &format!("capture occurs here")); db.span_label(s, &value_msg); + true } - None => () + None => false } } _ => { db.span_label(error_span, &value_msg); + false } - } + }; let sub_span = self.region_end_span(sub_scope); let super_span = self.region_end_span(super_scope); match (sub_span, super_span) { (Some(s1), Some(s2)) if s1 == s2 => { - db.span_label(s1, &format!("{} dropped before borrower", value_kind)); + if !is_temporary && !is_closure { + db.span = MultiSpan::from_span(s1); + db.span_label(error_span, &format!("borrow occurs here")); + let msg = match opt_loan_path(&err.cmt) { + None => "borrowed value".to_string(), + Some(lp) => { + format!("`{}`", self.loan_path_to_string(&lp)) + } + }; + db.span_label(s1, + &format!("{} dropped here while still borrowed", msg)); + } else { + db.span_label(s1, &format!("{} dropped before borrower", value_kind)); + } db.note("values in a scope are dropped in the opposite order \ they are created"); } diff --git a/src/test/compile-fail-fulldeps/dropck_tarena_cycle_checked.rs b/src/test/compile-fail-fulldeps/dropck_tarena_cycle_checked.rs index d36293a484d..bbdc59c8431 100644 --- a/src/test/compile-fail-fulldeps/dropck_tarena_cycle_checked.rs +++ b/src/test/compile-fail-fulldeps/dropck_tarena_cycle_checked.rs @@ -123,5 +123,5 @@ fn f<'a>(arena: &'a TypedArena>) { fn main() { let arena = TypedArena::new(); - f(&arena); //~ ERROR `arena` does not live long enough -} + f(&arena); +} //~ ERROR `arena` does not live long enough diff --git a/src/test/compile-fail-fulldeps/dropck_tarena_unsound_drop.rs b/src/test/compile-fail-fulldeps/dropck_tarena_unsound_drop.rs index 6cbed34c7ad..46cb7605574 100644 --- a/src/test/compile-fail-fulldeps/dropck_tarena_unsound_drop.rs +++ b/src/test/compile-fail-fulldeps/dropck_tarena_unsound_drop.rs @@ -46,5 +46,6 @@ fn f<'a>(_arena: &'a TypedArena>) {} fn main() { let arena: TypedArena = TypedArena::new(); - f(&arena); //~ ERROR `arena` does not live long enough -} + f(&arena); +} //~ ERROR `arena` does not live long enough + diff --git a/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr b/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr index 5d2096e8b07..2a4ba22ecc4 100644 --- a/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr +++ b/src/test/ui/dropck/dropck-eyepatch-extern-crate.stderr @@ -1,44 +1,44 @@ error: `c` does not live long enough - --> $DIR/dropck-eyepatch-extern-crate.rs:39:20 + --> $DIR/dropck-eyepatch-extern-crate.rs:55:1 | 39 | dt = Dt("dt", &c); //~ ERROR `c` does not live long enough - | ^ does not live long enough + | - borrow occurs here ... 55 | } - | - borrowed value dropped before borrower + | ^ `c` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created error: `c` does not live long enough - --> $DIR/dropck-eyepatch-extern-crate.rs:40:20 + --> $DIR/dropck-eyepatch-extern-crate.rs:55:1 | 40 | dr = Dr("dr", &c); //~ ERROR `c` does not live long enough - | ^ does not live long enough + | - borrow occurs here ... 55 | } - | - borrowed value dropped before borrower + | ^ `c` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created error: `c` does not live long enough - --> $DIR/dropck-eyepatch-extern-crate.rs:47:29 + --> $DIR/dropck-eyepatch-extern-crate.rs:55:1 | 47 | pt = Pt("pt", &c_long, &c); //~ ERROR `c` does not live long enough - | ^ does not live long enough + | - borrow occurs here ... 55 | } - | - borrowed value dropped before borrower + | ^ `c` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created error: `c` does not live long enough - --> $DIR/dropck-eyepatch-extern-crate.rs:48:29 + --> $DIR/dropck-eyepatch-extern-crate.rs:55:1 | 48 | pr = Pr("pr", &c_long, &c); //~ ERROR `c` does not live long enough - | ^ does not live long enough + | - borrow occurs here ... 55 | } - | - borrowed value dropped before borrower + | ^ `c` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created diff --git a/src/test/ui/dropck/dropck-eyepatch-reorder.stderr b/src/test/ui/dropck/dropck-eyepatch-reorder.stderr index 33b18f6f02e..cfcf988f31f 100644 --- a/src/test/ui/dropck/dropck-eyepatch-reorder.stderr +++ b/src/test/ui/dropck/dropck-eyepatch-reorder.stderr @@ -1,44 +1,44 @@ error: `c` does not live long enough - --> $DIR/dropck-eyepatch-reorder.rs:57:20 + --> $DIR/dropck-eyepatch-reorder.rs:73:1 | 57 | dt = Dt("dt", &c); //~ ERROR `c` does not live long enough - | ^ does not live long enough + | - borrow occurs here ... 73 | } - | - borrowed value dropped before borrower + | ^ `c` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created error: `c` does not live long enough - --> $DIR/dropck-eyepatch-reorder.rs:58:20 + --> $DIR/dropck-eyepatch-reorder.rs:73:1 | 58 | dr = Dr("dr", &c); //~ ERROR `c` does not live long enough - | ^ does not live long enough + | - borrow occurs here ... 73 | } - | - borrowed value dropped before borrower + | ^ `c` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created error: `c` does not live long enough - --> $DIR/dropck-eyepatch-reorder.rs:65:29 + --> $DIR/dropck-eyepatch-reorder.rs:73:1 | 65 | pt = Pt("pt", &c_long, &c); //~ ERROR `c` does not live long enough - | ^ does not live long enough + | - borrow occurs here ... 73 | } - | - borrowed value dropped before borrower + | ^ `c` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created error: `c` does not live long enough - --> $DIR/dropck-eyepatch-reorder.rs:66:29 + --> $DIR/dropck-eyepatch-reorder.rs:73:1 | 66 | pr = Pr("pr", &c_long, &c); //~ ERROR `c` does not live long enough - | ^ does not live long enough + | - borrow occurs here ... 73 | } - | - borrowed value dropped before borrower + | ^ `c` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created diff --git a/src/test/ui/dropck/dropck-eyepatch.stderr b/src/test/ui/dropck/dropck-eyepatch.stderr index 75e612ca9c8..cd420756b44 100644 --- a/src/test/ui/dropck/dropck-eyepatch.stderr +++ b/src/test/ui/dropck/dropck-eyepatch.stderr @@ -1,44 +1,44 @@ error: `c` does not live long enough - --> $DIR/dropck-eyepatch.rs:80:20 + --> $DIR/dropck-eyepatch.rs:96:1 | 80 | dt = Dt("dt", &c); //~ ERROR `c` does not live long enough - | ^ does not live long enough + | - borrow occurs here ... 96 | } - | - borrowed value dropped before borrower + | ^ `c` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created error: `c` does not live long enough - --> $DIR/dropck-eyepatch.rs:81:20 + --> $DIR/dropck-eyepatch.rs:96:1 | 81 | dr = Dr("dr", &c); //~ ERROR `c` does not live long enough - | ^ does not live long enough + | - borrow occurs here ... 96 | } - | - borrowed value dropped before borrower + | ^ `c` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created error: `c` does not live long enough - --> $DIR/dropck-eyepatch.rs:88:29 + --> $DIR/dropck-eyepatch.rs:96:1 | 88 | pt = Pt("pt", &c_long, &c); //~ ERROR `c` does not live long enough - | ^ does not live long enough + | - borrow occurs here ... 96 | } - | - borrowed value dropped before borrower + | ^ `c` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created error: `c` does not live long enough - --> $DIR/dropck-eyepatch.rs:89:29 + --> $DIR/dropck-eyepatch.rs:96:1 | 89 | pr = Pr("pr", &c_long, &c); //~ ERROR `c` does not live long enough - | ^ does not live long enough + | - borrow occurs here ... 96 | } - | - borrowed value dropped before borrower + | ^ `c` dropped here while still borrowed | = note: values in a scope are dropped in the opposite order they are created diff --git a/src/test/compile-fail/borrowck/borrowck-let-suggestion-suffixes.rs b/src/test/ui/span/borrowck-let-suggestion-suffixes.rs similarity index 89% rename from src/test/compile-fail/borrowck/borrowck-let-suggestion-suffixes.rs rename to src/test/ui/span/borrowck-let-suggestion-suffixes.rs index 95c74348e78..1206d716672 100644 --- a/src/test/compile-fail/borrowck/borrowck-let-suggestion-suffixes.rs +++ b/src/test/ui/span/borrowck-let-suggestion-suffixes.rs @@ -17,9 +17,7 @@ fn f() { let young = ['y']; // statement 3 v2.push(&young[0]); // statement 4 - //~^ ERROR `young[..]` does not live long enough - //~| NOTE does not live long enough - //~| NOTE values in a scope are dropped in the opposite order they are created + //~^ NOTE borrow occurs here let mut v3 = Vec::new(); // statement 5 @@ -52,7 +50,9 @@ fn f() { v1.push(&old[0]); } -//~^ NOTE borrowed value dropped before borrower +//~^ ERROR `young[..]` does not live long enough +//~| NOTE `young[..]` dropped here while still borrowed +//~| NOTE values in a scope are dropped in the opposite order they are created //~| NOTE temporary value needs to live until here //~| NOTE temporary value needs to live until here diff --git a/src/test/ui/span/borrowck-let-suggestion-suffixes.stderr b/src/test/ui/span/borrowck-let-suggestion-suffixes.stderr new file mode 100644 index 00000000000..0bba986e437 --- /dev/null +++ b/src/test/ui/span/borrowck-let-suggestion-suffixes.stderr @@ -0,0 +1,52 @@ +error: `young[..]` does not live long enough + --> $DIR/borrowck-let-suggestion-suffixes.rs:52:1 + | +19 | v2.push(&young[0]); // statement 4 + | -------- borrow occurs here +... +52 | } + | ^ `young[..]` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: borrowed value does not live long enough + --> $DIR/borrowck-let-suggestion-suffixes.rs:24:14 + | +24 | v3.push(&'x'); // statement 6 + | ^^^ - temporary value only lives until here + | | + | temporary value created here +... +52 | } + | - temporary value needs to live until here + | + = note: consider using a `let` binding to increase its lifetime + +error: borrowed value does not live long enough + --> $DIR/borrowck-let-suggestion-suffixes.rs:34:18 + | +34 | v4.push(&'y'); + | ^^^ - temporary value only lives until here + | | + | temporary value created here +... +40 | } // (statement 7) + | - temporary value needs to live until here + | + = note: consider using a `let` binding to increase its lifetime + +error: borrowed value does not live long enough + --> $DIR/borrowck-let-suggestion-suffixes.rs:45:14 + | +45 | v5.push(&'z'); + | ^^^ - temporary value only lives until here + | | + | temporary value created here +... +52 | } + | - temporary value needs to live until here + | + = note: consider using a `let` binding to increase its lifetime + +error: aborting due to 4 previous errors + diff --git a/src/test/compile-fail/dropck-object-cycle.rs b/src/test/ui/span/dropck-object-cycle.rs similarity index 89% rename from src/test/compile-fail/dropck-object-cycle.rs rename to src/test/ui/span/dropck-object-cycle.rs index 5432cbf402a..ce9bc17432e 100644 --- a/src/test/compile-fail/dropck-object-cycle.rs +++ b/src/test/ui/span/dropck-object-cycle.rs @@ -35,7 +35,7 @@ impl<'t> MakerTrait for Box+'static> { pub fn main() { let m : Box = make_val(); assert_eq!(object_invoke1(&*m), (4,5)); - //~^ ERROR `*m` does not live long enough + //~^ NOTE borrow occurs here // the problem here is that the full type of `m` is // @@ -55,3 +55,7 @@ pub fn main() { // the type of `m` *strictly outlives* `'m`. Hence we get an // error. } +//~^ ERROR `*m` does not live long enough +//~| NOTE `*m` dropped here while still borrowed +//~| NOTE values in a scope are dropped in the opposite order they are created + diff --git a/src/test/ui/span/dropck-object-cycle.stderr b/src/test/ui/span/dropck-object-cycle.stderr new file mode 100644 index 00000000000..e31c36e83df --- /dev/null +++ b/src/test/ui/span/dropck-object-cycle.stderr @@ -0,0 +1,13 @@ +error: `*m` does not live long enough + --> $DIR/dropck-object-cycle.rs:57:1 + | +37 | assert_eq!(object_invoke1(&*m), (4,5)); + | -- borrow occurs here +... +57 | } + | ^ `*m` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to previous error + diff --git a/src/test/compile-fail/dropck_arr_cycle_checked.rs b/src/test/ui/span/dropck_arr_cycle_checked.rs similarity index 84% rename from src/test/compile-fail/dropck_arr_cycle_checked.rs rename to src/test/ui/span/dropck_arr_cycle_checked.rs index 9cfeaca6dfa..8e8b3c24c76 100644 --- a/src/test/compile-fail/dropck_arr_cycle_checked.rs +++ b/src/test/ui/span/dropck_arr_cycle_checked.rs @@ -100,13 +100,19 @@ fn f() { b1 = B::new(); b2 = B::new(); b3 = B::new(); - b1.a[0].v.set(Some(&b2)); //~ ERROR `b2` does not live long enough - b1.a[1].v.set(Some(&b3)); //~ ERROR `b3` does not live long enough - b2.a[0].v.set(Some(&b2)); //~ ERROR `b2` does not live long enough - b2.a[1].v.set(Some(&b3)); //~ ERROR `b3` does not live long enough - b3.a[0].v.set(Some(&b1)); //~ ERROR `b1` does not live long enough - b3.a[1].v.set(Some(&b2)); //~ ERROR `b2` does not live long enough + b1.a[0].v.set(Some(&b2)); + b1.a[1].v.set(Some(&b3)); + b2.a[0].v.set(Some(&b2)); + b2.a[1].v.set(Some(&b3)); + b3.a[0].v.set(Some(&b1)); + b3.a[1].v.set(Some(&b2)); } +//~^ ERROR `b2` does not live long enough +//~| ERROR `b3` does not live long enough +//~| ERROR `b2` does not live long enough +//~| ERROR `b3` does not live long enough +//~| ERROR `b1` does not live long enough +//~| ERROR `b2` does not live long enough fn main() { f(); diff --git a/src/test/ui/span/dropck_arr_cycle_checked.stderr b/src/test/ui/span/dropck_arr_cycle_checked.stderr new file mode 100644 index 00000000000..c89da0baef2 --- /dev/null +++ b/src/test/ui/span/dropck_arr_cycle_checked.stderr @@ -0,0 +1,67 @@ +error: `b2` does not live long enough + --> $DIR/dropck_arr_cycle_checked.rs:109:1 + | +103 | b1.a[0].v.set(Some(&b2)); + | -- borrow occurs here +... +109 | } + | ^ `b2` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `b3` does not live long enough + --> $DIR/dropck_arr_cycle_checked.rs:109:1 + | +104 | b1.a[1].v.set(Some(&b3)); + | -- borrow occurs here +... +109 | } + | ^ `b3` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `b2` does not live long enough + --> $DIR/dropck_arr_cycle_checked.rs:109:1 + | +105 | b2.a[0].v.set(Some(&b2)); + | -- borrow occurs here +... +109 | } + | ^ `b2` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `b3` does not live long enough + --> $DIR/dropck_arr_cycle_checked.rs:109:1 + | +106 | b2.a[1].v.set(Some(&b3)); + | -- borrow occurs here +... +109 | } + | ^ `b3` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `b1` does not live long enough + --> $DIR/dropck_arr_cycle_checked.rs:109:1 + | +107 | b3.a[0].v.set(Some(&b1)); + | -- borrow occurs here +108 | b3.a[1].v.set(Some(&b2)); +109 | } + | ^ `b1` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `b2` does not live long enough + --> $DIR/dropck_arr_cycle_checked.rs:109:1 + | +108 | b3.a[1].v.set(Some(&b2)); + | -- borrow occurs here +109 | } + | ^ `b2` 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 + diff --git a/src/test/compile-fail/dropck_direct_cycle_with_drop.rs b/src/test/ui/span/dropck_direct_cycle_with_drop.rs similarity index 92% rename from src/test/compile-fail/dropck_direct_cycle_with_drop.rs rename to src/test/ui/span/dropck_direct_cycle_with_drop.rs index 5db23721259..6d13dfc7a79 100644 --- a/src/test/compile-fail/dropck_direct_cycle_with_drop.rs +++ b/src/test/ui/span/dropck_direct_cycle_with_drop.rs @@ -43,9 +43,11 @@ impl<'a> Drop for D<'a> { fn g() { let (d1, d2) = (D::new(format!("d1")), D::new(format!("d2"))); - d1.p.set(Some(&d2)); //~ ERROR `d2` does not live long enough - d2.p.set(Some(&d1)); //~ ERROR `d1` does not live long enough + d1.p.set(Some(&d2)); + d2.p.set(Some(&d1)); } +//~^ ERROR `d2` does not live long enough +//~| ERROR `d1` does not live long enough fn main() { g(); diff --git a/src/test/ui/span/dropck_direct_cycle_with_drop.stderr b/src/test/ui/span/dropck_direct_cycle_with_drop.stderr new file mode 100644 index 00000000000..9eb2a215771 --- /dev/null +++ b/src/test/ui/span/dropck_direct_cycle_with_drop.stderr @@ -0,0 +1,23 @@ +error: `d2` does not live long enough + --> $DIR/dropck_direct_cycle_with_drop.rs:48:1 + | +46 | d1.p.set(Some(&d2)); + | -- borrow occurs here +47 | d2.p.set(Some(&d1)); +48 | } + | ^ `d2` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `d1` does not live long enough + --> $DIR/dropck_direct_cycle_with_drop.rs:48:1 + | +47 | d2.p.set(Some(&d1)); + | -- borrow occurs here +48 | } + | ^ `d1` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to 2 previous errors + diff --git a/src/test/compile-fail/dropck_misc_variants.rs b/src/test/ui/span/dropck_misc_variants.rs similarity index 92% rename from src/test/compile-fail/dropck_misc_variants.rs rename to src/test/ui/span/dropck_misc_variants.rs index ee957f20d00..7b94eb10dfc 100644 --- a/src/test/compile-fail/dropck_misc_variants.rs +++ b/src/test/ui/span/dropck_misc_variants.rs @@ -31,17 +31,17 @@ fn projection() { let (_w, bomb); bomb = vec![""]; _w = Wrap::<&[&str]>(NoisyDrop(&bomb)); - //~^ ERROR `bomb` does not live long enough } +//~^ ERROR `bomb` does not live long enough fn closure() { let (_w,v); v = vec![""]; _w = { let u = NoisyDrop(&v); - //~^ ERROR `v` does not live long enough move || u.0.len() }; } +//~^ ERROR `v` does not live long enough fn main() { closure(); projection() } diff --git a/src/test/ui/span/dropck_misc_variants.stderr b/src/test/ui/span/dropck_misc_variants.stderr new file mode 100644 index 00000000000..98c1cbbba7b --- /dev/null +++ b/src/test/ui/span/dropck_misc_variants.stderr @@ -0,0 +1,23 @@ +error: `bomb` does not live long enough + --> $DIR/dropck_misc_variants.rs:34:1 + | +33 | _w = Wrap::<&[&str]>(NoisyDrop(&bomb)); + | ---- borrow occurs here +34 | } + | ^ `bomb` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `v` does not live long enough + --> $DIR/dropck_misc_variants.rs:44:1 + | +41 | let u = NoisyDrop(&v); + | - borrow occurs here +... +44 | } + | ^ `v` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to 2 previous errors + diff --git a/src/test/compile-fail/dropck_vec_cycle_checked.rs b/src/test/ui/span/dropck_vec_cycle_checked.rs similarity index 85% rename from src/test/compile-fail/dropck_vec_cycle_checked.rs rename to src/test/ui/span/dropck_vec_cycle_checked.rs index caf25e68d56..65db2a56b7d 100644 --- a/src/test/compile-fail/dropck_vec_cycle_checked.rs +++ b/src/test/ui/span/dropck_vec_cycle_checked.rs @@ -107,13 +107,19 @@ fn f() { c3.v.push(CheckId(Cell::new(None))); c3.v.push(CheckId(Cell::new(None))); - c1.v[0].v.set(Some(&c2)); //~ ERROR `c2` does not live long enough - c1.v[1].v.set(Some(&c3)); //~ ERROR `c3` does not live long enough - c2.v[0].v.set(Some(&c2)); //~ ERROR `c2` does not live long enough - c2.v[1].v.set(Some(&c3)); //~ ERROR `c3` does not live long enough - c3.v[0].v.set(Some(&c1)); //~ ERROR `c1` does not live long enough - c3.v[1].v.set(Some(&c2)); //~ ERROR `c2` does not live long enough + c1.v[0].v.set(Some(&c2)); + c1.v[1].v.set(Some(&c3)); + c2.v[0].v.set(Some(&c2)); + c2.v[1].v.set(Some(&c3)); + c3.v[0].v.set(Some(&c1)); + c3.v[1].v.set(Some(&c2)); } +//~^ ERROR `c2` does not live long enough +//~| ERROR `c3` does not live long enough +//~| ERROR `c2` does not live long enough +//~| ERROR `c3` does not live long enough +//~| ERROR `c1` does not live long enough +//~| ERROR `c2` does not live long enough fn main() { f(); diff --git a/src/test/ui/span/dropck_vec_cycle_checked.stderr b/src/test/ui/span/dropck_vec_cycle_checked.stderr new file mode 100644 index 00000000000..961ac81cf82 --- /dev/null +++ b/src/test/ui/span/dropck_vec_cycle_checked.stderr @@ -0,0 +1,67 @@ +error: `c2` does not live long enough + --> $DIR/dropck_vec_cycle_checked.rs:116:1 + | +110 | c1.v[0].v.set(Some(&c2)); + | -- borrow occurs here +... +116 | } + | ^ `c2` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `c3` does not live long enough + --> $DIR/dropck_vec_cycle_checked.rs:116:1 + | +111 | c1.v[1].v.set(Some(&c3)); + | -- borrow occurs here +... +116 | } + | ^ `c3` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `c2` does not live long enough + --> $DIR/dropck_vec_cycle_checked.rs:116:1 + | +112 | c2.v[0].v.set(Some(&c2)); + | -- borrow occurs here +... +116 | } + | ^ `c2` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `c3` does not live long enough + --> $DIR/dropck_vec_cycle_checked.rs:116:1 + | +113 | c2.v[1].v.set(Some(&c3)); + | -- borrow occurs here +... +116 | } + | ^ `c3` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `c1` does not live long enough + --> $DIR/dropck_vec_cycle_checked.rs:116:1 + | +114 | c3.v[0].v.set(Some(&c1)); + | -- borrow occurs here +115 | c3.v[1].v.set(Some(&c2)); +116 | } + | ^ `c1` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `c2` does not live long enough + --> $DIR/dropck_vec_cycle_checked.rs:116:1 + | +115 | c3.v[1].v.set(Some(&c2)); + | -- borrow occurs here +116 | } + | ^ `c2` 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 + diff --git a/src/test/compile-fail/issue-23338-locals-die-before-temps-of-body.rs b/src/test/ui/span/issue-23338-locals-die-before-temps-of-body.rs similarity index 94% rename from src/test/compile-fail/issue-23338-locals-die-before-temps-of-body.rs rename to src/test/ui/span/issue-23338-locals-die-before-temps-of-body.rs index 993893438e5..a04edd99b8b 100644 --- a/src/test/compile-fail/issue-23338-locals-die-before-temps-of-body.rs +++ b/src/test/ui/span/issue-23338-locals-die-before-temps-of-body.rs @@ -17,8 +17,9 @@ use std::cell::RefCell; fn foo(x: RefCell) -> String { let y = x; - y.borrow().clone() //~ ERROR `y` does not live long enough + y.borrow().clone() } +//~^ ERROR `y` does not live long enough fn foo2(x: RefCell) -> String { let ret = { diff --git a/src/test/ui/span/issue-23338-locals-die-before-temps-of-body.stderr b/src/test/ui/span/issue-23338-locals-die-before-temps-of-body.stderr new file mode 100644 index 00000000000..f10ba0bf221 --- /dev/null +++ b/src/test/ui/span/issue-23338-locals-die-before-temps-of-body.stderr @@ -0,0 +1,22 @@ +error: `y` does not live long enough + --> $DIR/issue-23338-locals-die-before-temps-of-body.rs:21:1 + | +20 | y.borrow().clone() + | - borrow occurs here +21 | } + | ^ `y` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `y` does not live long enough + --> $DIR/issue-23338-locals-die-before-temps-of-body.rs:27:9 + | +27 | y.borrow().clone() //~ ERROR `y` does not live long enough + | ^ does not live long enough +28 | }; + | -- borrowed value needs to live until here + | | + | borrowed value only lives until here + +error: aborting due to 2 previous errors + diff --git a/src/test/compile-fail/issue-24805-dropck-child-has-items-via-parent.rs b/src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.rs similarity index 95% rename from src/test/compile-fail/issue-24805-dropck-child-has-items-via-parent.rs rename to src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.rs index 37ef81e6866..acd363fc6b0 100644 --- a/src/test/compile-fail/issue-24805-dropck-child-has-items-via-parent.rs +++ b/src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.rs @@ -35,11 +35,12 @@ fn f_child() { d1 = D_Child(1); // ... we store a reference to `d1` within `_d` ... - _d = D_Child(&d1); //~ ERROR `d1` does not live long enough + _d = D_Child(&d1); // ... dropck *should* complain, because Drop of _d could (and // does) access the already dropped `d1` via the `foo` method. } +//~^ ERROR `d1` does not live long enough fn main() { f_child(); diff --git a/src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.stderr b/src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.stderr new file mode 100644 index 00000000000..a622e7cfb71 --- /dev/null +++ b/src/test/ui/span/issue-24805-dropck-child-has-items-via-parent.stderr @@ -0,0 +1,13 @@ +error: `d1` does not live long enough + --> $DIR/issue-24805-dropck-child-has-items-via-parent.rs:42:1 + | +38 | _d = D_Child(&d1); + | -- borrow occurs here +... +42 | } + | ^ `d1` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to previous error + diff --git a/src/test/compile-fail/issue-24805-dropck-trait-has-items.rs b/src/test/ui/span/issue-24805-dropck-trait-has-items.rs similarity index 88% rename from src/test/compile-fail/issue-24805-dropck-trait-has-items.rs rename to src/test/ui/span/issue-24805-dropck-trait-has-items.rs index 0da1b9fc6e1..3deb71411e8 100644 --- a/src/test/compile-fail/issue-24805-dropck-trait-has-items.rs +++ b/src/test/ui/span/issue-24805-dropck-trait-has-items.rs @@ -44,18 +44,21 @@ impl_drop!{HasType, D_HasType} fn f_sm() { let (_d, d1); d1 = D_HasSelfMethod(1); - _d = D_HasSelfMethod(&d1); //~ ERROR `d1` does not live long enough + _d = D_HasSelfMethod(&d1); } +//~^ ERROR `d1` does not live long enough fn f_mwsa() { let (_d, d1); d1 = D_HasMethodWithSelfArg(1); - _d = D_HasMethodWithSelfArg(&d1); //~ ERROR `d1` does not live long enough + _d = D_HasMethodWithSelfArg(&d1); } +//~^ ERROR `d1` does not live long enough fn f_t() { let (_d, d1); d1 = D_HasType(1); - _d = D_HasType(&d1); //~ ERROR `d1` does not live long enough + _d = D_HasType(&d1); } +//~^ ERROR `d1` does not live long enough fn main() { f_sm(); diff --git a/src/test/ui/span/issue-24805-dropck-trait-has-items.stderr b/src/test/ui/span/issue-24805-dropck-trait-has-items.stderr new file mode 100644 index 00000000000..d06c8af62ee --- /dev/null +++ b/src/test/ui/span/issue-24805-dropck-trait-has-items.stderr @@ -0,0 +1,32 @@ +error: `d1` does not live long enough + --> $DIR/issue-24805-dropck-trait-has-items.rs:48:1 + | +47 | _d = D_HasSelfMethod(&d1); + | -- borrow occurs here +48 | } + | ^ `d1` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `d1` does not live long enough + --> $DIR/issue-24805-dropck-trait-has-items.rs:54:1 + | +53 | _d = D_HasMethodWithSelfArg(&d1); + | -- borrow occurs here +54 | } + | ^ `d1` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `d1` does not live long enough + --> $DIR/issue-24805-dropck-trait-has-items.rs:60:1 + | +59 | _d = D_HasType(&d1); + | -- borrow occurs here +60 | } + | ^ `d1` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to 3 previous errors + diff --git a/src/test/compile-fail/issue-24895-copy-clone-dropck.rs b/src/test/ui/span/issue-24895-copy-clone-dropck.rs similarity index 93% rename from src/test/compile-fail/issue-24895-copy-clone-dropck.rs rename to src/test/ui/span/issue-24895-copy-clone-dropck.rs index 28835117369..a4207eb0aa9 100644 --- a/src/test/compile-fail/issue-24895-copy-clone-dropck.rs +++ b/src/test/ui/span/issue-24895-copy-clone-dropck.rs @@ -34,5 +34,5 @@ impl Drop for D { fn main() { let (d2, d1); d1 = D(34, "d1"); - d2 = D(S(&d1, "inner"), "d2"); //~ ERROR `d1` does not live long enough -} + d2 = D(S(&d1, "inner"), "d2"); +} //~ ERROR `d1` does not live long enough diff --git a/src/test/ui/span/issue-24895-copy-clone-dropck.stderr b/src/test/ui/span/issue-24895-copy-clone-dropck.stderr new file mode 100644 index 00000000000..160bfb63900 --- /dev/null +++ b/src/test/ui/span/issue-24895-copy-clone-dropck.stderr @@ -0,0 +1,12 @@ +error: `d1` does not live long enough + --> $DIR/issue-24895-copy-clone-dropck.rs:38:1 + | +37 | d2 = D(S(&d1, "inner"), "d2"); + | -- borrow occurs here +38 | } //~ ERROR `d1` does not live long enough + | ^ `d1` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to previous error + diff --git a/src/test/compile-fail/issue-25199.rs b/src/test/ui/span/issue-25199.rs similarity index 93% rename from src/test/compile-fail/issue-25199.rs rename to src/test/ui/span/issue-25199.rs index 74ea1ca2947..b88c58c29ac 100644 --- a/src/test/compile-fail/issue-25199.rs +++ b/src/test/ui/span/issue-25199.rs @@ -77,7 +77,9 @@ impl<'a> Drop for Test<'a> { fn main() { let container = Container::new(); - let test = Test{test: &container}; //~ ERROR `container` does not live long enough + let test = Test{test: &container}; println!("container.v[30]: {:?}", container.v.v[30]); - container.store(test); //~ ERROR `container` does not live long enough + container.store(test); } +//~^ ERROR `container` does not live long enough +//~| ERROR `container` does not live long enough diff --git a/src/test/ui/span/issue-25199.stderr b/src/test/ui/span/issue-25199.stderr new file mode 100644 index 00000000000..3c8ee07a1fd --- /dev/null +++ b/src/test/ui/span/issue-25199.stderr @@ -0,0 +1,23 @@ +error: `container` does not live long enough + --> $DIR/issue-25199.rs:83:1 + | +80 | let test = Test{test: &container}; + | --------- borrow occurs here +... +83 | } + | ^ `container` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `container` does not live long enough + --> $DIR/issue-25199.rs:83:1 + | +82 | container.store(test); + | --------- borrow occurs here +83 | } + | ^ `container` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to 2 previous errors + diff --git a/src/test/compile-fail/issue-26656.rs b/src/test/ui/span/issue-26656.rs similarity index 96% rename from src/test/compile-fail/issue-26656.rs rename to src/test/ui/span/issue-26656.rs index e5fa65498de..621da477ddc 100644 --- a/src/test/compile-fail/issue-26656.rs +++ b/src/test/ui/span/issue-26656.rs @@ -48,5 +48,5 @@ fn main() { trigger: Box::new(()) }; ticking = Bomb { usable: true }; zook.button = B::BigRedButton(&ticking); - //~^ ERROR `ticking` does not live long enough } +//~^ ERROR `ticking` does not live long enough diff --git a/src/test/ui/span/issue-26656.stderr b/src/test/ui/span/issue-26656.stderr new file mode 100644 index 00000000000..f960844c818 --- /dev/null +++ b/src/test/ui/span/issue-26656.stderr @@ -0,0 +1,12 @@ +error: `ticking` does not live long enough + --> $DIR/issue-26656.rs:51:1 + | +50 | zook.button = B::BigRedButton(&ticking); + | ------- borrow occurs here +51 | } + | ^ `ticking` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to previous error + diff --git a/src/test/compile-fail/issue-29106.rs b/src/test/ui/span/issue-29106.rs similarity index 83% rename from src/test/compile-fail/issue-29106.rs rename to src/test/ui/span/issue-29106.rs index 1872c62e366..8d28c64f264 100644 --- a/src/test/compile-fail/issue-29106.rs +++ b/src/test/ui/span/issue-29106.rs @@ -23,12 +23,12 @@ fn main() { { let (y, x); x = "alive".to_string(); - y = Arc::new(Foo(&x)); //~ ERROR `x` does not live long enough - } + y = Arc::new(Foo(&x)); + } //~ ERROR `x` does not live long enough { let (y, x); x = "alive".to_string(); - y = Rc::new(Foo(&x)); //~ ERROR `x` does not live long enough - } + y = Rc::new(Foo(&x)); + } //~ ERROR `x` does not live long enough } diff --git a/src/test/ui/span/issue-29106.stderr b/src/test/ui/span/issue-29106.stderr new file mode 100644 index 00000000000..a7d3b84daba --- /dev/null +++ b/src/test/ui/span/issue-29106.stderr @@ -0,0 +1,22 @@ +error: `x` does not live long enough + --> $DIR/issue-29106.rs:27:5 + | +26 | y = Arc::new(Foo(&x)); + | - borrow occurs here +27 | } //~ ERROR `x` does not live long enough + | ^ `x` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `x` does not live long enough + --> $DIR/issue-29106.rs:33:5 + | +32 | y = Rc::new(Foo(&x)); + | - borrow occurs here +33 | } //~ ERROR `x` does not live long enough + | ^ `x` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/span/issue-36537.rs b/src/test/ui/span/issue-36537.rs new file mode 100644 index 00000000000..33182e02fa3 --- /dev/null +++ b/src/test/ui/span/issue-36537.rs @@ -0,0 +1,18 @@ +// Copyright 2014 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. + +fn main() { + let p; + let a = 42; + p = &a; //~ NOTE borrow occurs here +} +//~^ ERROR `a` does not live long enough +//~| NOTE `a` dropped here while still borrowed +//~| NOTE values in a scope are dropped in the opposite order they are created diff --git a/src/test/ui/span/issue-36537.stderr b/src/test/ui/span/issue-36537.stderr new file mode 100644 index 00000000000..a335194580d --- /dev/null +++ b/src/test/ui/span/issue-36537.stderr @@ -0,0 +1,12 @@ +error: `a` does not live long enough + --> $DIR/issue-36537.rs:15:1 + | +14 | p = &a; //~ NOTE borrow occurs here + | - borrow occurs here +15 | } + | ^ `a` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to previous error + diff --git a/src/test/compile-fail/issue28498-reject-ex1.rs b/src/test/ui/span/issue28498-reject-ex1.rs similarity index 93% rename from src/test/compile-fail/issue28498-reject-ex1.rs rename to src/test/ui/span/issue28498-reject-ex1.rs index cee7c57c201..bed768005bf 100644 --- a/src/test/compile-fail/issue28498-reject-ex1.rs +++ b/src/test/ui/span/issue28498-reject-ex1.rs @@ -42,7 +42,7 @@ fn main() { foo.data.push(Concrete(0, Cell::new(None))); foo.data[0].1.set(Some(&foo.data[1])); - //~^ ERROR `foo.data` does not live long enough foo.data[1].1.set(Some(&foo.data[0])); - //~^ ERROR `foo.data` does not live long enough } +//~^ ERROR `foo.data` does not live long enough +//~| ERROR `foo.data` does not live long enough diff --git a/src/test/ui/span/issue28498-reject-ex1.stderr b/src/test/ui/span/issue28498-reject-ex1.stderr new file mode 100644 index 00000000000..b5fbe99ec72 --- /dev/null +++ b/src/test/ui/span/issue28498-reject-ex1.stderr @@ -0,0 +1,23 @@ +error: `foo.data` does not live long enough + --> $DIR/issue28498-reject-ex1.rs:46:1 + | +44 | foo.data[0].1.set(Some(&foo.data[1])); + | -------- borrow occurs here +45 | foo.data[1].1.set(Some(&foo.data[0])); +46 | } + | ^ `foo.data` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `foo.data` does not live long enough + --> $DIR/issue28498-reject-ex1.rs:46:1 + | +45 | foo.data[1].1.set(Some(&foo.data[0])); + | -------- borrow occurs here +46 | } + | ^ `foo.data` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to 2 previous errors + diff --git a/src/test/compile-fail/issue28498-reject-lifetime-param.rs b/src/test/ui/span/issue28498-reject-lifetime-param.rs similarity index 92% rename from src/test/compile-fail/issue28498-reject-lifetime-param.rs rename to src/test/ui/span/issue28498-reject-lifetime-param.rs index 92028c7a818..7e7893ac3c8 100644 --- a/src/test/compile-fail/issue28498-reject-lifetime-param.rs +++ b/src/test/ui/span/issue28498-reject-lifetime-param.rs @@ -40,9 +40,9 @@ fn main() { last_dropped = ScribbleOnDrop(format!("last")); first_dropped = ScribbleOnDrop(format!("first")); foo0 = Foo(0, &last_dropped); - //~^ ERROR `last_dropped` does not live long enough foo1 = Foo(1, &first_dropped); - //~^ ERROR `first_dropped` does not live long enough println!("foo0.1: {:?} foo1.1: {:?}", foo0.1, foo1.1); } +//~^ ERROR `last_dropped` does not live long enough +//~| ERROR `first_dropped` does not live long enough diff --git a/src/test/ui/span/issue28498-reject-lifetime-param.stderr b/src/test/ui/span/issue28498-reject-lifetime-param.stderr new file mode 100644 index 00000000000..debb8354568 --- /dev/null +++ b/src/test/ui/span/issue28498-reject-lifetime-param.stderr @@ -0,0 +1,24 @@ +error: `last_dropped` does not live long enough + --> $DIR/issue28498-reject-lifetime-param.rs:46:1 + | +42 | foo0 = Foo(0, &last_dropped); + | ------------ borrow occurs here +... +46 | } + | ^ `last_dropped` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `first_dropped` does not live long enough + --> $DIR/issue28498-reject-lifetime-param.rs:46:1 + | +43 | foo1 = Foo(1, &first_dropped); + | ------------- borrow occurs here +... +46 | } + | ^ `first_dropped` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to 2 previous errors + diff --git a/src/test/compile-fail/issue28498-reject-passed-to-fn.rs b/src/test/ui/span/issue28498-reject-passed-to-fn.rs similarity index 93% rename from src/test/compile-fail/issue28498-reject-passed-to-fn.rs rename to src/test/ui/span/issue28498-reject-passed-to-fn.rs index 27378b1e0be..54fc20b62f2 100644 --- a/src/test/compile-fail/issue28498-reject-passed-to-fn.rs +++ b/src/test/ui/span/issue28498-reject-passed-to-fn.rs @@ -42,9 +42,9 @@ fn main() { last_dropped = ScribbleOnDrop(format!("last")); first_dropped = ScribbleOnDrop(format!("first")); foo0 = Foo(0, &last_dropped, Box::new(callback)); - //~^ ERROR `last_dropped` does not live long enough foo1 = Foo(1, &first_dropped, Box::new(callback)); - //~^ ERROR `first_dropped` does not live long enough println!("foo0.1: {:?} foo1.1: {:?}", foo0.1, foo1.1); } +//~^ ERROR `last_dropped` does not live long enough +//~| ERROR `first_dropped` does not live long enough diff --git a/src/test/ui/span/issue28498-reject-passed-to-fn.stderr b/src/test/ui/span/issue28498-reject-passed-to-fn.stderr new file mode 100644 index 00000000000..7d3ac3e9d03 --- /dev/null +++ b/src/test/ui/span/issue28498-reject-passed-to-fn.stderr @@ -0,0 +1,24 @@ +error: `last_dropped` does not live long enough + --> $DIR/issue28498-reject-passed-to-fn.rs:48:1 + | +44 | foo0 = Foo(0, &last_dropped, Box::new(callback)); + | ------------ borrow occurs here +... +48 | } + | ^ `last_dropped` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `first_dropped` does not live long enough + --> $DIR/issue28498-reject-passed-to-fn.rs:48:1 + | +45 | foo1 = Foo(1, &first_dropped, Box::new(callback)); + | ------------- borrow occurs here +... +48 | } + | ^ `first_dropped` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to 2 previous errors + diff --git a/src/test/compile-fail/issue28498-reject-trait-bound.rs b/src/test/ui/span/issue28498-reject-trait-bound.rs similarity index 92% rename from src/test/compile-fail/issue28498-reject-trait-bound.rs rename to src/test/ui/span/issue28498-reject-trait-bound.rs index 3904d68ba19..6164beaf858 100644 --- a/src/test/compile-fail/issue28498-reject-trait-bound.rs +++ b/src/test/ui/span/issue28498-reject-trait-bound.rs @@ -42,9 +42,9 @@ fn main() { last_dropped = ScribbleOnDrop(format!("last")); first_dropped = ScribbleOnDrop(format!("first")); foo0 = Foo(0, &last_dropped); - //~^ ERROR `last_dropped` does not live long enough foo1 = Foo(1, &first_dropped); - //~^ ERROR `first_dropped` does not live long enough println!("foo0.1: {:?} foo1.1: {:?}", foo0.1, foo1.1); } +//~^ ERROR `last_dropped` does not live long enough +//~| ERROR `first_dropped` does not live long enough diff --git a/src/test/ui/span/issue28498-reject-trait-bound.stderr b/src/test/ui/span/issue28498-reject-trait-bound.stderr new file mode 100644 index 00000000000..ae96cace91c --- /dev/null +++ b/src/test/ui/span/issue28498-reject-trait-bound.stderr @@ -0,0 +1,24 @@ +error: `last_dropped` does not live long enough + --> $DIR/issue28498-reject-trait-bound.rs:48:1 + | +44 | foo0 = Foo(0, &last_dropped); + | ------------ borrow occurs here +... +48 | } + | ^ `last_dropped` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `first_dropped` does not live long enough + --> $DIR/issue28498-reject-trait-bound.rs:48:1 + | +45 | foo1 = Foo(1, &first_dropped); + | ------------- borrow occurs here +... +48 | } + | ^ `first_dropped` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to 2 previous errors + diff --git a/src/test/compile-fail/impl-trait/loan-extend.rs b/src/test/ui/span/loan-extend.rs similarity index 76% rename from src/test/compile-fail/impl-trait/loan-extend.rs rename to src/test/ui/span/loan-extend.rs index 8dfcb08cff3..a4b951daab4 100644 --- a/src/test/compile-fail/impl-trait/loan-extend.rs +++ b/src/test/ui/span/loan-extend.rs @@ -17,7 +17,8 @@ fn main() { let long; let mut short = 0; long = borrow(&mut short); - //~^ ERROR `short` does not live long enough - //~| NOTE does not live long enough - //~| NOTE values in a scope are dropped in the opposite order they are created -} //~ borrowed value dropped before borrower + //~^ NOTE borrow occurs here +} +//~^ ERROR `short` does not live long enough +//~| NOTE `short` dropped here while still borrowed +//~| NOTE values in a scope are dropped in the opposite order they are created diff --git a/src/test/ui/span/loan-extend.stderr b/src/test/ui/span/loan-extend.stderr new file mode 100644 index 00000000000..b0f191e29d1 --- /dev/null +++ b/src/test/ui/span/loan-extend.stderr @@ -0,0 +1,13 @@ +error: `short` does not live long enough + --> $DIR/loan-extend.rs:21:1 + | +19 | long = borrow(&mut short); + | ----- borrow occurs here +20 | //~^ NOTE borrow occurs here +21 | } + | ^ `short` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to previous error + diff --git a/src/test/compile-fail/vec-must-not-hide-type-from-dropck.rs b/src/test/ui/span/vec-must-not-hide-type-from-dropck.rs similarity index 96% rename from src/test/compile-fail/vec-must-not-hide-type-from-dropck.rs rename to src/test/ui/span/vec-must-not-hide-type-from-dropck.rs index c8f4326bb28..310ab20489a 100644 --- a/src/test/compile-fail/vec-must-not-hide-type-from-dropck.rs +++ b/src/test/ui/span/vec-must-not-hide-type-from-dropck.rs @@ -124,9 +124,11 @@ fn f() { c1.v.push(CheckId(Cell::new(None))); c2.v.push(CheckId(Cell::new(None))); - c1.v[0].v.set(Some(&c2)); //~ ERROR `c2` does not live long enough - c2.v[0].v.set(Some(&c1)); //~ ERROR `c1` does not live long enough + c1.v[0].v.set(Some(&c2)); + c2.v[0].v.set(Some(&c1)); } +//~^ ERROR `c2` does not live long enough +//~| ERROR `c1` does not live long enough fn main() { f(); diff --git a/src/test/ui/span/vec-must-not-hide-type-from-dropck.stderr b/src/test/ui/span/vec-must-not-hide-type-from-dropck.stderr new file mode 100644 index 00000000000..11031ee0ab2 --- /dev/null +++ b/src/test/ui/span/vec-must-not-hide-type-from-dropck.stderr @@ -0,0 +1,23 @@ +error: `c2` does not live long enough + --> $DIR/vec-must-not-hide-type-from-dropck.rs:129:1 + | +127 | c1.v[0].v.set(Some(&c2)); + | -- borrow occurs here +128 | c2.v[0].v.set(Some(&c1)); +129 | } + | ^ `c2` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `c1` does not live long enough + --> $DIR/vec-must-not-hide-type-from-dropck.rs:129:1 + | +128 | c2.v[0].v.set(Some(&c1)); + | -- borrow occurs here +129 | } + | ^ `c1` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to 2 previous errors + diff --git a/src/test/compile-fail/vec_refs_data_with_early_death.rs b/src/test/ui/span/vec_refs_data_with_early_death.rs similarity index 90% rename from src/test/compile-fail/vec_refs_data_with_early_death.rs rename to src/test/ui/span/vec_refs_data_with_early_death.rs index 0025449a3db..f40a25920bf 100644 --- a/src/test/compile-fail/vec_refs_data_with_early_death.rs +++ b/src/test/ui/span/vec_refs_data_with_early_death.rs @@ -24,8 +24,10 @@ fn main() { let x: i8 = 3; let y: i8 = 4; - v.push(&x); //~ ERROR `x` does not live long enough - v.push(&y); //~ ERROR `y` does not live long enough + v.push(&x); + v.push(&y); assert_eq!(v, [&3, &4]); } +//~^ ERROR `x` does not live long enough +//~| ERROR `y` does not live long enough diff --git a/src/test/ui/span/vec_refs_data_with_early_death.stderr b/src/test/ui/span/vec_refs_data_with_early_death.stderr new file mode 100644 index 00000000000..8cc12c32b93 --- /dev/null +++ b/src/test/ui/span/vec_refs_data_with_early_death.stderr @@ -0,0 +1,24 @@ +error: `x` does not live long enough + --> $DIR/vec_refs_data_with_early_death.rs:31:1 + | +27 | v.push(&x); + | - borrow occurs here +... +31 | } + | ^ `x` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: `y` does not live long enough + --> $DIR/vec_refs_data_with_early_death.rs:31:1 + | +28 | v.push(&y); + | - borrow occurs here +... +31 | } + | ^ `y` dropped here while still borrowed + | + = note: values in a scope are dropped in the opposite order they are created + +error: aborting due to 2 previous errors +