As a drive-by, also added test analogous to existing
static_to_a_to_static_through_tuple, but now apply to a struct instead
of a tuple.
+
+fn struct_no_initializer_must_normalize() {
+ trait Indirect { type Assoc; }
+ struct StaticU32;
+ impl Indirect for StaticU32 { type Assoc = &'static u32; }
+ struct Single2<T: Indirect> { value: <T as Indirect>::Assoc }
+
+ let x = 22;
+ let Single2 { value: mut _y }: Single2<StaticU32>;
+ _y = &x; //~ ERROR
+}
+
fn variable_with_initializer() {
let x = 22;
let y: &'static u32 = &x; //~ ERROR
fn variable_with_initializer() {
let x = 22;
let y: &'static u32 = &x; //~ ERROR
+fn static_to_a_to_static_through_struct<'a>(_x: &'a u32) -> &'static u32 {
+ let Single { value: y }: Single<&'a u32> = Single { value: &22 };
+ y //~ ERROR
+}
+
fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 {
let (y, _z): (&'static u32, u32) = (x, 44); //~ ERROR
y
fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 {
let (y, _z): (&'static u32, u32) = (x, 44); //~ ERROR
y
| - `x` dropped here while still borrowed
error[E0597]: `x` does not live long enough
| - `x` dropped here while still borrowed
error[E0597]: `x` does not live long enough
- --> $DIR/patterns.rs:46:27
+ --> $DIR/patterns.rs:53:10
+ |
+LL | let Single2 { value: mut _y }: Single2<StaticU32>;
+ | ------------------ type annotation requires that `x` is borrowed for `'static`
+LL | _y = &x; //~ ERROR
+ | ^^ borrowed value does not live long enough
+LL | }
+ | - `x` dropped here while still borrowed
+
+error[E0597]: `x` does not live long enough
+ --> $DIR/patterns.rs:58:27
|
LL | let y: &'static u32 = &x; //~ ERROR
| ------------ ^^ borrowed value does not live long enough
|
LL | let y: &'static u32 = &x; //~ ERROR
| ------------ ^^ borrowed value does not live long enough
| - `x` dropped here while still borrowed
error[E0597]: `x` does not live long enough
| - `x` dropped here while still borrowed
error[E0597]: `x` does not live long enough
- --> $DIR/patterns.rs:51:27
+ --> $DIR/patterns.rs:63:27
|
LL | let _: &'static u32 = &x; //~ ERROR
| ------------ ^^ borrowed value does not live long enough
|
LL | let _: &'static u32 = &x; //~ ERROR
| ------------ ^^ borrowed value does not live long enough
| - `x` dropped here while still borrowed
error[E0716]: temporary value dropped while borrowed
| - `x` dropped here while still borrowed
error[E0716]: temporary value dropped while borrowed
- --> $DIR/patterns.rs:53:41
+ --> $DIR/patterns.rs:65:41
|
LL | let _: Vec<&'static String> = vec![&String::new()];
| -------------------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
|
LL | let _: Vec<&'static String> = vec![&String::new()];
| -------------------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| type annotation requires that borrow lasts for `'static`
error[E0716]: temporary value dropped while borrowed
| type annotation requires that borrow lasts for `'static`
error[E0716]: temporary value dropped while borrowed
- --> $DIR/patterns.rs:56:52
+ --> $DIR/patterns.rs:68:52
|
LL | let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44);
| ------------------------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
|
LL | let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44);
| ------------------------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| type annotation requires that borrow lasts for `'static`
error[E0716]: temporary value dropped while borrowed
| type annotation requires that borrow lasts for `'static`
error[E0716]: temporary value dropped while borrowed
- --> $DIR/patterns.rs:59:53
+ --> $DIR/patterns.rs:71:53
|
LL | let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44);
| ------------------------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
|
LL | let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44);
| ------------------------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement
| type annotation requires that borrow lasts for `'static`
error[E0597]: `x` does not live long enough
| type annotation requires that borrow lasts for `'static`
error[E0597]: `x` does not live long enough
- --> $DIR/patterns.rs:65:40
+ --> $DIR/patterns.rs:77:40
|
LL | let (_, _): (&'static u32, u32) = (&x, 44); //~ ERROR
| ------------------- ^^ borrowed value does not live long enough
|
LL | let (_, _): (&'static u32, u32) = (&x, 44); //~ ERROR
| ------------------- ^^ borrowed value does not live long enough
| - `x` dropped here while still borrowed
error[E0597]: `x` does not live long enough
| - `x` dropped here while still borrowed
error[E0597]: `x` does not live long enough
- --> $DIR/patterns.rs:70:40
+ --> $DIR/patterns.rs:82:40
|
LL | let (y, _): (&'static u32, u32) = (&x, 44); //~ ERROR
| ------------------- ^^ borrowed value does not live long enough
|
LL | let (y, _): (&'static u32, u32) = (&x, 44); //~ ERROR
| ------------------- ^^ borrowed value does not live long enough
| - `x` dropped here while still borrowed
error[E0597]: `x` does not live long enough
| - `x` dropped here while still borrowed
error[E0597]: `x` does not live long enough
- --> $DIR/patterns.rs:75:69
+ --> $DIR/patterns.rs:87:69
|
LL | let Single { value: y }: Single<&'static u32> = Single { value: &x }; //~ ERROR
| -------------------- ^^ borrowed value does not live long enough
|
LL | let Single { value: y }: Single<&'static u32> = Single { value: &x }; //~ ERROR
| -------------------- ^^ borrowed value does not live long enough
| - `x` dropped here while still borrowed
error[E0597]: `x` does not live long enough
| - `x` dropped here while still borrowed
error[E0597]: `x` does not live long enough
- --> $DIR/patterns.rs:80:69
+ --> $DIR/patterns.rs:92:69
|
LL | let Single { value: _ }: Single<&'static u32> = Single { value: &x }; //~ ERROR
| -------------------- ^^ borrowed value does not live long enough
|
LL | let Single { value: _ }: Single<&'static u32> = Single { value: &x }; //~ ERROR
| -------------------- ^^ borrowed value does not live long enough
| - `x` dropped here while still borrowed
error[E0597]: `x` does not live long enough
| - `x` dropped here while still borrowed
error[E0597]: `x` does not live long enough
- --> $DIR/patterns.rs:88:17
+ --> $DIR/patterns.rs:100:17
|
LL | let Double { value1: _, value2: _ }: Double<&'static u32> = Double {
| -------------------- type annotation requires that `x` is borrowed for `'static`
|
LL | let Double { value1: _, value2: _ }: Double<&'static u32> = Double {
| -------------------- type annotation requires that `x` is borrowed for `'static`
| - `x` dropped here while still borrowed
error: unsatisfied lifetime constraints
| - `x` dropped here while still borrowed
error: unsatisfied lifetime constraints
- --> $DIR/patterns.rs:101:5
+ --> $DIR/patterns.rs:113:5
|
LL | fn static_to_a_to_static_through_variable<'a>(x: &'a u32) -> &'static u32 {
| -- lifetime `'a` defined here
|
LL | fn static_to_a_to_static_through_variable<'a>(x: &'a u32) -> &'static u32 {
| -- lifetime `'a` defined here
| ^ returning this value requires that `'a` must outlive `'static`
error: unsatisfied lifetime constraints
| ^ returning this value requires that `'a` must outlive `'static`
error: unsatisfied lifetime constraints
- --> $DIR/patterns.rs:113:5
+ --> $DIR/patterns.rs:125:5
|
LL | fn static_to_a_to_static_through_tuple<'a>(x: &'a u32) -> &'static u32 {
| -- lifetime `'a` defined here
|
LL | fn static_to_a_to_static_through_tuple<'a>(x: &'a u32) -> &'static u32 {
| -- lifetime `'a` defined here
| ^ returning this value requires that `'a` must outlive `'static`
error: unsatisfied lifetime constraints
| ^ returning this value requires that `'a` must outlive `'static`
error: unsatisfied lifetime constraints
- --> $DIR/patterns.rs:117:18
+ --> $DIR/patterns.rs:130:5
+ |
+LL | fn static_to_a_to_static_through_struct<'a>(_x: &'a u32) -> &'static u32 {
+ | -- lifetime `'a` defined here
+LL | let Single { value: y }: Single<&'a u32> = Single { value: &22 };
+LL | y //~ ERROR
+ | ^ returning this value requires that `'a` must outlive `'static`
+
+error: unsatisfied lifetime constraints
+ --> $DIR/patterns.rs:134:18
|
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
| ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
|
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
| ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static`
-error: aborting due to 17 previous errors
+error: aborting due to 19 previous errors
Some errors occurred: E0597, E0716.
For more information about an error, try `rustc --explain E0597`.
Some errors occurred: E0597, E0716.
For more information about an error, try `rustc --explain E0597`.