about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKeith Yeung <kungfukeith11@gmail.com>2018-09-25 11:51:36 -0700
committerKeith Yeung <kungfukeith11@gmail.com>2018-09-29 10:34:36 -0700
commit8380b25d13eeeb387efd6442c4e3638198b06412 (patch)
treef1d3a9f16498d438c8d80c73c1533395e36732d5
parent4a293a3990a0c1bf170d31d1d9bcbc79cef8a5b8 (diff)
downloadrust-8380b25d13eeeb387efd6442c4e3638198b06412.tar.gz
rust-8380b25d13eeeb387efd6442c4e3638198b06412.zip
Add UI test for preserving user types in type ascriptions
-rw-r--r--src/test/ui/nll/user-annotations/type_ascription_static_lifetime.rs19
-rw-r--r--src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr13
2 files changed, 32 insertions, 0 deletions
diff --git a/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.rs b/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.rs
new file mode 100644
index 00000000000..2785f71ebcf
--- /dev/null
+++ b/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.rs
@@ -0,0 +1,19 @@
+// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+
+#![allow(warnings)]
+#![feature(nll)]
+#![feature(type_ascription)]
+
+fn main() {
+    let x = 22_u32;
+    let y: &u32 = &x: &'static u32; //~ ERROR E0597
+}
diff --git a/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr b/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr
new file mode 100644
index 00000000000..2303ed64db9
--- /dev/null
+++ b/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr
@@ -0,0 +1,13 @@
+error[E0597]: `x` does not live long enough
+  --> $DIR/type_ascription_static_lifetime.rs:18:19
+   |
+LL |     let y: &u32 = &x: &'static u32; //~ ERROR E0597
+   |                   ^^ 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: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0597`.