best_blame_constraint: avoid blaming assignments without user-provided types
This commit is contained in:
parent
31e4d8175a
commit
50222dba2e
19 changed files with 88 additions and 64 deletions
|
|
@ -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 ()>, //~ ERROR lifetime may not live long enough
|
||||
true => foo::<&'c ()>,
|
||||
false => foo::<&'a ()>, //~ ERROR lifetime may not live long enough
|
||||
};
|
||||
|
||||
x(a);
|
||||
x(b);
|
||||
x(b); //~ ERROR lifetime may not live long enough
|
||||
x(c);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 `'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
|
||||
|
|
@ -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 `'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
|
||||
|
|
@ -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 `'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
|
||||
|
|
@ -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 `'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
|
||||
|
|
@ -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 `'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
|
||||
|
|
@ -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 `'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
|
||||
|
|
@ -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:49:17
|
||||
--> $DIR/fn_def_coercion.rs:50:18
|
||||
|
|
||||
LL | fn k<'a, 'b, 'c: 'a + 'b>(a: &'a (), b: &'b (), c: &'c ()) {
|
||||
| -- -- lifetime `'c` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
LL | let x = match true {
|
||||
LL | true => foo::<&'c ()>,
|
||||
| ^^^^^^^^^^^^^ assignment requires that `'a` must outlive `'c`
|
||||
...
|
||||
LL | false => foo::<&'a ()>,
|
||||
| ^^^^^^^^^^^^^ 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,20 +133,17 @@ LL | true => foo::<&'c ()>,
|
|||
= 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:50:18
|
||||
--> $DIR/fn_def_coercion.rs:54:5
|
||||
|
|
||||
LL | fn k<'a, 'b, 'c: 'a + 'b>(a: &'a (), b: &'b (), c: &'c ()) {
|
||||
| -- -- lifetime `'b` defined here
|
||||
| |
|
||||
| lifetime `'a` defined here
|
||||
...
|
||||
LL | false => foo::<&'a ()>,
|
||||
| ^^^^^^^^^^^^^ assignment requires that `'b` must outlive `'a`
|
||||
LL | x(b);
|
||||
| ^^^^ argument 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
|
||||
|
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
fn foo(&mut (ref mut v, w): &mut (&u8, &u8), x: &u8) {
|
||||
//~^ ERROR lifetime may not live long enough
|
||||
*v = x;
|
||||
//~^ ERROR lifetime may not live long enough
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
|
|
|
|||
|
|
@ -1,15 +1,13 @@
|
|||
error: lifetime may not live long enough
|
||||
--> $DIR/ex3-both-anon-regions-2.rs:1:14
|
||||
--> $DIR/ex3-both-anon-regions-2.rs:2:5
|
||||
|
|
||||
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`
|
||||
| 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`
|
||||
LL | *v = x;
|
||||
| ^^^^^^ 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) {
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
error: lifetime may not live long enough
|
||||
--> $DIR/match-ref-mut-invariance.rs:10:24
|
||||
--> $DIR/match-ref-mut-invariance.rs:10:9
|
||||
|
|
||||
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 }
|
||||
| ^^^^^^^^^ assignment requires that `'a` must outlive `'b`
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ method was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
|
||||
|
|
||||
= help: consider adding the following bound: `'a: 'b`
|
||||
= note: requirement occurs because of a mutable reference to `&i32`
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
//~^ ERROR lifetime may not live long enough
|
||||
x
|
||||
//~^ ERROR lifetime may not live long enough
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
error: lifetime may not live long enough
|
||||
--> $DIR/match-ref-mut-let-invariance.rs:10:13
|
||||
--> $DIR/match-ref-mut-let-invariance.rs:11:9
|
||||
|
|
||||
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;
|
||||
| ^^^^^^^^^ assignment requires that `'a` must outlive `'b`
|
||||
LL | x
|
||||
| ^ method was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a`
|
||||
|
|
||||
= help: consider adding the following bound: `'a: 'b`
|
||||
= note: requirement occurs because of a mutable reference to `&i32`
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ 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
|
||||
| --^^-
|
||||
| | |
|
||||
| | borrowed value does not live long enough
|
||||
| argument requires that `c` is borrowed for `'static`
|
||||
LL | }
|
||||
| - `c` dropped here while still borrowed
|
||||
|
||||
|
|
@ -18,9 +20,11 @@ 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
|
||||
| --^^-
|
||||
| | |
|
||||
| | borrowed value does not live long enough
|
||||
| argument requires that `c` is borrowed for `'a`
|
||||
LL | }
|
||||
| - `c` dropped here while still borrowed
|
||||
|
||||
|
|
@ -33,9 +37,11 @@ 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
|
||||
| --^^-
|
||||
| | |
|
||||
| | borrowed value does not live long enough
|
||||
| argument requires that `c` is borrowed for `'a`
|
||||
LL | };
|
||||
| - `c` dropped here while still borrowed
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ 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
|
||||
| --^^-------
|
||||
| | |
|
||||
| | borrowed value does not live long enough
|
||||
| argument requires that `a` is borrowed for `'static`
|
||||
LL | }
|
||||
| - `a` dropped here while still borrowed
|
||||
|
||||
|
|
|
|||
|
|
@ -4,10 +4,11 @@ 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
|
||||
| --^^-------
|
||||
| | |
|
||||
| | borrowed value does not live long enough
|
||||
| argument requires that `a` is borrowed for `'static`
|
||||
LL | }
|
||||
| - `a` dropped here while still borrowed
|
||||
|
||||
|
|
|
|||
|
|
@ -6,9 +6,11 @@ LL | fn foo<'a>() {
|
|||
LL | let x = 0;
|
||||
| - binding `x` declared here
|
||||
LL | let f = &drop::<&'a i32>;
|
||||
| ---------------- assignment requires that `x` is borrowed for `'a`
|
||||
LL | f(&x);
|
||||
| ^^ borrowed value does not live long enough
|
||||
| --^^-
|
||||
| | |
|
||||
| | borrowed value does not live long enough
|
||||
| argument requires that `x` is borrowed for `'a`
|
||||
LL |
|
||||
LL | }
|
||||
| - `x` dropped here while still borrowed
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue