From 8380b25d13eeeb387efd6442c4e3638198b06412 Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Tue, 25 Sep 2018 11:51:36 -0700 Subject: [PATCH] Add UI test for preserving user types in type ascriptions --- .../type_ascription_static_lifetime.rs | 19 +++++++++++++++++++ .../type_ascription_static_lifetime.stderr | 13 +++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 src/test/ui/nll/user-annotations/type_ascription_static_lifetime.rs create mode 100644 src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr 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 000000000000..2785f71ebcf6 --- /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 or the MIT license +// , 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 000000000000..2303ed64db94 --- /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`.