best_blame_constraint: don't filter constraints by sup SCC

The SCCs of the region graph are not a reliable heuristic to use for blaming an interesting
constraint for diagnostics. For region errors, if the outlived region is `'static`, or the involved
types are invariant in their lifetiems, there will be cycles in the constraint graph containing both
the target region and the most interesting constraints to blame. To get better diagnostics in these
cases, this commit removes that heuristic.
This commit is contained in:
dianne 2024-12-04 03:19:03 -08:00
parent 2249232ad8
commit ac922245f0
102 changed files with 588 additions and 510 deletions

View file

@ -1945,7 +1945,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
target_test: impl Fn(RegionVid) -> bool,
) -> (BlameConstraint<'tcx>, Vec<OutlivesConstraint<'tcx>>) {
// Find all paths
let (path, target_region) = self
let (path, _) = self
.find_constraint_paths_between_regions(from_region, target_test)
.or_else(|| {
self.find_constraint_paths_between_regions(from_region, |r| {
@ -1983,29 +1983,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
})
.unwrap_or_else(|| ObligationCauseCode::Misc);
// To find the best span to cite, we first try to look for the
// final constraint that is interesting and where the `sup` is
// not unified with the ultimate target region. The reason
// for this is that we have a chain of constraints that lead
// from the source to the target region, something like:
//
// '0: '1 ('0 is the source)
// '1: '2
// '2: '3
// '3: '4
// '4: '5
// '5: '6 ('6 is the target)
//
// Some of those regions are unified with `'6` (in the same
// SCC). We want to screen those out. After that point, the
// "closest" constraint we have to the end is going to be the
// most likely to be the point where the value escapes -- but
// we still want to screen for an "interesting" point to
// highlight (e.g., a call site or something).
let target_scc = self.constraint_sccs.scc(target_region);
// As noted above, when reporting an error, there is typically a chain of constraints
// leading from some "source" region which must outlive some "target" region.
// When reporting an error, there is typically a chain of constraints leading from some
// "source" region which must outlive some "target" region.
// In most cases, we prefer to "blame" the constraints closer to the target --
// but there is one exception. When constraints arise from higher-ranked subtyping,
// we generally prefer to blame the source value,
@ -2047,30 +2026,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
};
let interesting_to_blame = |constraint: &OutlivesConstraint<'tcx>| {
let constraint_sup_scc = self.constraint_sccs.scc(constraint.sup);
if blame_source {
match constraint.category {
ConstraintCategory::OpaqueType
!matches!(
constraint.category,
ConstraintCategory::OpaqueType
| ConstraintCategory::Boring
| ConstraintCategory::BoringNoLocation
| ConstraintCategory::Internal
| ConstraintCategory::Predicate(_) => false,
ConstraintCategory::TypeAnnotation
| ConstraintCategory::Return(_)
| ConstraintCategory::Yield => true,
_ => constraint_sup_scc != target_scc,
}
} else {
!matches!(
constraint.category,
ConstraintCategory::OpaqueType
| ConstraintCategory::Boring
| ConstraintCategory::BoringNoLocation
| ConstraintCategory::Internal
| ConstraintCategory::Predicate(_)
)
}
| ConstraintCategory::Predicate(_)
)
};
let best_choice = if blame_source {
@ -2111,10 +2074,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
Some(i) => path[i],
None => {
// If that search fails, that is.. unusual. Maybe everything
// is in the same SCC or something. In that case, find what
// appears to be the most interesting point to report to the
// user via an even more ad-hoc guess.
// If that search fails, the only constraints on the path are those that we try not
// to blame. In that case, find what appears to be the most interesting point to
// report to the user via an even more ad-hoc guess.
*path.iter().min_by_key(|p| p.category).unwrap()
}
};

View file

@ -7,9 +7,9 @@ LL | fn bar<'a, 'b, I : for<'x> Foo<&'x isize>>(
| lifetime `'a` defined here
...
LL | let z: I::A = if cond { x } else { y };
| ^ assignment requires that `'a` must outlive `'b`
| ^ assignment requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'a: 'b`
= help: consider adding the following bound: `'b: 'a`
error: lifetime may not live long enough
--> $DIR/associated-types-project-from-hrtb-in-fn-body.rs:22:40
@ -20,9 +20,9 @@ LL | fn bar<'a, 'b, I : for<'x> Foo<&'x isize>>(
| lifetime `'a` defined here
...
LL | let z: I::A = if cond { x } else { y };
| ^ assignment requires that `'b` must outlive `'a`
| ^ assignment requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'b: 'a`
= help: consider adding the following bound: `'a: 'b`
help: `'a` and `'b` must be the same: replace one with the other

View file

@ -7,9 +7,9 @@ LL | fn baz<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
| lifetime `'a` defined here
LL | let f = foo; // <-- No consistent type can be inferred for `f` here.
LL | let a = bar(f, x);
| ^^^^^^^^^ argument requires that `'a` must outlive `'b`
| ^^^^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'a: 'b`
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of the type `Type<'_>`, which makes the generic argument `'_` invariant
= note: the struct `Type<'a>` is invariant over the parameter `'a`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
@ -23,9 +23,9 @@ LL | fn baz<'a, 'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
| lifetime `'a` defined here
...
LL | let b = bar(f, y);
| ^^^^^^^^^ argument requires that `'b` must outlive `'a`
| ^^^^^^^^^ argument requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'b: 'a`
= help: consider adding the following bound: `'a: 'b`
= note: requirement occurs because of the type `Type<'_>`, which makes the generic argument `'_` invariant
= note: the struct `Type<'a>` is invariant over the parameter `'a`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance

View file

@ -7,7 +7,7 @@ LL | let c = async || { println!("{}", *x); };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ borrowed value does not live long enough
LL | outlives::<'a>(c());
LL | outlives::<'a>(call_once(c));
| ------------ argument requires that `x` is borrowed for `'a`
| ---------------------------- argument requires that `x` is borrowed for `'a`
...
LL | }
| - `x` dropped here while still borrowed
@ -21,10 +21,10 @@ LL | fn simple<'a>(x: &'a i32) {
LL | let c = async move || { println!("{}", *x); };
| - binding `c` declared here
LL | outlives::<'a>(c());
| ^--
| |
| borrowed value does not live long enough
| argument requires that `c` is borrowed for `'a`
| ---------------^---
| | |
| | borrowed value does not live long enough
| argument requires that `c` is borrowed for `'a`
LL | outlives::<'a>(call_once(c));
LL | }
| - `c` dropped here while still borrowed
@ -38,7 +38,7 @@ LL | let c = async || { println!("{}", *x.0); };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ borrowed value does not live long enough
LL | outlives::<'a>(c());
LL | outlives::<'a>(call_once(c));
| ------------ argument requires that `x` is borrowed for `'a`
| ---------------------------- argument requires that `x` is borrowed for `'a`
...
LL | }
| - `x` dropped here while still borrowed
@ -52,7 +52,7 @@ LL | let c = async || { println!("{}", *x.0); };
| ---------------------------------- borrow of `x` occurs here
LL | outlives::<'a>(c());
LL | outlives::<'a>(call_once(c));
| ------------ argument requires that `x` is borrowed for `'a`
| ---------------------------- argument requires that `x` is borrowed for `'a`
LL |
LL | let c = async move || { println!("{}", *x.0); };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ move out of `x` occurs here
@ -66,10 +66,10 @@ LL | fn through_field<'a>(x: S<'a>) {
LL | let c = async move || { println!("{}", *x.0); };
| - binding `c` declared here
LL | outlives::<'a>(c());
| ^--
| |
| borrowed value does not live long enough
| argument requires that `c` is borrowed for `'a`
| ---------------^---
| | |
| | borrowed value does not live long enough
| argument requires that `c` is borrowed for `'a`
LL | outlives::<'a>(call_once(c));
LL | }
| - `c` dropped here while still borrowed
@ -83,10 +83,10 @@ LL | fn through_field<'a>(x: S<'a>) {
LL | let c = async move || { println!("{}", *x.0); };
| - binding `c` declared here
LL | outlives::<'a>(c());
| ---
| |
| borrow of `c` occurs here
| argument requires that `c` is borrowed for `'a`
| -------------------
| | |
| | borrow of `c` occurs here
| argument requires that `c` is borrowed for `'a`
LL | outlives::<'a>(call_once(c));
| ^ move out of `c` occurs here
@ -99,18 +99,18 @@ LL | let c = async || { println!("{}", *x.0); };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ borrowed value does not live long enough
LL | outlives::<'a>(c());
LL | outlives::<'a>(call_once(c));
| ------------ argument requires that `x` is borrowed for `'a`
| ---------------------------- argument requires that `x` is borrowed for `'a`
LL | }
| - `x` dropped here while still borrowed
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/without-precise-captures-we-are-powerless.rs:38:20
--> $DIR/without-precise-captures-we-are-powerless.rs:38:5
|
LL | fn through_field_and_ref<'a>(x: &S<'a>) {
| ------ help: add explicit lifetime `'a` to the type of `x`: `&'a S<'a>`
...
LL | outlives::<'a>(call_once(c));
| ^^^^^^^^^^^^ lifetime `'a` required
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
error[E0597]: `c` does not live long enough
--> $DIR/without-precise-captures-we-are-powerless.rs:43:20
@ -120,22 +120,22 @@ LL | fn through_field_and_ref_move<'a>(x: &S<'a>) {
LL | let c = async move || { println!("{}", *x.0); };
| - binding `c` declared here
LL | outlives::<'a>(c());
| ^--
| |
| borrowed value does not live long enough
| argument requires that `c` is borrowed for `'a`
| ---------------^---
| | |
| | borrowed value does not live long enough
| argument requires that `c` is borrowed for `'a`
LL | outlives::<'a>(call_once(c));
LL | }
| - `c` dropped here while still borrowed
error[E0621]: explicit lifetime required in the type of `x`
--> $DIR/without-precise-captures-we-are-powerless.rs:44:20
--> $DIR/without-precise-captures-we-are-powerless.rs:44:5
|
LL | fn through_field_and_ref_move<'a>(x: &S<'a>) {
| ------ help: add explicit lifetime `'a` to the type of `x`: `&'a S<'a>`
...
LL | outlives::<'a>(call_once(c));
| ^^^^^^^^^^^^ lifetime `'a` required
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
error: aborting due to 10 previous errors

View file

@ -17,8 +17,8 @@ impl<'a> Future for ListFut<'a> {
}
async fn fut(bufs: &mut [&mut [u8]]) {
ListFut(bufs).await
//~^ ERROR lifetime may not live long enough
ListFut(bufs).await
}
pub struct ListFut2<'a>(&'a mut [&'a mut [u8]]);
@ -31,8 +31,8 @@ impl<'a> Future for ListFut2<'a> {
}
async fn fut2(bufs: &mut [&mut [u8]]) -> i32 {
ListFut2(bufs).await
//~^ ERROR lifetime may not live long enough
ListFut2(bufs).await
}
fn main() {}

View file

@ -1,12 +1,11 @@
error: lifetime may not live long enough
--> $DIR/issue-76547.rs:20:13
--> $DIR/issue-76547.rs:19:14
|
LL | async fn fut(bufs: &mut [&mut [u8]]) {
| - - let's call the lifetime of this reference `'2`
| |
| let's call the lifetime of this reference `'1`
LL | ListFut(bufs).await
| ^^^^ this usage requires that `'1` must outlive `'2`
| ^^^^ - - let's call the lifetime of this reference `'2`
| | |
| | let's call the lifetime of this reference `'1`
| assignment requires that `'1` must outlive `'2`
|
help: consider introducing a named lifetime parameter
|
@ -14,14 +13,13 @@ LL | async fn fut<'a>(bufs: &'a mut [&'a mut [u8]]) {
| ++++ ++ ++
error: lifetime may not live long enough
--> $DIR/issue-76547.rs:34:14
--> $DIR/issue-76547.rs:33:15
|
LL | async fn fut2(bufs: &mut [&mut [u8]]) -> i32 {
| - - let's call the lifetime of this reference `'2`
| |
| let's call the lifetime of this reference `'1`
LL | ListFut2(bufs).await
| ^^^^ this usage requires that `'1` must outlive `'2`
| ^^^^ - - let's call the lifetime of this reference `'2`
| | |
| | let's call the lifetime of this reference `'1`
| assignment requires that `'1` must outlive `'2`
|
help: consider introducing a named lifetime parameter
|

View file

@ -12,12 +12,12 @@ LL | extend_lt(val);
| argument requires that `'a` must outlive `'static`
error: lifetime may not live long enough
--> $DIR/fn-item-check-type-params.rs:39:12
--> $DIR/fn-item-check-type-params.rs:39:31
|
LL | pub fn test_coercion<'a>() {
| -- lifetime `'a` defined here
LL | let _: fn(&'a str) -> _ = extend_lt;
| ^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
| ^^^^^^^^^ coercion requires that `'a` must outlive `'static`
error[E0716]: temporary value dropped while borrowed
--> $DIR/fn-item-check-type-params.rs:48:11

View file

@ -15,10 +15,10 @@ LL | async {
LL | let not_static = 0;
| ---------- binding `not_static` declared here
LL | force_send(async_load(&not_static));
| -----------^^^^^^^^^^^-
| | |
| | borrowed value does not live long enough
| argument requires that `not_static` is borrowed for `'1`
| ----------------------^^^^^^^^^^^--
| | |
| | borrowed value does not live long enough
| argument requires that `not_static` is borrowed for `'1`
...
LL | }
| - `not_static` dropped here while still borrowed

View file

@ -17,6 +17,8 @@ pub fn remove_package_from_database() {
lines_to_use.push(installed_id);
//~^ ERROR borrowed data escapes outside of closure
//~| NOTE `installed_id` escapes the closure body here
//~| NOTE requirement occurs because of a mutable reference to `Vec<&CrateId>`
//~| NOTE mutable references are invariant over their type parameter
};
list_database(push_id);

View file

@ -9,6 +9,10 @@ LL | let push_id = |installed_id: &CrateId| {
LL |
LL | lines_to_use.push(installed_id);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `installed_id` escapes the closure body here
|
= note: requirement occurs because of a mutable reference to `Vec<&CrateId>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 1 previous error

View file

@ -71,14 +71,13 @@ error[E0502]: cannot borrow `*reg` as mutable because it is also borrowed as imm
LL | fn register_plugins<'a>(mk_reg: impl Fn() -> &'a mut Registry<'a>) {
| -- lifetime `'a` defined here
...
LL | let reg = mk_reg();
| -------- assignment requires that `reg.sess_mut` is borrowed for `'a`
LL | reg.register_univ(Box::new(CapturePass::new(&reg.sess_mut)));
| ^^^^^^^^^^^^^^^^^^-----------------------------------------^
| | | |
| | | immutable borrow occurs here
| | coercion requires that `reg.sess_mut` is borrowed for `'a`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-------------^^^
| | |
| | immutable borrow occurs here
| mutable borrow occurs here
|
= note: due to object lifetime defaults, `Box<dyn for<'b> LateLintPass<'b>>` actually means `Box<(dyn for<'b> LateLintPass<'b> + 'static)>`
error[E0502]: cannot borrow `*reg` as mutable because it is also borrowed as immutable
--> $DIR/two-phase-surprise-no-conflict.rs:144:5
@ -115,14 +114,13 @@ error[E0499]: cannot borrow `*reg` as mutable more than once at a time
LL | fn register_plugins<'a>(mk_reg: impl Fn() -> &'a mut Registry<'a>) {
| -- lifetime `'a` defined here
...
LL | let reg = mk_reg();
| -------- assignment requires that `reg.sess_mut` is borrowed for `'a`
LL | reg.register_univ(Box::new(CapturePass::new_mut(&mut reg.sess_mut)));
| ^^^^^^^^^^^^^^^^^^-------------------------------------------------^
| | | |
| | | first mutable borrow occurs here
| | coercion requires that `reg.sess_mut` is borrowed for `'a`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------^^^
| | |
| | first mutable borrow occurs here
| second mutable borrow occurs here
|
= note: due to object lifetime defaults, `Box<dyn for<'b> LateLintPass<'b>>` actually means `Box<(dyn for<'b> LateLintPass<'b> + 'static)>`
error[E0499]: cannot borrow `reg.sess_mut` as mutable more than once at a time
--> $DIR/two-phase-surprise-no-conflict.rs:158:53

View file

@ -120,14 +120,14 @@ LL | }
| - `ap1` dropped here while still borrowed
error: lifetime may not live long enough
--> $DIR/variadic-ffi-4.rs:35:12
--> $DIR/variadic-ffi-4.rs:35:5
|
LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut ap1: ...) {
| ------- ------- has type `VaListImpl<'2>`
| |
| has type `&mut VaListImpl<'1>`
LL | *ap0 = ap1.clone();
| ^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
| ^^^^ assignment requires that `'2` must outlive `'1`
|
= note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
= note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`
@ -141,7 +141,7 @@ LL | pub unsafe extern "C" fn no_escape5(_: usize, mut ap0: &mut VaListImpl, mut
| |
| has type `&mut VaListImpl<'1>`
LL | *ap0 = ap1.clone();
| ^^^^^^^^^^^ argument requires that `'2` must outlive `'1`
| ^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of the type `VaListImpl<'_>`, which makes the generic argument `'_` invariant
= note: the struct `VaListImpl<'f>` is invariant over the parameter `'f`

View file

@ -4,7 +4,7 @@ error: lifetime may not live long enough
LL | fn bad_cast<'a>(x: *const dyn Static<'static>) -> *const dyn Static<'a> {
| -- lifetime `'a` defined here
LL | x as _
| ^^^^^^ returning this value requires that `'a` must outlive `'static`
| ^^^^^^ cast requires that `'a` must outlive `'static`
error: aborting due to 1 previous error

View file

@ -42,7 +42,7 @@ fn change_assoc_1<'a, 'b>(
// This tests the default borrow check error, without the special casing for return values.
fn require_static(_: *const dyn Trait<'static>) {}
fn extend_to_static<'a>(ptr: *const dyn Trait<'a>) {
require_static(ptr as _) //~ error: lifetime may not live long enough
require_static(ptr as _) //~ error: borrowed data escapes outside of function
}
fn main() {}

View file

@ -6,12 +6,9 @@ LL | fn change_lt<'a, 'b>(x: *mut dyn Trait<'a>) -> *mut dyn Trait<'b> {
| |
| lifetime `'a` defined here
LL | x as _
| ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
| ^^^^^^ cast requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of a mutable pointer to `dyn Trait<'_>`
= note: mutable pointers are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
--> $DIR/ptr-to-trait-obj-different-regions-misc.rs:6:5
@ -38,12 +35,9 @@ LL | fn change_lt_ab<'a: 'b, 'b>(x: *mut dyn Trait<'a>) -> *mut dyn Trait<'b> {
| |
| lifetime `'a` defined here
LL | x as _
| ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
| ^^^^^^ cast requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of a mutable pointer to `dyn Trait<'_>`
= note: mutable pointers are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
--> $DIR/ptr-to-trait-obj-different-regions-misc.rs:15:5
@ -91,12 +85,9 @@ LL | fn change_assoc_0<'a, 'b>(
| lifetime `'a` defined here
...
LL | x as _
| ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
| ^^^^^^ cast requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of a mutable pointer to `dyn Assocked<Assoc = dyn Send>`
= note: mutable pointers are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
--> $DIR/ptr-to-trait-obj-different-regions-misc.rs:31:5
@ -127,12 +118,9 @@ LL | fn change_assoc_1<'a, 'b>(
| lifetime `'a` defined here
...
LL | x as _
| ^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b`
| ^^^^^^ cast requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of a mutable pointer to `dyn Assocked<Assoc = dyn Trait<'_>>`
= note: mutable pointers are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
--> $DIR/ptr-to-trait-obj-different-regions-misc.rs:38:5
@ -154,14 +142,22 @@ help: `'b` and `'a` must be the same: replace one with the other
|
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: lifetime may not live long enough
--> $DIR/ptr-to-trait-obj-different-regions-misc.rs:45:20
error[E0521]: borrowed data escapes outside of function
--> $DIR/ptr-to-trait-obj-different-regions-misc.rs:45:5
|
LL | fn extend_to_static<'a>(ptr: *const dyn Trait<'a>) {
| -- lifetime `'a` defined here
| -- ---
| | |
| | `ptr` declared here, outside of the function body
| | `ptr` is a reference that is only valid in the function body
| lifetime `'a` defined here
LL | require_static(ptr as _)
| ^^^^^^^^ cast requires that `'a` must outlive `'static`
| ^^^^^^^^^^^^^^^^^^^^^^^^
| |
| `ptr` escapes the function body here
| argument requires that `'a` must outlive `'static`
error: aborting due to 11 previous errors
For more information about this error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0308, E0521.
For more information about an error, try `rustc --explain E0308`.

View file

@ -18,8 +18,8 @@ fn demo<'not_static>(s: &'not_static str) -> thread::JoinHandle<()> {
// exploit:
generator.as_mut().resume("");
generator.as_mut().resume(s); // <- generator hoards it as `let ctx`.
//~^ ERROR borrowed data escapes outside of function
thread::spawn(move || {
//~^ ERROR borrowed data escapes outside of function
thread::sleep(time::Duration::from_millis(200));
generator.as_mut().resume(""); // <- resumes from the last `yield`, running `dbg!(ctx)`.
})

View file

@ -1,16 +1,20 @@
error[E0521]: borrowed data escapes outside of function
--> $DIR/resume-arg-outlives-2.rs:20:5
--> $DIR/resume-arg-outlives-2.rs:21:5
|
LL | fn demo<'not_static>(s: &'not_static str) -> thread::JoinHandle<()> {
| ----------- - `s` is a reference that is only valid in the function body
| |
| lifetime `'not_static` defined here
LL | fn demo<'not_static>(s: &'not_static str) -> thread::JoinHandle<()> {
| ----------- - `s` is a reference that is only valid in the function body
| |
| lifetime `'not_static` defined here
...
LL | generator.as_mut().resume(s); // <- generator hoards it as `let ctx`.
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| `s` escapes the function body here
| argument requires that `'not_static` must outlive `'static`
LL | / thread::spawn(move || {
LL | |
LL | | thread::sleep(time::Duration::from_millis(200));
LL | | generator.as_mut().resume(""); // <- resumes from the last `yield`, running `dbg!(ctx)`.
LL | | })
| | ^
| | |
| |______`s` escapes the function body here
| argument requires that `'not_static` must outlive `'static`
error: aborting due to 1 previous error

View file

@ -2,83 +2,87 @@ error[E0597]: `o2` does not live long enough
--> $DIR/dropck_trait_cycle_checked.rs:111:13
|
LL | let (o1, o2, o3): (Box<dyn Obj>, Box<dyn Obj>, Box<dyn Obj>) = (O::new(), O::new(), O::new());
| -- binding `o2` declared here -------- coercion requires that `o2` is borrowed for `'static`
| -- binding `o2` declared here
LL | o1.set0(&o2);
| ^^^ borrowed value does not live long enough
...
LL | o3.set0(&o1);
| ------------ argument requires that `o2` is borrowed for `'static`
LL | o3.set1(&o2);
LL | }
| - `o2` dropped here while still borrowed
|
= note: due to object lifetime defaults, `Box<dyn Obj<'_>>` actually means `Box<(dyn Obj<'_> + 'static)>`
error[E0597]: `o3` does not live long enough
--> $DIR/dropck_trait_cycle_checked.rs:112:13
|
LL | let (o1, o2, o3): (Box<dyn Obj>, Box<dyn Obj>, Box<dyn Obj>) = (O::new(), O::new(), O::new());
| -- binding `o3` declared here -------- coercion requires that `o3` is borrowed for `'static`
| -- binding `o3` declared here
LL | o1.set0(&o2);
LL | o1.set1(&o3);
| ^^^ borrowed value does not live long enough
...
LL | o3.set0(&o1);
| ------------ argument requires that `o3` is borrowed for `'static`
LL | o3.set1(&o2);
LL | }
| - `o3` dropped here while still borrowed
|
= note: due to object lifetime defaults, `Box<dyn Obj<'_>>` actually means `Box<(dyn Obj<'_> + 'static)>`
error[E0597]: `o2` does not live long enough
--> $DIR/dropck_trait_cycle_checked.rs:113:13
|
LL | let (o1, o2, o3): (Box<dyn Obj>, Box<dyn Obj>, Box<dyn Obj>) = (O::new(), O::new(), O::new());
| -- binding `o2` declared here -------- coercion requires that `o2` is borrowed for `'static`
...
| -- binding `o2` declared here
LL | o1.set0(&o2);
| ------------ argument requires that `o2` is borrowed for `'static`
LL | o1.set1(&o3);
LL | o2.set0(&o2);
| ^^^ borrowed value does not live long enough
...
LL | }
| - `o2` dropped here while still borrowed
|
= note: due to object lifetime defaults, `Box<dyn Obj<'_>>` actually means `Box<(dyn Obj<'_> + 'static)>`
error[E0597]: `o3` does not live long enough
--> $DIR/dropck_trait_cycle_checked.rs:114:13
|
LL | let (o1, o2, o3): (Box<dyn Obj>, Box<dyn Obj>, Box<dyn Obj>) = (O::new(), O::new(), O::new());
| -- binding `o3` declared here -------- coercion requires that `o3` is borrowed for `'static`
| -- binding `o3` declared here
LL | o1.set0(&o2);
| ------------ argument requires that `o3` is borrowed for `'static`
...
LL | o2.set1(&o3);
| ^^^ borrowed value does not live long enough
...
LL | }
| - `o3` dropped here while still borrowed
|
= note: due to object lifetime defaults, `Box<dyn Obj<'_>>` actually means `Box<(dyn Obj<'_> + 'static)>`
error[E0597]: `o1` does not live long enough
--> $DIR/dropck_trait_cycle_checked.rs:115:13
|
LL | let (o1, o2, o3): (Box<dyn Obj>, Box<dyn Obj>, Box<dyn Obj>) = (O::new(), O::new(), O::new());
| -- binding `o1` declared here -------- coercion requires that `o1` is borrowed for `'static`
| -- binding `o1` declared here
LL | o1.set0(&o2);
LL | o1.set1(&o3);
| ------------ argument requires that `o1` is borrowed for `'static`
...
LL | o3.set0(&o1);
| ^^^ borrowed value does not live long enough
LL | o3.set1(&o2);
LL | }
| - `o1` dropped here while still borrowed
|
= note: due to object lifetime defaults, `Box<dyn Obj<'_>>` actually means `Box<(dyn Obj<'_> + 'static)>`
error[E0597]: `o2` does not live long enough
--> $DIR/dropck_trait_cycle_checked.rs:116:13
|
LL | let (o1, o2, o3): (Box<dyn Obj>, Box<dyn Obj>, Box<dyn Obj>) = (O::new(), O::new(), O::new());
| -- binding `o2` declared here -------- coercion requires that `o2` is borrowed for `'static`
| -- binding `o2` declared here
LL | o1.set0(&o2);
LL | o1.set1(&o3);
| ------------ argument requires that `o2` is borrowed for `'static`
...
LL | o3.set1(&o2);
| ^^^ borrowed value does not live long enough
LL | }
| - `o2` dropped here while still borrowed
|
= note: due to object lifetime defaults, `Box<dyn Obj<'_>>` actually means `Box<(dyn Obj<'_> + 'static)>`
error: aborting due to 6 previous errors

View file

@ -46,12 +46,12 @@ fn j<'a, 'b, 'c: 'a + 'b>(a: &'a (), b: &'b (), c: &'c ()) {
fn k<'a, 'b, 'c: 'a + 'b>(a: &'a (), b: &'b (), c: &'c ()) {
let x = match true {
true => foo::<&'c ()>,
true => foo::<&'c ()>, //~ ERROR lifetime may not live long enough
false => foo::<&'a ()>, //~ ERROR lifetime may not live long enough
};
x(a);
x(b); //~ ERROR lifetime may not live long enough
x(b);
x(c);
}

View file

@ -6,9 +6,9 @@ LL | fn f<'a, 'b, 'c: 'a + 'b>(a: &'a (), b: &'b (), c: &'c ()) {
| |
| lifetime `'a` defined here
LL | let mut x = foo::<&'a ()>;
| ^^^^^^^^^^^^^ assignment requires that `'a` must outlive `'b`
| ^^^^^^^^^^^^^ assignment requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'a: 'b`
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of a function pointer to `foo`
= note: the function `foo` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
@ -22,9 +22,9 @@ LL | fn f<'a, 'b, 'c: 'a + 'b>(a: &'a (), b: &'b (), c: &'c ()) {
| lifetime `'a` defined here
LL | let mut x = foo::<&'a ()>;
LL | x = foo::<&'b ()>;
| ^^^^^^^^^^^^^^^^^ assignment requires that `'b` must outlive `'a`
| ^^^^^^^^^^^^^^^^^ assignment requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'b: 'a`
= help: consider adding the following bound: `'a: 'b`
= note: requirement occurs because of a function pointer to `foo`
= note: the function `foo` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
@ -53,9 +53,9 @@ LL | fn i<'a, 'b, 'c: 'a + 'b>(a: &'a (), b: &'b (), c: &'c ()) {
| lifetime `'a` defined here
LL | let mut x = foo::<&'c ()>;
LL | x = foo::<&'b ()>;
| ^^^^^^^^^^^^^^^^^ assignment requires that `'b` must outlive `'a`
| ^^^^^^^^^^^^^^^^^ assignment requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'b: 'a`
= help: consider adding the following bound: `'a: 'b`
= note: requirement occurs because of a function pointer to `foo`
= note: the function `foo` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
@ -69,9 +69,9 @@ LL | fn i<'a, 'b, 'c: 'a + 'b>(a: &'a (), b: &'b (), c: &'c ()) {
| lifetime `'a` defined here
...
LL | x = foo::<&'a ()>;
| ^^^^^^^^^^^^^^^^^ assignment requires that `'a` must outlive `'b`
| ^^^^^^^^^^^^^^^^^ assignment requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'a: 'b`
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of a function pointer to `foo`
= note: the function `foo` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
@ -89,9 +89,9 @@ LL | fn j<'a, 'b, 'c: 'a + 'b>(a: &'a (), b: &'b (), c: &'c ()) {
| lifetime `'a` defined here
LL | let x = match true {
LL | true => foo::<&'b ()>,
| ^^^^^^^^^^^^^ assignment requires that `'b` must outlive `'a`
| ^^^^^^^^^^^^^ assignment requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'b: 'a`
= help: consider adding the following bound: `'a: 'b`
= note: requirement occurs because of a function pointer to `foo`
= note: the function `foo` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
@ -105,9 +105,9 @@ LL | fn j<'a, 'b, 'c: 'a + 'b>(a: &'a (), b: &'b (), c: &'c ()) {
| lifetime `'a` defined here
...
LL | false => foo::<&'a ()>,
| ^^^^^^^^^^^^^ assignment requires that `'a` must outlive `'b`
| ^^^^^^^^^^^^^ assignment requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'a: 'b`
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of a function pointer to `foo`
= note: the function `foo` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
@ -117,15 +117,15 @@ help: `'a` and `'b` must be the same: replace one with the other
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
error: lifetime may not live long enough
--> $DIR/fn_def_coercion.rs:50:18
--> $DIR/fn_def_coercion.rs:49:17
|
LL | fn k<'a, 'b, 'c: 'a + 'b>(a: &'a (), b: &'b (), c: &'c ()) {
| -- -- lifetime `'c` defined here
| |
| lifetime `'a` defined here
...
LL | false => foo::<&'a ()>,
| ^^^^^^^^^^^^^ assignment requires that `'a` must outlive `'c`
LL | let x = match true {
LL | true => foo::<&'c ()>,
| ^^^^^^^^^^^^^ assignment requires that `'a` must outlive `'c`
|
= help: consider adding the following bound: `'a: 'c`
= note: requirement occurs because of a function pointer to `foo`
@ -133,17 +133,20 @@ LL | false => foo::<&'a ()>,
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
--> $DIR/fn_def_coercion.rs:54:5
--> $DIR/fn_def_coercion.rs:50:18
|
LL | fn k<'a, 'b, 'c: 'a + 'b>(a: &'a (), b: &'b (), c: &'c ()) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | x(b);
| ^^^^ argument requires that `'b` must outlive `'a`
LL | false => foo::<&'a ()>,
| ^^^^^^^^^^^^^ assignment requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of a function pointer to `foo`
= note: the function `foo` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: the following changes may resolve your lifetime errors
|

View file

@ -29,11 +29,11 @@ fn needs_static() {
let a = display_len(&x);
//~^ ERROR `x` does not live long enough
//~| NOTE this call may capture more lifetimes than intended
//~| NOTE argument requires that `x` is borrowed for `'static`
//~| NOTE borrowed value does not live long enoug
fn needs_static(_: impl Sized + 'static) {}
needs_static(a);
//~^ NOTE argument requires that `x` is borrowed for `'static`
}
//~^ NOTE `x` dropped here while still borrowed
@ -76,11 +76,11 @@ fn needs_static_mut() {
let a = display_len_mut(&mut x);
//~^ ERROR `x` does not live long enough
//~| NOTE this call may capture more lifetimes than intended
//~| NOTE argument requires that `x` is borrowed for `'static`
//~| NOTE borrowed value does not live long enough
fn needs_static(_: impl Sized + 'static) {}
needs_static(a);
//~^ NOTE argument requires that `x` is borrowed for `'static`
}
//~^ NOTE `x` dropped here while still borrowed

View file

@ -42,11 +42,11 @@ LL | let x = vec![1];
| - binding `x` declared here
LL |
LL | let a = display_len(&x);
| ------------^^-
| | |
| | borrowed value does not live long enough
| argument requires that `x` is borrowed for `'static`
| ^^ borrowed value does not live long enough
...
LL | needs_static(a);
| --------------- argument requires that `x` is borrowed for `'static`
LL |
LL | }
| - `x` dropped here while still borrowed
|
@ -118,11 +118,11 @@ LL | let mut x = vec![1];
| ----- binding `x` declared here
LL |
LL | let a = display_len_mut(&mut x);
| ----------------^^^^^^-
| | |
| | borrowed value does not live long enough
| argument requires that `x` is borrowed for `'static`
| ^^^^^^ borrowed value does not live long enough
...
LL | needs_static(a);
| --------------- argument requires that `x` is borrowed for `'static`
LL |
LL | }
| - `x` dropped here while still borrowed
|

View file

@ -6,10 +6,9 @@ LL | fn foo<'a>() {
LL | let y = ();
| - binding `y` declared here
LL | equate(InvariantRef::new(&y), const { InvariantRef::<'a>::NEW });
| ------------------^^-
| | |
| | borrowed value does not live long enough
| argument requires that `y` is borrowed for `'a`
| ^^ ----------------------- using this value as a constant requires that `y` is borrowed for `'a`
| |
| borrowed value does not live long enough
LL |
LL | }
| - `y` dropped here while still borrowed

View file

@ -9,7 +9,7 @@ LL | match InvariantRef::new(&y) {
| ^^ borrowed value does not live long enough
LL |
LL | const { InvariantRef::<'a>::NEW } => (),
| --------------------------------- type annotation requires that `y` is borrowed for `'a`
| ----------------------- using this value as a constant requires that `y` is borrowed for `'a`
LL | }
LL | }
| - `y` dropped here while still borrowed

View file

@ -1,10 +1,10 @@
error[E0621]: explicit lifetime required in the type of `lexer`
--> $DIR/issue-15034.rs:17:9
--> $DIR/issue-15034.rs:17:25
|
LL | pub fn new(lexer: &'a mut Lexer) -> Parser<'a> {
| ------------- help: add explicit lifetime `'a` to the type of `lexer`: `&'a mut Lexer<'a>`
LL | Parser { lexer: lexer }
| ^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
| ^^^^^ lifetime `'a` required
error: aborting due to 1 previous error

View file

@ -112,13 +112,13 @@ LL | struct Foo; // does not impl Copy
|
error: lifetime may not live long enough
--> $DIR/kindck-impl-type-params.rs:30:19
--> $DIR/kindck-impl-type-params.rs:30:13
|
LL | fn foo<'a>() {
| -- lifetime `'a` defined here
LL | let t: S<&'a isize> = S(marker::PhantomData);
LL | let a = &t as &dyn Gettable<&'a isize>;
| ^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cast requires that `'a` must outlive `'static`
error: aborting due to 7 previous errors

View file

@ -4,11 +4,7 @@ error: lifetime may not live long enough
LL | fn foo<'a>() -> [Foo<'a>; 100] {
| -- lifetime `'a` defined here
LL | [mk_foo::<'a>(); 100]
| ^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static`
|
= note: requirement occurs because of the type `Foo<'_>`, which makes the generic argument `'_` invariant
= note: the struct `Foo<'a>` is invariant over the parameter `'a`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
| ^^^^^^^^^^^^^^^^^^^^^ copying this value requires that `'a` must outlive `'static`
error: aborting due to 1 previous error

View file

@ -7,6 +7,9 @@ LL | pub fn foo(x: &mut Vec<&u8>, y: &u8) { x.push(y); }
| | let's call the lifetime of this reference `'1`
| let's call the lifetime of this reference `'2`
|
= note: requirement occurs because of a mutable reference to `Vec<&u8>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider introducing a named lifetime parameter
|
LL | pub fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); }
@ -21,6 +24,9 @@ LL | pub fn foo2(x: &mut Vec<&'_ u8>, y: &u8) { x.push(y); }
| | let's call the lifetime of this reference `'1`
| let's call the lifetime of this reference `'2`
|
= note: requirement occurs because of a mutable reference to `Vec<&u8>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider introducing a named lifetime parameter
|
LL | pub fn foo2<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); }
@ -35,6 +41,9 @@ LL | pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&u8>, y: &u8) { x.push(y); }
| | let's call the lifetime of this reference `'1`
| let's call the lifetime of this reference `'2`
|
= note: requirement occurs because of a mutable reference to `Vec<&u8>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider reusing a named lifetime parameter
|
LL | pub fn foo3<'a>(_other: &'a [u8], x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); }

View file

@ -7,9 +7,9 @@ fn inner(mut foo: &[u8]) {
let refcell = RefCell::new(&mut foo);
//~^ ERROR `foo` does not live long enough
let read = &refcell as &RefCell<dyn Read>;
//~^ ERROR lifetime may not live long enough
read_thing(read);
//~^ ERROR borrowed data escapes outside of function
}
fn read_thing(refcell: &RefCell<dyn Read>) {}

View file

@ -5,22 +5,32 @@ LL | fn inner(mut foo: &[u8]) {
| ------- binding `foo` declared here
LL | let refcell = RefCell::new(&mut foo);
| ^^^^^^^^ borrowed value does not live long enough
LL |
LL | let read = &refcell as &RefCell<dyn Read>;
| ------------------------------ cast requires that `foo` is borrowed for `'static`
...
LL | read_thing(read);
| ---------------- argument requires that `foo` is borrowed for `'static`
LL |
LL | }
| - `foo` dropped here while still borrowed
error: lifetime may not live long enough
--> $DIR/issue-90600-expected-return-static-indirect.rs:9:16
error[E0521]: borrowed data escapes outside of function
--> $DIR/issue-90600-expected-return-static-indirect.rs:11:5
|
LL | fn inner(mut foo: &[u8]) {
| - let's call the lifetime of this reference `'1`
| ------- - let's call the lifetime of this reference `'1`
| |
| `foo` is a reference that is only valid in the function body
...
LL | let read = &refcell as &RefCell<dyn Read>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cast requires that `'1` must outlive `'static`
LL | read_thing(read);
| ^^^^^^^^^^^^^^^^
| |
| `foo` escapes the function body here
| argument requires that `'1` must outlive `'static`
|
= note: requirement occurs because of the type `RefCell<(dyn std::io::Read + 'static)>`, which makes the generic argument `(dyn std::io::Read + 'static)` invariant
= note: the struct `RefCell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0597`.
Some errors have detailed explanations: E0521, E0597.
For more information about an error, try `rustc --explain E0521`.

View file

@ -8,6 +8,9 @@ LL | fn foo(x: &mut Vec<Ref<i32>>, y: Ref<i32>) {
LL | x.push(y);
| ^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of a mutable reference to `Vec<Ref<'_, i32>>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider introducing a named lifetime parameter
|
LL | fn foo<'a>(x: &mut Vec<Ref<'a, i32>>, y: Ref<'a, i32>) {

View file

@ -10,6 +10,9 @@ LL | x.push(z);
| ^^^^^^^^^ argument requires that `'c` must outlive `'b`
|
= help: consider adding the following bound: `'c: 'b`
= note: requirement occurs because of a mutable reference to `Vec<Ref<'_, i32>>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 1 previous error

View file

@ -4,9 +4,9 @@ struct Ref<'a, T: 'a> {
fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
let a: &mut Vec<Ref<i32>> = x;
//~^ ERROR lifetime may not live long enough
let b = Ref { data: y.data };
a.push(b);
//~^ ERROR lifetime may not live long enough
}
fn main() { }

View file

@ -1,15 +1,17 @@
error: lifetime may not live long enough
--> $DIR/ex2d-push-inference-variable-2.rs:8:5
--> $DIR/ex2d-push-inference-variable-2.rs:6:33
|
LL | fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
| -- -- lifetime `'c` defined here
| |
| lifetime `'b` defined here
...
LL | a.push(b);
| ^^^^^^^^^ argument requires that `'c` must outlive `'b`
LL | let a: &mut Vec<Ref<i32>> = x;
| ^ assignment requires that `'c` must outlive `'b`
|
= help: consider adding the following bound: `'c: 'b`
= note: requirement occurs because of a mutable reference to `Vec<Ref<'_, i32>>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 1 previous error

View file

@ -4,9 +4,9 @@ struct Ref<'a, T: 'a> {
fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
let a: &mut Vec<Ref<i32>> = x;
//~^ ERROR lifetime may not live long enough
let b = Ref { data: y.data };
Vec::push(a, b);
//~^ ERROR lifetime may not live long enough
}
fn main() { }

View file

@ -1,15 +1,17 @@
error: lifetime may not live long enough
--> $DIR/ex2e-push-inference-variable-3.rs:8:5
--> $DIR/ex2e-push-inference-variable-3.rs:6:33
|
LL | fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
| -- -- lifetime `'c` defined here
| |
| lifetime `'b` defined here
...
LL | Vec::push(a, b);
| ^^^^^^^^^^^^^^^ argument requires that `'c` must outlive `'b`
LL | let a: &mut Vec<Ref<i32>> = x;
| ^ assignment requires that `'c` must outlive `'b`
|
= help: consider adding the following bound: `'c: 'b`
= note: requirement occurs because of a mutable reference to `Vec<Ref<'_, i32>>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 1 previous error

View file

@ -1,6 +1,6 @@
fn foo(&mut (ref mut v, w): &mut (&u8, &u8), x: &u8) {
*v = x;
//~^ ERROR lifetime may not live long enough
*v = x;
}
fn main() { }

View file

@ -1,13 +1,15 @@
error: lifetime may not live long enough
--> $DIR/ex3-both-anon-regions-2.rs:2:5
--> $DIR/ex3-both-anon-regions-2.rs:1:14
|
LL | fn foo(&mut (ref mut v, w): &mut (&u8, &u8), x: &u8) {
| - - let's call the lifetime of this reference `'1`
| |
| let's call the lifetime of this reference `'2`
LL | *v = x;
| ^^^^^^ assignment requires that `'1` must outlive `'2`
| ^^^^^^^^^ - - let's call the lifetime of this reference `'1`
| | |
| | let's call the lifetime of this reference `'2`
| assignment requires that `'1` must outlive `'2`
|
= note: requirement occurs because of a mutable reference to `&u8`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider introducing a named lifetime parameter
|
LL | fn foo<'a>(&mut (ref mut v, w): &mut (&'a u8, &u8), x: &'a u8) {

View file

@ -8,6 +8,9 @@ LL | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
LL | z.push((x,y));
| ^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of a mutable reference to `Vec<(&u8, &u8)>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider introducing a named lifetime parameter
|
LL | fn foo<'a>(z: &mut Vec<(&'a u8,&u8)>, (x, y): (&'a u8, &u8)) {
@ -23,6 +26,9 @@ LL | fn foo(z: &mut Vec<(&u8,&u8)>, (x, y): (&u8, &u8)) {
LL | z.push((x,y));
| ^^^^^^^^^^^^^ argument requires that `'3` must outlive `'4`
|
= note: requirement occurs because of a mutable reference to `Vec<(&u8, &u8)>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider introducing a named lifetime parameter
|
LL | fn foo<'a>(z: &mut Vec<(&u8,&'a u8)>, (x, y): (&u8, &'a u8)) {

View file

@ -10,6 +10,9 @@ LL | x.push(y);
| ^^^^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of a mutable reference to `Vec<Ref<'_>>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 1 previous error

View file

@ -9,6 +9,9 @@ LL | x.push(y);
| ^^^^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of a mutable reference to `Vec<Ref<'_>>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 1 previous error

View file

@ -8,6 +8,9 @@ LL | fn foo(mut x: Vec<Ref>, y: Ref) {
LL | x.push(y);
| ^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of a mutable reference to `Vec<Ref<'_>>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider introducing a named lifetime parameter
|
LL | fn foo<'a>(mut x: Vec<Ref<'a>>, y: Ref<'a>) {

View file

@ -9,6 +9,9 @@ LL | x.push(y);
| ^^^^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of a mutable reference to `Vec<&u8>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 1 previous error

View file

@ -19,6 +19,9 @@ LL | fn foo(x:fn(&u8, &u8), y: Vec<&u8>, z: &u8) {
LL | y.push(z);
| ^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of a mutable reference to `Vec<&u8>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider introducing a named lifetime parameter
|
LL | fn foo<'a>(x:fn(&u8, &u8), y: Vec<&'a u8>, z: &'a u8) {

View file

@ -8,6 +8,9 @@ LL | fn foo(x: &mut Vec<&u8>, y: &u8) {
LL | x.push(y);
| ^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of a mutable reference to `Vec<&u8>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider introducing a named lifetime parameter and update trait if needed
|
LL | fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) {

View file

@ -19,6 +19,9 @@ LL | fn foo(x:Box<dyn Fn(&u8, &u8)> , y: Vec<&u8>, z: &u8) {
LL | y.push(z);
| ^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of a mutable reference to `Vec<&u8>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider introducing a named lifetime parameter
|
LL | fn foo<'a>(x:Box<dyn Fn(&u8, &u8)> , y: Vec<&'a u8>, z: &'a u8) {

View file

@ -8,6 +8,9 @@ LL | fn foo(x: &mut Vec<&u8>, y: &u8) {
LL | x.push(y);
| ^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of a mutable reference to `Vec<&u8>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider introducing a named lifetime parameter
|
LL | fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) {

View file

@ -1,12 +1,12 @@
error: lifetime may not live long enough
--> $DIR/match-ref-mut-invariance.rs:10:9
--> $DIR/match-ref-mut-invariance.rs:10:24
|
LL | impl<'b> S<'b> {
| -- lifetime `'b` defined here
LL | fn bar<'a>(&'a mut self) -> &'a mut &'a i32 {
| -- lifetime `'a` defined here
LL | match self.0 { ref mut x => x }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
| ^^^^^^^^^ assignment requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'a: 'b`
= note: requirement occurs because of a mutable reference to `&i32`

View file

@ -8,8 +8,8 @@ struct S<'b>(&'b i32);
impl<'b> S<'b> {
fn bar<'a>(&'a mut self) -> &'a mut &'a i32 {
let ref mut x = self.0;
x
//~^ ERROR lifetime may not live long enough
x
}
}

View file

@ -1,13 +1,12 @@
error: lifetime may not live long enough
--> $DIR/match-ref-mut-let-invariance.rs:11:9
--> $DIR/match-ref-mut-let-invariance.rs:10:13
|
LL | impl<'b> S<'b> {
| -- lifetime `'b` defined here
LL | fn bar<'a>(&'a mut self) -> &'a mut &'a i32 {
| -- lifetime `'a` defined here
LL | let ref mut x = self.0;
LL | x
| ^ method was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
| ^^^^^^^^^ assignment requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'a: 'b`
= note: requirement occurs because of a mutable reference to `&i32`

View file

@ -23,6 +23,10 @@ LL | |_outlives1, _outlives2, _outlives3, x, y| {
...
LL | demand_y(x, y, p)
| ^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of the type `Cell<&'?34 u32>`, which makes the generic argument `&'?34 u32` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
note: no external requirements
--> $DIR/propagate-approximated-fail-no-postdom.rs:38:1

View file

@ -41,9 +41,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
#[rustc_regions]
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
//~^ ERROR lifetime may not live long enough
// Only works if 'x: 'y:
demand_y(x, y, x.get())
//~^ ERROR lifetime may not live long enough
});
}

View file

@ -23,17 +23,21 @@ LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
= note: defining type: supply
error: lifetime may not live long enough
--> $DIR/propagate-approximated-ref.rs:45:9
--> $DIR/propagate-approximated-ref.rs:43:5
|
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | demand_y(x, y, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | / establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
... |
LL | | });
| |______^ argument requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'a: 'b`
= note: requirement occurs because of the type `Cell<&'?11 u32>`, which makes the generic argument `&'?11 u32` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 1 previous error

View file

@ -19,6 +19,10 @@ LL | foo(cell, |cell_a, cell_x| {
| `cell_a` declared here, outside of the closure body
LL | cell_a.set(cell_x.get()); // forces 'x: 'a, error in closure
| ^^^^^^^^^^^^^^^^^^^^^^^^ `cell_x` escapes the closure body here
|
= note: requirement occurs because of the type `Cell<&'?8 u32>`, which makes the generic argument `&'?8 u32` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
note: no external requirements
--> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:18:1
@ -56,11 +60,11 @@ error[E0597]: `a` does not live long enough
LL | let a = 0;
| - binding `a` declared here
LL | let cell = Cell::new(&a);
| ----------^^-
| | |
| | borrowed value does not live long enough
| argument requires that `a` is borrowed for `'static`
| ^^ borrowed value does not live long enough
...
LL | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error
| ------------------------ argument requires that `a` is borrowed for `'static`
LL | })
LL | }
| - `a` dropped here while still borrowed

View file

@ -30,10 +30,9 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
#[rustc_regions]
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
//~^ ERROR borrowed data escapes outside of function
// Only works if 'x: 'y:
demand_y(x, y, x.get())
//~^ ERROR borrowed data escapes outside of function
});
}

View file

@ -23,23 +23,18 @@ LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
= note: defining type: supply
error[E0521]: borrowed data escapes outside of function
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:32:5
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:34:9
|
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- ------ `cell_a` is a reference that is only valid in the function body
| |
| lifetime `'a` defined here
LL | / establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
... |
LL | | });
| | ^
| | |
| |______`cell_a` escapes the function body here
| argument requires that `'a` must outlive `'static`
|
= note: requirement occurs because of the type `Cell<&'?9 u32>`, which makes the generic argument `&'?9 u32` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- ------ `cell_a` is a reference that is only valid in the function body
| |
| lifetime `'a` defined here
...
LL | demand_y(x, y, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^
| |
| `cell_a` escapes the function body here
| argument requires that `'a` must outlive `'static`
error: aborting due to 1 previous error

View file

@ -33,10 +33,9 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3
#[rustc_regions]
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
//~^ ERROR borrowed data escapes outside of function
// Only works if 'x: 'y:
demand_y(x, y, x.get())
//~^ ERROR borrowed data escapes outside of function
});
}

View file

@ -23,23 +23,18 @@ LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
= note: defining type: supply
error[E0521]: borrowed data escapes outside of function
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:35:5
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:37:9
|
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- ------ `cell_a` is a reference that is only valid in the function body
| |
| lifetime `'a` defined here
LL | / establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
... |
LL | | });
| | ^
| | |
| |______`cell_a` escapes the function body here
| argument requires that `'a` must outlive `'static`
|
= note: requirement occurs because of the type `Cell<&'?10 u32>`, which makes the generic argument `&'?10 u32` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
LL | fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- ------ `cell_a` is a reference that is only valid in the function body
| |
| lifetime `'a` defined here
...
LL | demand_y(x, y, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^
| |
| `cell_a` escapes the function body here
| argument requires that `'a` must outlive `'static`
error: aborting due to 1 previous error

View file

@ -34,9 +34,10 @@ fn demand_y<'x, 'y>(_outlives1: Cell<&&'x u32>, _outlives2: Cell<&'y &u32>, _y:
#[rustc_regions]
fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
//~^ ERROR lifetime may not live long enough
// Only works if 'x: 'y:
demand_y(outlives1, outlives2, x.get())
//~^ ERROR lifetime may not live long enough
});
}

View file

@ -23,17 +23,21 @@ LL | fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
= note: defining type: test
error: lifetime may not live long enough
--> $DIR/propagate-approximated-val.rs:38:9
--> $DIR/propagate-approximated-val.rs:36:5
|
LL | fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | demand_y(outlives1, outlives2, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'b`
LL | fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | / establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| {
... |
LL | | });
| |______^ argument requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'a: 'b`
= note: requirement occurs because of the type `Cell<&'?7 u32>`, which makes the generic argument `&'?7 u32` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 1 previous error

View file

@ -22,6 +22,10 @@ LL | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
LL | // Only works if 'x: 'y:
LL | demand_y(x, y, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of the type `Cell<&'?37 u32>`, which makes the generic argument `&'?37 u32` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
note: no external requirements
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:34:1

View file

@ -22,6 +22,10 @@ LL | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y
LL | // Only works if 'x: 'y:
LL | demand_y(x, y, x.get())
| ^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of the type `Cell<&'?43 u32>`, which makes the generic argument `&'?43 u32` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
note: no external requirements
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:38:1

View file

@ -29,7 +29,7 @@ impl DebugWith<dyn DebugContext> for Foo {
fmt: &mut std::fmt::Formatter<'_>,
) -> std::fmt::Result {
let Foo { bar } = self;
bar.debug_with(cx); //~ ERROR: lifetime may not live long enough
bar.debug_with(cx); //~ ERROR borrowed data escapes outside of method [E0521]
Ok(())
}
}

View file

@ -1,11 +1,17 @@
error: lifetime may not live long enough
--> $DIR/issue-54779-anon-static-lifetime.rs:32:24
error[E0521]: borrowed data escapes outside of method
--> $DIR/issue-54779-anon-static-lifetime.rs:32:9
|
LL | cx: &dyn DebugContext,
| - let's call the lifetime of this reference `'1`
| -- - let's call the lifetime of this reference `'1`
| |
| `cx` is a reference that is only valid in the method body
...
LL | bar.debug_with(cx);
| ^^ coercion requires that `'1` must outlive `'static`
| ^^^^^^^^^^^^^^^^^^
| |
| `cx` escapes the method body here
| argument requires that `'1` must outlive `'static`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0521`.

View file

@ -17,10 +17,9 @@ LL | fn to_refs<T>(mut list: [&mut List<T>; 2]) -> Vec<&mut T> {
| - let's call the lifetime of this reference `'1`
...
LL | if let Some(n) = list[0].next.as_mut() {
| ^^^^^^^^^^^^---------
| |
| `list[_].next` was mutably borrowed here in the previous iteration of the loop
| argument requires that `list[_].next` is borrowed for `'1`
| ^^^^^^^^^^^^ `list[_].next` was mutably borrowed here in the previous iteration of the loop
LL | list[0] = n;
| ----------- assignment requires that `list[_].next` is borrowed for `'1`
error: aborting due to 2 previous errors

View file

@ -17,10 +17,9 @@ LL | fn to_refs<'a, T>(mut list: (&'a mut List<T>, &'a mut List<T>)) -> Vec<&'a
| -- lifetime `'a` defined here
...
LL | if let Some(n) = (list.0).next.as_mut() {
| ^^^^^^^^^^^^^---------
| |
| `list.0.next` was mutably borrowed here in the previous iteration of the loop
| argument requires that `list.0.next` is borrowed for `'a`
| ^^^^^^^^^^^^^ `list.0.next` was mutably borrowed here in the previous iteration of the loop
LL | list.1 = n;
| ---------- assignment requires that `list.0.next` is borrowed for `'a`
error: aborting due to 2 previous errors

View file

@ -12,8 +12,8 @@ struct Consumer<'tcx>(&'tcx ());
impl<'tcx> Consumer<'tcx> {
fn bad_method<'a>(&self, fcx: &FnCtxt<'a, 'tcx>) {
let other = self.use_fcx(fcx); //~ ERROR lifetime may not live long enough
fcx.use_it(other);
let other = self.use_fcx(fcx);
fcx.use_it(other); //~ ERROR lifetime may not live long enough
}
fn use_fcx<'a>(&self, _: &FnCtxt<'a, 'tcx>) -> &'a () {

View file

@ -1,14 +1,18 @@
error: lifetime may not live long enough
--> $DIR/issue-67007-escaping-data.rs:15:21
--> $DIR/issue-67007-escaping-data.rs:16:9
|
LL | impl<'tcx> Consumer<'tcx> {
| ---- lifetime `'tcx` defined here
LL | fn bad_method<'a>(&self, fcx: &FnCtxt<'a, 'tcx>) {
| -- lifetime `'a` defined here
LL | let other = self.use_fcx(fcx);
| ^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'tcx`
LL | fcx.use_it(other);
| ^^^^^^^^^^^^^^^^^ argument requires that `'a` must outlive `'tcx`
|
= help: consider adding the following bound: `'a: 'tcx`
= note: requirement occurs because of the type `FnCtxt<'_, '_>`, which makes the generic argument `'_` invariant
= note: the struct `FnCtxt<'a, 'tcx>` is invariant over the parameter `'tcx`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 1 previous error

View file

@ -8,8 +8,8 @@ where
fn test<'a, 'b>(x: Cell<&'a ()>, y: Cell<&'b ()>) {
let f = check;
//~^ ERROR lifetime may not live long enough
f(x, y);
//~^ ERROR lifetime may not live long enough
}
fn main() {}

View file

@ -1,16 +1,17 @@
error: lifetime may not live long enough
--> $DIR/issue-95272.rs:10:13
--> $DIR/issue-95272.rs:11:5
|
LL | fn test<'a, 'b>(x: Cell<&'a ()>, y: Cell<&'b ()>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | let f = check;
| ^^^^^ assignment requires that `'a` must outlive `'b`
LL | f(x, y);
| ^^^^^^^ argument requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'a: 'b`
= note: requirement occurs because of a function pointer to `check`
= note: the function `check` is invariant over the parameter `'a`
= note: requirement occurs because of the type `Cell<&()>`, which makes the generic argument `&()` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 1 previous error

View file

@ -99,6 +99,10 @@ LL | fn get_bar(&self) -> Bar2 {
| - let's call the lifetime of this reference `'1`
LL | Bar2::new(&self)
| ^^^^^^^^^^^^^^^^ argument requires that `'1` must outlive `'a`
|
= note: requirement occurs because of the type `Foo2<'_>`, which makes the generic argument `'_` invariant
= note: the struct `Foo2<'a>` is invariant over the parameter `'a`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 9 previous errors

View file

@ -17,10 +17,10 @@ LL | fn assignment_to_field_projection<'a, T>(
| -- lifetime `'a` defined here
...
LL | if let Some(n) = (list.0).next.as_mut() {
| ^^^^^^^^^^^^^---------
| |
| `list.0.next` was mutably borrowed here in the previous iteration of the loop
| argument requires that `list.0.next` is borrowed for `'a`
| ^^^^^^^^^^^^^ `list.0.next` was mutably borrowed here in the previous iteration of the loop
LL |
LL | list.1 = n;
| ---------- assignment requires that `list.0.next` is borrowed for `'a`
error[E0499]: cannot borrow `list.0.0.0.0.0.value` as mutable more than once at a time
--> $DIR/assignment-to-differing-field.rs:37:21
@ -41,10 +41,10 @@ LL | fn assignment_through_projection_chain<'a, T>(
| -- lifetime `'a` defined here
...
LL | if let Some(n) = ((((list.0).0).0).0).0.next.as_mut() {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^---------
| |
| `list.0.0.0.0.0.next` was mutably borrowed here in the previous iteration of the loop
| argument requires that `list.0.0.0.0.0.next` is borrowed for `'a`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `list.0.0.0.0.0.next` was mutably borrowed here in the previous iteration of the loop
LL |
LL | *((((list.0).0).0).0).1 = n;
| --------------------------- assignment requires that `list.0.0.0.0.0.next` is borrowed for `'a`
error: aborting due to 4 previous errors

View file

@ -1,23 +1,20 @@
error[E0597]: `a` does not live long enough
--> $DIR/location-insensitive-scopes-issue-117146.rs:10:18
error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function
--> $DIR/location-insensitive-scopes-issue-117146.rs:10:13
|
LL | let a = ();
| - binding `a` declared here
LL | let b = |_| &a;
| --- -^
| | ||
| | |borrowed value does not live long enough
| | returning this value requires that `a` is borrowed for `'static`
| value captured here
...
LL | }
| - `a` dropped here while still borrowed
| ^^^ - `a` is borrowed here
| |
| may outlive borrowed value `a`
|
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
--> $DIR/location-insensitive-scopes-issue-117146.rs:20:22
note: function requires argument type to outlive `'static`
--> $DIR/location-insensitive-scopes-issue-117146.rs:13:5
|
LL | fn bad<F: Fn(&()) -> &()>(_: F) {}
| ^^^
LL | bad(&b);
| ^^^^^^^
help: to force the closure to take ownership of `a` (and any other referenced variables), use the `move` keyword
|
LL | let b = move |_| &a;
| ++++
error: implementation of `Fn` is not general enough
--> $DIR/location-insensitive-scopes-issue-117146.rs:13:5
@ -39,4 +36,4 @@ LL | bad(&b);
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0597`.
For more information about this error, try `rustc --explain E0373`.

View file

@ -1,23 +1,20 @@
error[E0597]: `a` does not live long enough
--> $DIR/location-insensitive-scopes-issue-117146.rs:10:18
error[E0373]: closure may outlive the current function, but it borrows `a`, which is owned by the current function
--> $DIR/location-insensitive-scopes-issue-117146.rs:10:13
|
LL | let a = ();
| - binding `a` declared here
LL | let b = |_| &a;
| --- -^
| | ||
| | |borrowed value does not live long enough
| | returning this value requires that `a` is borrowed for `'static`
| value captured here
...
LL | }
| - `a` dropped here while still borrowed
| ^^^ - `a` is borrowed here
| |
| may outlive borrowed value `a`
|
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
--> $DIR/location-insensitive-scopes-issue-117146.rs:20:22
note: function requires argument type to outlive `'static`
--> $DIR/location-insensitive-scopes-issue-117146.rs:13:5
|
LL | fn bad<F: Fn(&()) -> &()>(_: F) {}
| ^^^
LL | bad(&b);
| ^^^^^^^
help: to force the closure to take ownership of `a` (and any other referenced variables), use the `move` keyword
|
LL | let b = move |_| &a;
| ++++
error: implementation of `Fn` is not general enough
--> $DIR/location-insensitive-scopes-issue-117146.rs:13:5
@ -39,4 +36,4 @@ LL | bad(&b);
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0597`.
For more information about this error, try `rustc --explain E0373`.

View file

@ -8,8 +8,8 @@
fn main() {
let a = ();
let b = |_| &a;
//[nll]~^ ERROR `a` does not live long enough
//[polonius]~^^ ERROR `a` does not live long enough
//[nll]~^ ERROR closure may outlive the current function, but it borrows `a`
//[polonius]~^^ ERROR closure may outlive the current function, but it borrows `a`
bad(&b);
//[nll]~^ ERROR implementation of `Fn`
//[nll]~| ERROR implementation of `FnOnce`

View file

@ -5,9 +5,10 @@ LL | let b = 44;
| - binding `b` declared here
...
LL | let x: DoubleCell<_> = make_cell(&b);
| ------------- ^^ borrowed value does not live long enough
| |
| type annotation requires that `b` is borrowed for `'static`
| ----------^^-
| | |
| | borrowed value does not live long enough
| assignment requires that `b` is borrowed for `'static`
...
LL | }
| - `b` dropped here while still borrowed

View file

@ -24,6 +24,22 @@ LL | | T: Anything<'b>,
|
= note: defining type: no_relationships_late::<'?1, T>
error: lifetime may not live long enough
--> $DIR/projection-one-region-closure.rs:45:5
|
LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of the type `Cell<&'?6 ()>`, which makes the generic argument `&'?6 ()` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error[E0309]: the parameter type `T` may not live long enough
--> $DIR/projection-one-region-closure.rs:45:39
|
@ -38,19 +54,6 @@ help: consider adding an explicit lifetime bound
LL | T: Anything<'b> + 'a,
| ++++
error: lifetime may not live long enough
--> $DIR/projection-one-region-closure.rs:45:39
|
LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
note: external requirements
--> $DIR/projection-one-region-closure.rs:56:29
|
@ -77,6 +80,22 @@ LL | | 'a: 'a,
|
= note: defining type: no_relationships_early::<'?1, '?2, T>
error: lifetime may not live long enough
--> $DIR/projection-one-region-closure.rs:56:5
|
LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of the type `Cell<&'?7 ()>`, which makes the generic argument `&'?7 ()` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error[E0309]: the parameter type `T` may not live long enough
--> $DIR/projection-one-region-closure.rs:56:39
|
@ -91,19 +110,6 @@ help: consider adding an explicit lifetime bound
LL | T: Anything<'b> + 'a,
| ++++
error: lifetime may not live long enough
--> $DIR/projection-one-region-closure.rs:56:39
|
LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
...
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
note: external requirements
--> $DIR/projection-one-region-closure.rs:70:29
|

View file

@ -24,7 +24,7 @@ LL | | T: Anything<'b>,
= note: defining type: no_relationships_late::<'?1, T>
error: lifetime may not live long enough
--> $DIR/projection-one-region-trait-bound-closure.rs:37:39
--> $DIR/projection-one-region-trait-bound-closure.rs:37:5
|
LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| -- -- lifetime `'b` defined here
@ -32,9 +32,12 @@ LL | fn no_relationships_late<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| lifetime `'a` defined here
...
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of the type `Cell<&'?6 ()>`, which makes the generic argument `&'?6 ()` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
note: external requirements
--> $DIR/projection-one-region-trait-bound-closure.rs:47:29
@ -62,7 +65,7 @@ LL | | 'a: 'a,
= note: defining type: no_relationships_early::<'?1, '?2, T>
error: lifetime may not live long enough
--> $DIR/projection-one-region-trait-bound-closure.rs:47:39
--> $DIR/projection-one-region-trait-bound-closure.rs:47:5
|
LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| -- -- lifetime `'b` defined here
@ -70,9 +73,12 @@ LL | fn no_relationships_early<'a, 'b, T>(cell: Cell<&'a ()>, t: T)
| lifetime `'a` defined here
...
LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of the type `Cell<&'?7 ()>`, which makes the generic argument `&'?7 ()` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
note: external requirements
--> $DIR/projection-one-region-trait-bound-closure.rs:60:29

View file

@ -182,7 +182,7 @@ LL | with_signature(cell, t, |cell, t| require(cell, t));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ argument requires that `'b` must outlive `'a`
|
= help: consider adding the following bound: `'b: 'a`
= note: requirement occurs because of the type `Cell<&'?8 ()>`, which makes the generic argument `&'?8 ()` invariant
= note: requirement occurs because of the type `Cell<&'?6 ()>`, which makes the generic argument `&'?6 ()` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance

View file

@ -1,52 +1,49 @@
error[E0597]: `c` does not live long enough
--> $DIR/adt-nullary-enums.rs:33:41
|
LL | let c = 66;
| - binding `c` declared here
LL | combine(
LL | SomeEnum::SomeVariant(Cell::new(&c)),
| ----------^^-
| | |
| | borrowed value does not live long enough
| argument requires that `c` is borrowed for `'static`
...
LL | }
| - `c` dropped here while still borrowed
LL | let c = 66;
| - binding `c` declared here
LL | / combine(
LL | | SomeEnum::SomeVariant(Cell::new(&c)),
| | ^^ borrowed value does not live long enough
LL | | SomeEnum::SomeOtherVariant::<Cell<&'static u32>>,
LL | | );
| |_____- argument requires that `c` is borrowed for `'static`
LL | }
| - `c` dropped here while still borrowed
error[E0597]: `c` does not live long enough
--> $DIR/adt-nullary-enums.rs:41:41
|
LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
| -- lifetime `'a` defined here
LL | let c = 66;
| - binding `c` declared here
LL | combine(
LL | SomeEnum::SomeVariant(Cell::new(&c)),
| ----------^^-
| | |
| | borrowed value does not live long enough
| argument requires that `c` is borrowed for `'a`
...
LL | }
| - `c` dropped here while still borrowed
LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
| -- lifetime `'a` defined here
LL | let c = 66;
| - binding `c` declared here
LL | / combine(
LL | | SomeEnum::SomeVariant(Cell::new(&c)),
| | ^^ borrowed value does not live long enough
LL | | SomeEnum::SomeOtherVariant::<Cell<&'a u32>>,
LL | | );
| |_____- argument requires that `c` is borrowed for `'a`
LL | }
| - `c` dropped here while still borrowed
error[E0597]: `c` does not live long enough
--> $DIR/adt-nullary-enums.rs:54:45
|
LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
| -- lifetime `'a` defined here
LL | let _closure = || {
LL | let c = 66;
| - binding `c` declared here
LL | combine(
LL | SomeEnum::SomeVariant(Cell::new(&c)),
| ----------^^-
| | |
| | borrowed value does not live long enough
| argument requires that `c` is borrowed for `'a`
...
LL | };
| - `c` dropped here while still borrowed
LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) {
| -- lifetime `'a` defined here
LL | let _closure = || {
LL | let c = 66;
| - binding `c` declared here
LL | / combine(
LL | | SomeEnum::SomeVariant(Cell::new(&c)),
| | ^^ borrowed value does not live long enough
LL | | SomeEnum::SomeOtherVariant::<Cell<&'a u32>>,
LL | | );
| |_________- argument requires that `c` is borrowed for `'a`
LL | };
| - `c` dropped here while still borrowed
error: aborting due to 3 previous errors

View file

@ -4,11 +4,9 @@ error[E0597]: `c` does not live long enough
LL | let c = 66;
| - binding `c` declared here
LL | let f = SomeStruct::<&'static u32>;
| -------------------------- assignment requires that `c` is borrowed for `'static`
LL | f(&c);
| --^^-
| | |
| | borrowed value does not live long enough
| argument requires that `c` is borrowed for `'static`
| ^^ borrowed value does not live long enough
LL | }
| - `c` dropped here while still borrowed
@ -20,11 +18,9 @@ LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) {
LL | let c = 66;
| - binding `c` declared here
LL | let f = SomeStruct::<&'a u32>;
| --------------------- assignment requires that `c` is borrowed for `'a`
LL | f(&c);
| --^^-
| | |
| | borrowed value does not live long enough
| argument requires that `c` is borrowed for `'a`
| ^^ borrowed value does not live long enough
LL | }
| - `c` dropped here while still borrowed
@ -37,11 +33,9 @@ LL | let _closure = || {
LL | let c = 66;
| - binding `c` declared here
LL | let f = SomeStruct::<&'a u32>;
| --------------------- assignment requires that `c` is borrowed for `'a`
LL | f(&c);
| --^^-
| | |
| | borrowed value does not live long enough
| argument requires that `c` is borrowed for `'a`
| ^^ borrowed value does not live long enough
LL | };
| - `c` dropped here while still borrowed

View file

@ -4,11 +4,10 @@ error[E0597]: `a` does not live long enough
LL | let a = 22;
| - binding `a` declared here
...
LL | let x = <&'static u32 as Bazoom<_>>::method;
| ----------------------------------- assignment requires that `a` is borrowed for `'static`
LL | x(&a, b, c);
| --^^-------
| | |
| | borrowed value does not live long enough
| argument requires that `a` is borrowed for `'static`
| ^^ borrowed value does not live long enough
LL | }
| - `a` dropped here while still borrowed

View file

@ -4,11 +4,10 @@ error[E0597]: `a` does not live long enough
LL | let a = 22;
| - binding `a` declared here
...
LL | let x = <&'static u32 as Bazoom<_>>::method;
| ----------------------------------- assignment requires that `a` is borrowed for `'static`
LL | x(&a, b, c);
| --^^-------
| | |
| | borrowed value does not live long enough
| argument requires that `a` is borrowed for `'static`
| ^^ borrowed value does not live long enough
LL | }
| - `a` dropped here while still borrowed

View file

@ -1,12 +1,12 @@
error: lifetime may not live long enough
--> $DIR/where_clauses_in_structs.rs:11:11
--> $DIR/where_clauses_in_structs.rs:11:14
|
LL | fn bar<'a, 'b>(x: Cell<&'a u32>, y: Cell<&'b u32>) {
| -- -- lifetime `'b` defined here
| |
| lifetime `'a` defined here
LL | Foo { x, y };
| ^ this usage requires that `'a` must outlive `'b`
| ^ this usage requires that `'a` must outlive `'b`
|
= help: consider adding the following bound: `'a: 'b`
= note: requirement occurs because of the type `Cell<&u32>`, which makes the generic argument `&u32` invariant

View file

@ -0,0 +1,13 @@
//! diagnostic test for #132749: ensure we pick a decent span and reason to blame for region errors
//! when failing to prove a region outlives 'static
struct Bytes(&'static [u8]);
fn deserialize_simple_string(buf: &[u8]) -> (Bytes, &[u8]) {
//~^ NOTE let's call the lifetime of this reference `'1`
let (s, rest) = buf.split_at(2);
(Bytes(s), rest) //~ ERROR lifetime may not live long enough
//~| NOTE this usage requires that `'1` must outlive `'static`
}
fn main() {}

View file

@ -0,0 +1,11 @@
error: lifetime may not live long enough
--> $DIR/better-blame-constraint-for-outlives-static.rs:9:12
|
LL | fn deserialize_simple_string(buf: &[u8]) -> (Bytes, &[u8]) {
| - let's call the lifetime of this reference `'1`
...
LL | (Bytes(s), rest)
| ^ this usage requires that `'1` must outlive `'static`
error: aborting due to 1 previous error

View file

@ -25,6 +25,10 @@ LL | self.enter_scope(|ctx| {
| has type `&mut FooImpl<'2, '_, T>`
LL | BarImpl(ctx);
| ^^^ this usage requires that `'1` must outlive `'2`
|
= note: requirement occurs because of a mutable reference to `FooImpl<'_, '_, T>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: lifetime may not live long enough
--> $DIR/lifetime-not-long-enough-suggestion-regression-test-124563.rs:22:9

View file

@ -3,7 +3,7 @@
// over time, but this test used to exhibit some pretty bogus messages
// that were not remotely helpful.
//@ error-pattern:argument requires that `'a` must outlive `'static`
//@ error-pattern:requires that `'a` must outlive `'static`
struct Invariant<'a>(Option<&'a mut &'a mut ()>);
@ -11,9 +11,9 @@ fn mk_static() -> Invariant<'static> { Invariant(None) }
fn unify<'a>(x: Option<Invariant<'a>>, f: fn(Invariant<'a>)) {
let bad = if x.is_some() {
x.unwrap() //~ ERROR borrowed data escapes outside of function [E0521]
x.unwrap()
} else {
mk_static()
mk_static() //~ ERROR lifetime may not live long enough
};
f(bad);
}

View file

@ -1,16 +1,11 @@
error[E0521]: borrowed data escapes outside of function
--> $DIR/region-invariant-static-error-reporting.rs:14:9
error: lifetime may not live long enough
--> $DIR/region-invariant-static-error-reporting.rs:16:9
|
LL | fn unify<'a>(x: Option<Invariant<'a>>, f: fn(Invariant<'a>)) {
| -- - `x` is a reference that is only valid in the function body
| |
| lifetime `'a` defined here
LL | let bad = if x.is_some() {
LL | x.unwrap()
| ^^^^^^^^^^
| |
| `x` escapes the function body here
| argument requires that `'a` must outlive `'static`
| -- lifetime `'a` defined here
...
LL | mk_static()
| ^^^^^^^^^^^ assignment requires that `'a` must outlive `'static`
|
= note: requirement occurs because of the type `Invariant<'_>`, which makes the generic argument `'_` invariant
= note: the struct `Invariant<'a>` is invariant over the parameter `'a`
@ -18,4 +13,3 @@ LL | x.unwrap()
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0521`.

View file

@ -64,7 +64,7 @@ mod bay {
fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32> + 'a>) -> &'a () {
val.use_self()
//~^ ERROR: cannot return value referencing function parameter `val`
//~^ ERROR: `val` does not live long enough
//~| ERROR: borrowed data escapes outside of function
}
}

View file

@ -25,6 +25,20 @@ LL | val.use_self()
| returns a value referencing data owned by the current function
| `val` is borrowed here
error[E0597]: `val` does not live long enough
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:66:9
|
LL | fn use_it<'a>(val: Box<dyn ObjectTrait<Assoc = i32> + 'a>) -> &'a () {
| --- binding `val` declared here
LL | val.use_self()
| ^^^-----------
| |
| borrowed value does not live long enough
| argument requires that `val` is borrowed for `'static`
...
LL | }
| - `val` dropped here while still borrowed
error[E0521]: borrowed data escapes outside of function
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:66:9
|
@ -50,15 +64,6 @@ help: consider relaxing the implicit `'static` requirement
LL | impl MyTrait for Box<dyn ObjectTrait<Assoc = i32> + '_> {
| ++++
error[E0515]: cannot return value referencing function parameter `val`
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:66:9
|
LL | val.use_self()
| ---^^^^^^^^^^^
| |
| returns a value referencing data owned by the current function
| `val` is borrowed here
error[E0515]: cannot return value referencing function parameter `val`
--> $DIR/impl-on-dyn-trait-with-implicit-static-bound-needing-more-suggestions.rs:90:9
|
@ -70,5 +75,5 @@ LL | val.use_self()
error: aborting due to 6 previous errors
Some errors have detailed explanations: E0515, E0521.
Some errors have detailed explanations: E0515, E0521, E0597.
For more information about an error, try `rustc --explain E0515`.

View file

@ -4,11 +4,9 @@ error[E0597]: `person` does not live long enough
LL | let person = "Fred".to_string();
| ------ binding `person` declared here
LL | let person: &str = &person;
| ^^^^^^^
| |
| borrowed value does not live long enough
| assignment requires that `person` is borrowed for `'static`
| ^^^^^^^ borrowed value does not live long enough
LL | let s: Box<dyn Trait<&'static str>> = Box::new(Struct { person: person });
| ------ this usage requires that `person` is borrowed for `'static`
LL | }
| - `person` dropped here while still borrowed

View file

@ -6,9 +6,8 @@ fn main() {
let local = 0; //~ NOTE binding `local` declared here
let r = &local; //~ ERROR `local` does not live long enough
//~| NOTE borrowed value does not live long enough
//~| NOTE due to object lifetime defaults, `Box<dyn A>` actually means `Box<(dyn A + 'static)>`
require_box(Box::new(r));
//~^ NOTE coercion requires that `local` is borrowed for `'static`
//~^ NOTE argument requires that `local` is borrowed for `'static`
let _ = 0;
} //~ NOTE `local` dropped here while still borrowed

View file

@ -5,14 +5,12 @@ LL | let local = 0;
| ----- binding `local` declared here
LL | let r = &local;
| ^^^^^^ borrowed value does not live long enough
...
LL |
LL | require_box(Box::new(r));
| ----------- coercion requires that `local` is borrowed for `'static`
| ------------------------ argument requires that `local` is borrowed for `'static`
...
LL | }
| - `local` dropped here while still borrowed
|
= note: due to object lifetime defaults, `Box<dyn A>` actually means `Box<(dyn A + 'static)>`
error: aborting due to 1 previous error

View file

@ -1,10 +1,10 @@
error: lifetime may not live long enough
--> $DIR/type-checking-test-3.rs:11:18
--> $DIR/type-checking-test-3.rs:11:13
|
LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) {
| -- lifetime `'a` defined here
LL | let _ = x as &dyn Bar<'a>; // Error
| ^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
| ^^^^^^^^^^^^^^^^^ cast requires that `'a` must outlive `'static`
error: lifetime may not live long enough
--> $DIR/type-checking-test-3.rs:16:18

View file

@ -1,10 +1,10 @@
error: lifetime may not live long enough
--> $DIR/type-checking-test-4.rs:19:18
--> $DIR/type-checking-test-4.rs:19:13
|
LL | fn test_wrong1<'a>(x: &dyn Foo<'static>, y: &'a u32) {
| -- lifetime `'a` defined here
LL | let _ = x as &dyn Bar<'static, 'a>; // Error
| ^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cast requires that `'a` must outlive `'static`
error: lifetime may not live long enough
--> $DIR/type-checking-test-4.rs:24:18

View file

@ -7,6 +7,10 @@ LL | doit(0, &|x, y| {
| has type `&Cell<&'2 i32>`
LL | x.set(y);
| ^^^^^^^^ argument requires that `'1` must outlive `'2`
|
= note: requirement occurs because of the type `Cell<&i32>`, which makes the generic argument `&i32` invariant
= note: the struct `Cell<T>` is invariant over the parameter `T`
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
error: aborting due to 1 previous error

View file

@ -7,6 +7,9 @@ LL | fn foo(x: &mut Vec<&'_ u8>, y: &'_ u8) { x.push(y); }
| | let's call the lifetime of this reference `'1`
| let's call the lifetime of this reference `'2`
|
= note: requirement occurs because of a mutable reference to `Vec<&u8>`
= note: mutable references are invariant over their type parameter
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
help: consider introducing a named lifetime parameter
|
LL | fn foo<'a>(x: &mut Vec<&'a u8>, y: &'a u8) { x.push(y); }

View file

@ -1,10 +1,10 @@
error: lifetime may not live long enough
--> $DIR/variance-associated-types2.rs:13:12
--> $DIR/variance-associated-types2.rs:13:42
|
LL | fn take<'a>(_: &'a u32) {
| -- lifetime `'a` defined here
LL | let _: Box<dyn Foo<Bar = &'a u32>> = make();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
| ^^^^^^ coercion requires that `'a` must outlive `'static`
error: aborting due to 1 previous error

View file

@ -7,7 +7,7 @@ LL | fn get_min_from_max<'min, 'max>(v: Box<dyn Get<&'max i32>>)
| lifetime `'min` defined here
...
LL | v
| ^ function was supposed to return data with lifetime `'max` but it is returning data with lifetime `'min`
| ^ coercion requires that `'min` must outlive `'max`
|
= help: consider adding the following bound: `'min: 'max`

Some files were not shown because too many files have changed in this diff Show more