]> git.lizzy.rs Git - rust.git/commitdiff
Add test for normalization during field-lookup on patterns with ascribed types.
authorFelix S. Klock II <pnkfelix@pnkfx.org>
Thu, 25 Oct 2018 13:45:41 +0000 (15:45 +0200)
committerFelix S. Klock II <pnkfelix@pnkfx.org>
Fri, 26 Oct 2018 21:47:53 +0000 (23:47 +0200)
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.

src/test/ui/nll/user-annotations/patterns.rs
src/test/ui/nll/user-annotations/patterns.stderr

index 643231b39b42e096611f7e0b22eb21fa6d464826..8c8e61cd6fbeb7ff3e3b547402236860ef9fcb98 100644 (file)
@@ -41,6 +41,18 @@ fn struct_no_initializer() {
     y = &x; //~ ERROR
 }
 
     y = &x; //~ ERROR
 }
 
+
+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
@@ -113,6 +125,11 @@ fn static_to_a_to_static_through_tuple<'a>(x: &'a u32) -> &'static u32 {
     y //~ ERROR
 }
 
     y //~ 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
index 58b708fcb1b53ef5eadbcf07bc75b1d9fdb7b2e7..b0c554e6ca1d47f24ecf2cbb827ee0fd55b2a070 100644 (file)
@@ -40,7 +40,17 @@ LL | }
    | - `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
@@ -50,7 +60,7 @@ LL | }
    | - `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
@@ -61,7 +71,7 @@ LL | }
    | - `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
@@ -70,7 +80,7 @@ LL |     let _: Vec<&'static String> = vec![&String::new()];
    |            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
@@ -79,7 +89,7 @@ LL |     let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44);
    |                 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
@@ -88,7 +98,7 @@ LL |     let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44);
    |                  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
@@ -98,7 +108,7 @@ LL | }
    | - `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
@@ -108,7 +118,7 @@ LL | }
    | - `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
@@ -118,7 +128,7 @@ LL | }
    | - `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
@@ -128,7 +138,7 @@ LL | }
    | - `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`
@@ -139,7 +149,7 @@ LL | }
    | - `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
@@ -148,7 +158,7 @@ LL |     y //~ ERROR
    |     ^ 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
@@ -157,14 +167,23 @@ LL |     y //~ ERROR
    |     ^ 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`.