propagate user-ascribes types down onto resulting bindings
But only in very simple cases.
This commit is contained in:
parent
a8710539cb
commit
e87bf30f5f
14 changed files with 171 additions and 35 deletions
|
|
@ -3,10 +3,41 @@
|
|||
#![feature(nll)]
|
||||
|
||||
fn variable_no_initializer() {
|
||||
// FIXME: It is unclear to me whether this should be an error or not.
|
||||
|
||||
let x = 22;
|
||||
let y: &'static u32;
|
||||
y = &x; //~ ERROR
|
||||
}
|
||||
|
||||
fn tuple_no_initializer() {
|
||||
// FIXME(#47187): We are not propagating ascribed type through tuples.
|
||||
|
||||
let x = 22;
|
||||
let (y, z): (&'static u32, &'static u32);
|
||||
y = &x;
|
||||
}
|
||||
|
||||
fn ref_with_ascribed_static_type() -> u32 {
|
||||
// Check the behavior in some wacky cases.
|
||||
let x = 22;
|
||||
let y = &x; //~ ERROR
|
||||
let ref z: &'static u32 = y; //~ ERROR
|
||||
**z
|
||||
}
|
||||
|
||||
fn ref_with_ascribed_any_type() -> u32 {
|
||||
let x = 22;
|
||||
let y = &x;
|
||||
let ref z: &u32 = y;
|
||||
**z
|
||||
}
|
||||
|
||||
struct Single<T> { value: T }
|
||||
|
||||
fn struct_no_initializer() {
|
||||
// FIXME(#47187): We are not propagating ascribed type through patterns.
|
||||
|
||||
let x = 22;
|
||||
let Single { value: y }: Single<&'static u32>;
|
||||
y = &x;
|
||||
}
|
||||
|
||||
|
|
@ -39,8 +70,6 @@ fn pair_variable_with_initializer() {
|
|||
let (y, _): (&'static u32, u32) = (&x, 44); //~ ERROR
|
||||
}
|
||||
|
||||
struct Single<T> { value: T }
|
||||
|
||||
fn struct_single_field_variable_with_initializer() {
|
||||
let x = 22;
|
||||
let Single { value: y }: Single<&'static u32> = Single { value: &x }; //~ ERROR
|
||||
|
|
@ -73,7 +102,7 @@ fn static_to_a_to_static_through_variable<'a>(x: &'a u32) -> &'static u32 {
|
|||
}
|
||||
|
||||
fn static_to_a_to_static_through_tuple<'a>(x: &'a u32) -> &'static u32 {
|
||||
// FIXME: The fact that this type-checks is perhaps surprising.
|
||||
// FIXME(#47187): The fact that this type-checks is perhaps surprising.
|
||||
// What happens is that the right-hand side is constrained to have
|
||||
// type `&'a u32`, which is possible, because it has type
|
||||
// `&'static u32`. The variable `y` is then forced to have type
|
||||
|
|
|
|||
|
|
@ -1,5 +1,37 @@
|
|||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/patterns.rs:15:27
|
||||
--> $DIR/patterns.rs:8:9
|
||||
|
|
||||
LL | y = &x; //~ ERROR
|
||||
| ^^ borrowed value does not live long enough
|
||||
LL | }
|
||||
| - `x` dropped here while still borrowed
|
||||
|
|
||||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/patterns.rs:22:13
|
||||
|
|
||||
LL | let y = &x; //~ ERROR
|
||||
| ^^ borrowed value does not live long enough
|
||||
...
|
||||
LL | }
|
||||
| - `x` dropped here while still borrowed
|
||||
|
|
||||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: `y` does not live long enough
|
||||
--> $DIR/patterns.rs:23:9
|
||||
|
|
||||
LL | let ref z: &'static u32 = y; //~ ERROR
|
||||
| ^^^^^ borrowed value does not live long enough
|
||||
LL | **z
|
||||
LL | }
|
||||
| - `y` dropped here while still borrowed
|
||||
|
|
||||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/patterns.rs:46:27
|
||||
|
|
||||
LL | let y: &'static u32 = &x; //~ ERROR
|
||||
| ^^ borrowed value does not live long enough
|
||||
|
|
@ -9,7 +41,7 @@ LL | }
|
|||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/patterns.rs:20:27
|
||||
--> $DIR/patterns.rs:51:27
|
||||
|
|
||||
LL | let _: &'static u32 = &x; //~ ERROR
|
||||
| ^^ borrowed value does not live long enough
|
||||
|
|
@ -20,7 +52,7 @@ LL | }
|
|||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: borrowed value does not live long enough
|
||||
--> $DIR/patterns.rs:22:41
|
||||
--> $DIR/patterns.rs:53:41
|
||||
|
|
||||
LL | let _: Vec<&'static String> = vec![&String::new()];
|
||||
| ^^^^^^^^^^^^^ - temporary value only lives until here
|
||||
|
|
@ -30,7 +62,7 @@ LL | let _: Vec<&'static String> = vec![&String::new()];
|
|||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: borrowed value does not live long enough
|
||||
--> $DIR/patterns.rs:25:52
|
||||
--> $DIR/patterns.rs:56:52
|
||||
|
|
||||
LL | let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44);
|
||||
| ^^^^^^^^^^^^^ - temporary value only lives until here
|
||||
|
|
@ -40,7 +72,7 @@ LL | let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44);
|
|||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: borrowed value does not live long enough
|
||||
--> $DIR/patterns.rs:28:53
|
||||
--> $DIR/patterns.rs:59:53
|
||||
|
|
||||
LL | let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44);
|
||||
| ^^^^^^^^^^^^^ - temporary value only lives until here
|
||||
|
|
@ -50,7 +82,7 @@ LL | let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44);
|
|||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/patterns.rs:34:40
|
||||
--> $DIR/patterns.rs:65:40
|
||||
|
|
||||
LL | let (_, _): (&'static u32, u32) = (&x, 44); //~ ERROR
|
||||
| ^^ borrowed value does not live long enough
|
||||
|
|
@ -60,7 +92,7 @@ LL | }
|
|||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/patterns.rs:39:40
|
||||
--> $DIR/patterns.rs:70:40
|
||||
|
|
||||
LL | let (y, _): (&'static u32, u32) = (&x, 44); //~ ERROR
|
||||
| ^^ borrowed value does not live long enough
|
||||
|
|
@ -70,7 +102,7 @@ LL | }
|
|||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/patterns.rs:46:69
|
||||
--> $DIR/patterns.rs:75:69
|
||||
|
|
||||
LL | let Single { value: y }: Single<&'static u32> = Single { value: &x }; //~ ERROR
|
||||
| ^^ borrowed value does not live long enough
|
||||
|
|
@ -80,7 +112,7 @@ LL | }
|
|||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/patterns.rs:51:69
|
||||
--> $DIR/patterns.rs:80:69
|
||||
|
|
||||
LL | let Single { value: _ }: Single<&'static u32> = Single { value: &x }; //~ ERROR
|
||||
| ^^ borrowed value does not live long enough
|
||||
|
|
@ -90,7 +122,7 @@ LL | }
|
|||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error[E0597]: `x` does not live long enough
|
||||
--> $DIR/patterns.rs:59:17
|
||||
--> $DIR/patterns.rs:88:17
|
||||
|
|
||||
LL | value1: &x, //~ ERROR
|
||||
| ^^ borrowed value does not live long enough
|
||||
|
|
@ -101,7 +133,7 @@ LL | }
|
|||
= note: borrowed value must be valid for the static lifetime...
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/patterns.rs:72:5
|
||||
--> $DIR/patterns.rs:101:5
|
||||
|
|
||||
LL | fn static_to_a_to_static_through_variable<'a>(x: &'a u32) -> &'static u32 {
|
||||
| -- lifetime `'a` defined here
|
||||
|
|
@ -110,13 +142,13 @@ LL | y //~ ERROR
|
|||
| ^ returning this value requires that `'a` must outlive `'static`
|
||||
|
||||
error: unsatisfied lifetime constraints
|
||||
--> $DIR/patterns.rs:88:40
|
||||
--> $DIR/patterns.rs:117:40
|
||||
|
|
||||
LL | fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 {
|
||||
| -- lifetime `'a` defined here
|
||||
LL | let (y, _z): (&'static u32, u32) = (x, 44); //~ ERROR
|
||||
| ^^^^^^^ requires that `'a` must outlive `'static`
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
error: aborting due to 15 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0597`.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue