]> git.lizzy.rs Git - rust.git/commitdiff
insert `AscribeUserType` for ascriptions
authorNiko Matsakis <niko@alum.mit.edu>
Fri, 31 Aug 2018 23:20:43 +0000 (19:20 -0400)
committerNiko Matsakis <niko@alum.mit.edu>
Mon, 10 Sep 2018 12:22:31 +0000 (08:22 -0400)
13 files changed:
src/librustc_mir/build/matches/mod.rs
src/test/ui/associated-types/associated-types-project-from-hrtb-in-fn-body.nll.stderr
src/test/ui/borrowck/borrowck-access-permissions.ast.nll.stderr
src/test/ui/borrowck/borrowck-access-permissions.mir.stderr
src/test/ui/consts/const-eval/dont_promote_unstable_const_fn.nll.stderr
src/test/ui/nll/relate_tys/hr-fn-aaa-as-aba.rs
src/test/ui/nll/relate_tys/hr-fn-aaa-as-aba.stderr
src/test/ui/nll/user-annotations/patterns.rs [new file with mode: 0644]
src/test/ui/nll/user-annotations/patterns.stderr [new file with mode: 0644]
src/test/ui/regions/region-object-lifetime-in-coercion.nll.stderr
src/test/ui/slice-mut-2.nll.stderr
src/test/ui/try-block/try-block-bad-lifetime.stderr
src/test/ui/unboxed-closures/unboxed-closures-failed-recursive-fn-1.nll.stderr

index 09e03554f05c36f8e835f5f704da603c39db3ad1..b5b0f5a2aa033af9ec6a7a912d5dd698dbc5d259 100644 (file)
@@ -329,6 +329,8 @@ pub fn place_into_pattern(
             }
         }
 
+        self.ascribe_types(block, &candidate.ascriptions);
+
         // now apply the bindings, which will also declare the variables
         self.bind_matched_candidate_for_arm_body(block, &candidate.bindings);
 
@@ -958,6 +960,8 @@ fn bind_and_guard_matched_candidate<'pat>(
 
         debug_assert!(candidate.match_pairs.is_empty());
 
+        self.ascribe_types(block, &candidate.ascriptions);
+
         let arm_block = arm_blocks.blocks[candidate.arm_index];
         let candidate_source_info = self.source_info(candidate.span);
 
@@ -1169,6 +1173,28 @@ fn bind_and_guard_matched_candidate<'pat>(
         }
     }
 
+    /// Append `AscribeUserType` statements onto the end of `block`
+    /// for each ascription
+    fn ascribe_types<'pat>(
+        &mut self,
+        block: BasicBlock,
+        ascriptions: &[Ascription<'tcx>],
+    ) {
+        for ascription in ascriptions {
+            let source_info = self.source_info(ascription.span);
+            self.cfg.push(
+                block,
+                Statement {
+                    source_info,
+                    kind: StatementKind::AscribeUserType(
+                        ascription.source.clone(),
+                        ascription.user_ty,
+                    ),
+                },
+            );
+        }
+    }
+
     // Only called when all_pat_vars_are_implicit_refs_within_guards,
     // and thus all code/comments assume we are in that context.
     fn bind_matched_candidate_for_guard(
index 674d85d95911260ccb9e87fe9a821424733c1bb5..d2388c377fc02beb15df0bdd3bf595c2bcfb5b76 100644 (file)
@@ -1,5 +1,5 @@
 error: unsatisfied lifetime constraints
-  --> $DIR/associated-types-project-from-hrtb-in-fn-body.rs:32:29
+  --> $DIR/associated-types-project-from-hrtb-in-fn-body.rs:32:19
    |
 LL | fn bar<'a, 'b, I : for<'x> Foo<&'x isize>>(
    |        --  -- lifetime `'b` defined here
@@ -7,10 +7,10 @@ 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`
+   |                   ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'a` must outlive `'b`
 
 error: unsatisfied lifetime constraints
-  --> $DIR/associated-types-project-from-hrtb-in-fn-body.rs:32:40
+  --> $DIR/associated-types-project-from-hrtb-in-fn-body.rs:32:19
    |
 LL | fn bar<'a, 'b, I : for<'x> Foo<&'x isize>>(
    |        --  -- lifetime `'b` defined here
@@ -18,7 +18,7 @@ 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`
+   |                   ^^^^^^^^^^^^^^^^^^^^^^^^ requires that `'b` must outlive `'a`
 
 error: aborting due to 2 previous errors
 
index 0df5e0c6e66925f32341bcdf3e0f8ad0cb4a3d24..bedbc744dd3ce1d4fe7be8be4056ab0f2754c29c 100644 (file)
@@ -35,7 +35,7 @@ error[E0596]: cannot borrow `*ptr_x` as mutable, as it is behind a `*const` poin
   --> $DIR/borrowck-access-permissions.rs:56:23
    |
 LL |         let ptr_x : *const _ = &x;
-   |                                -- help: consider changing this to be a mutable pointer: `&mut x`
+   |             ----- help: consider changing this to be a mutable pointer: `*mut i32`
 ...
 LL |             let _y1 = &mut *ptr_x; //[ast]~ ERROR [E0596]
    |                       ^^^^^^^^^^^ `ptr_x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable
index 0df5e0c6e66925f32341bcdf3e0f8ad0cb4a3d24..bedbc744dd3ce1d4fe7be8be4056ab0f2754c29c 100644 (file)
@@ -35,7 +35,7 @@ error[E0596]: cannot borrow `*ptr_x` as mutable, as it is behind a `*const` poin
   --> $DIR/borrowck-access-permissions.rs:56:23
    |
 LL |         let ptr_x : *const _ = &x;
-   |                                -- help: consider changing this to be a mutable pointer: `&mut x`
+   |             ----- help: consider changing this to be a mutable pointer: `*mut i32`
 ...
 LL |             let _y1 = &mut *ptr_x; //[ast]~ ERROR [E0596]
    |                       ^^^^^^^^^^^ `ptr_x` is a `*const` pointer, so the data it refers to cannot be borrowed as mutable
index ed3e38486baf628a045b33d3709c250044c4d5dd..f701ce187e3ce57f5a7e295cde2a3a1cb23e3d9a 100644 (file)
@@ -6,6 +6,27 @@ LL | const fn bar() -> u32 { foo() } //~ ERROR `foo` is not yet stable as a cons
    |
    = help: in Nightly builds, add `#![feature(foo)]` to the crate attributes to enable
 
+error[E0597]: borrowed value does not live long enough
+  --> $DIR/dont_promote_unstable_const_fn.rs:28:28
+   |
+LL |     let _: &'static u32 = &foo(); //~ ERROR does not live long enough
+   |                            ^^^^^ temporary value does not live long enough
+LL | }
+   | - temporary value only lives until here
+   |
+   = note: borrowed value must be valid for the static lifetime...
+
+error[E0597]: borrowed value does not live long enough
+  --> $DIR/dont_promote_unstable_const_fn.rs:32:28
+   |
+LL |     let _: &'static u32 = &meh(); //~ ERROR does not live long enough
+   |                            ^^^^^ temporary value does not live long enough
+LL |     let x: &'static _ = &std::time::Duration::from_millis(42).subsec_millis();
+LL | }
+   | - temporary value only lives until here
+   |
+   = note: borrowed value must be valid for the static lifetime...
+
 error[E0597]: borrowed value does not live long enough
   --> $DIR/dont_promote_unstable_const_fn.rs:33:26
    |
@@ -17,6 +38,6 @@ LL | }
    |
    = note: borrowed value must be valid for the static lifetime...
 
-error: aborting due to 2 previous errors
+error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0597`.
index 84c305f5907d102a44064cb924a643ada33e39bb..c1a46a2f1b560979f278444532822f3352b758dd 100644 (file)
@@ -23,5 +23,6 @@ fn make_it() -> for<'a> fn(&'a u32, &'a u32) -> &'a u32 {
 fn main() {
     let a: for<'a, 'b> fn(&'a u32, &'b u32) -> &'a u32 = make_it();
     //~^ ERROR higher-ranked subtype error
+    //~| ERROR higher-ranked subtype error
     drop(a);
 }
index e08d848b471407d8697a65afd9d50762b23e49ce..bd5d1f44512a2ed335432bac10deb5660ac936ca 100644 (file)
@@ -4,5 +4,11 @@ error: higher-ranked subtype error
 LL |     let a: for<'a, 'b> fn(&'a u32, &'b u32) -> &'a u32 = make_it();
    |                                                          ^^^^^^^^^
 
-error: aborting due to previous error
+error: higher-ranked subtype error
+  --> $DIR/hr-fn-aaa-as-aba.rs:24:9
+   |
+LL |     let a: for<'a, 'b> fn(&'a u32, &'b u32) -> &'a u32 = make_it();
+   |         ^
+
+error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/nll/user-annotations/patterns.rs b/src/test/ui/nll/user-annotations/patterns.rs
new file mode 100644 (file)
index 0000000..855f174
--- /dev/null
@@ -0,0 +1,14 @@
+// Test that various patterns also enforce types.
+
+#![feature(nll)]
+
+fn main() {
+    let _: Vec<&'static String> = vec![&String::new()];
+    //~^ ERROR borrowed value does not live long enough [E0597]
+
+    let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44);
+    //~^ ERROR borrowed value does not live long enough [E0597]
+
+    let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44);
+    //~^ ERROR borrowed value does not live long enough [E0597]
+}
diff --git a/src/test/ui/nll/user-annotations/patterns.stderr b/src/test/ui/nll/user-annotations/patterns.stderr
new file mode 100644 (file)
index 0000000..f982362
--- /dev/null
@@ -0,0 +1,33 @@
+error[E0597]: borrowed value does not live long enough
+  --> $DIR/patterns.rs:6:41
+   |
+LL |     let _: Vec<&'static String> = vec![&String::new()];
+   |                                         ^^^^^^^^^^^^^ - temporary value only lives until here
+   |                                         |
+   |                                         temporary value does not live long enough
+   |
+   = note: borrowed value must be valid for the static lifetime...
+
+error[E0597]: borrowed value does not live long enough
+  --> $DIR/patterns.rs:9:52
+   |
+LL |     let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44);
+   |                                                    ^^^^^^^^^^^^^      - temporary value only lives until here
+   |                                                    |
+   |                                                    temporary value does not live long enough
+   |
+   = note: borrowed value must be valid for the static lifetime...
+
+error[E0597]: borrowed value does not live long enough
+  --> $DIR/patterns.rs:12:53
+   |
+LL |     let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44);
+   |                                                     ^^^^^^^^^^^^^      - temporary value only lives until here
+   |                                                     |
+   |                                                     temporary value does not live long enough
+   |
+   = note: borrowed value must be valid for the static lifetime...
+
+error: aborting due to 3 previous errors
+
+For more information about this error, try `rustc --explain E0597`.
index e8c1d7e74a038a9477acfcac8bc8d962397cdfae..ed51cc38d5a6ca92c90cc31bafdd3c54a26a7f0a 100644 (file)
@@ -1,10 +1,11 @@
 error[E0621]: explicit lifetime required in the type of `v`
-  --> $DIR/region-object-lifetime-in-coercion.rs:18:33
+  --> $DIR/region-object-lifetime-in-coercion.rs:20:5
    |
 LL | fn a(v: &[u8]) -> Box<Foo + 'static> {
    |         ----- help: add explicit lifetime `'static` to the type of `v`: `&'static [u8]`
-LL |     let x: Box<Foo + 'static> = Box::new(v);
-   |                                 ^^^^^^^^^^^ lifetime `'static` required
+...
+LL |     x
+   |     ^ lifetime `'static` required
 
 error[E0621]: explicit lifetime required in the type of `v`
   --> $DIR/region-object-lifetime-in-coercion.rs:24:5
index 98d9297e112a4e47a68dc76f900e34d57d2b31fa..9678430060b2730828012b6759c9868b6458815d 100644 (file)
@@ -2,7 +2,7 @@ error[E0596]: cannot borrow `*x` as mutable, as it is behind a `&` reference
   --> $DIR/slice-mut-2.rs:17:18
    |
 LL |     let x: &[isize] = &[1, 2, 3, 4, 5];
-   |                       ---------------- help: consider changing this to be a mutable reference: `&mut [1, 2, 3, 4, 5]`
+   |         - help: consider changing this to be a mutable reference: `&mut [isize]`
 ...
 LL |     let _ = &mut x[2..4]; //~ERROR cannot borrow immutable borrowed content `*x` as mutable
    |                  ^ `x` is a `&` reference, so the data it refers to cannot be borrowed as mutable
index 36c89faf5a2ca8f35489c164d3d05f8f6cc88746..ebf56dc9835f4928842586f30424f8f2e8d83e43 100644 (file)
@@ -1,13 +1,14 @@
 error[E0597]: `my_string` does not live long enough
   --> $DIR/try-block-bad-lifetime.rs:25:33
    |
+LL |         let result: Result<(), &str> = try {
+   |             ------ borrow later used here
+LL |             let my_string = String::from("");
 LL |             let my_str: & str = & my_string;
    |                                 ^^^^^^^^^^^ borrowed value does not live long enough
 ...
 LL |         };
    |         - `my_string` dropped here while still borrowed
-LL |         do_something_with(result);
-   |                           ------ borrow later used here
 
 error[E0506]: cannot assign to `i` because it is borrowed
   --> $DIR/try-block-bad-lifetime.rs:39:13
index 8cda1e60ba988284ddee1bdca2558c03d0e82da5..a4527e793923f567f9966e56d52460a3e4e95142 100644 (file)
@@ -38,9 +38,12 @@ LL |         let g = factorial.as_ref().unwrap();
    |                 ^^^^^^^^^ borrowed value does not live long enough
 ...
 LL | }
-   | - `factorial` dropped here while still borrowed
+   | -
+   | |
+   | `factorial` dropped here while still borrowed
+   | borrow later used here, when `factorial` is dropped
    |
-   = note: borrowed value must be valid for the static lifetime...
+   = note: values in a scope are dropped in the opposite order they are defined
 
 error[E0506]: cannot assign to `factorial` because it is borrowed
   --> $DIR/unboxed-closures-failed-recursive-fn-1.rs:42:5
@@ -52,9 +55,10 @@ LL |         let g = factorial.as_ref().unwrap();
    |                 --------- borrow occurs due to use in closure
 ...
 LL |     factorial = Some(Box::new(f));
-   |     ^^^^^^^^^ assignment to borrowed `factorial` occurs here
-   |
-   = note: borrowed value must be valid for the static lifetime...
+   |     ^^^^^^^^^
+   |     |
+   |     assignment to borrowed `factorial` occurs here
+   |     borrow later used here
 
 error: aborting due to 4 previous errors