}
}
+ 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);
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);
}
}
+ /// 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(
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
| 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
| 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
--> $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
--> $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
|
= 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
|
|
= 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`.
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);
}
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
--- /dev/null
+// 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]
+}
--- /dev/null
+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`.
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
--> $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
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
| ^^^^^^^^^ 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
| --------- 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