Auto merge of #37174 - mikhail-m1:dnlle, r=jonathandturner
improve "Doesn't live long enough" error I've fixed only with same case issue #36537 part of #35233 r? @jonathandturner
This commit is contained in:
commit
a6fa57291b
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -123,5 +123,5 @@ fn f<'a>(arena: &'a TypedArena<C<'a>>) {
|
|||
|
||||
fn main() {
|
||||
let arena = TypedArena::new();
|
||||
f(&arena); //~ ERROR `arena` does not live long enough
|
||||
}
|
||||
f(&arena);
|
||||
} //~ ERROR `arena` does not live long enough
|
||||
|
|
|
@ -46,5 +46,6 @@ fn f<'a>(_arena: &'a TypedArena<C<'a>>) {}
|
|||
|
||||
fn main() {
|
||||
let arena: TypedArena<C> = TypedArena::new();
|
||||
f(&arena); //~ ERROR `arena` does not live long enough
|
||||
}
|
||||
f(&arena);
|
||||
} //~ ERROR `arena` does not live long enough
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
@ -35,7 +35,7 @@ impl<'t> MakerTrait for Box<Trait<'t>+'static> {
|
|||
pub fn main() {
|
||||
let m : Box<Trait+'static> = 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
|
||||
|
|
@ -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
|
||||
|
|
@ -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();
|
|
@ -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
|
||||
|
|
@ -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();
|
|
@ -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
|
||||
|
|
@ -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() }
|
|
@ -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
|
||||
|
|
@ -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();
|
|
@ -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
|
||||
|
|
@ -17,8 +17,9 @@ use std::cell::RefCell;
|
|||
|
||||
fn foo(x: RefCell<String>) -> 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>) -> String {
|
||||
let ret = {
|
|
@ -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
|
||||
|
|
@ -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();
|
|
@ -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
|
||||
|
|
@ -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();
|
|
@ -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
|
||||
|
|
@ -34,5 +34,5 @@ impl<T:Copy> Drop for D<T> {
|
|||
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
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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
|
||||
}
|
|
@ -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
|
||||
|
|
@ -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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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
|
||||
|
|
@ -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();
|
|
@ -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
|
||||
|
|
@ -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
|
|
@ -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
|
||||
|
Loading…
Reference in New Issue