diff options
| author | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-08-13 11:46:49 +0300 |
|---|---|---|
| committer | Eduard-Mihai Burtescu <edy.burt@gmail.com> | 2017-08-16 20:30:56 +0300 |
| commit | 014333fbd422f56628a2b5b707d192cef838afc3 (patch) | |
| tree | ed4f2943607c52e31191871b405035451d1c223e /src/test/compile-fail | |
| parent | c88624682ddb5768cca4dacc8482e9bc966261fc (diff) | |
| download | rust-014333fbd422f56628a2b5b707d192cef838afc3.tar.gz rust-014333fbd422f56628a2b5b707d192cef838afc3.zip | |
Stabilize rvalue promotion to 'static.
Diffstat (limited to 'src/test/compile-fail')
11 files changed, 36 insertions, 30 deletions
diff --git a/src/test/compile-fail/borrowck/borrowck-borrow-from-temporary.rs b/src/test/compile-fail/borrowck/borrowck-borrow-from-temporary.rs index fbb3824cd40..f7514df800d 100644 --- a/src/test/compile-fail/borrowck/borrowck-borrow-from-temporary.rs +++ b/src/test/compile-fail/borrowck/borrowck-borrow-from-temporary.rs @@ -11,10 +11,12 @@ // Test lifetimes are linked properly when we take reference // to interior. +fn id<T>(x: T) -> T { x } + struct Foo(isize); fn foo<'a>() -> &'a isize { - let &Foo(ref x) = &Foo(3); //~ ERROR borrowed value does not live long enough + let &Foo(ref x) = &id(Foo(3)); //~ ERROR borrowed value does not live long enough x } diff --git a/src/test/compile-fail/feature-gate-rvalue_static_promotion.rs b/src/test/compile-fail/feature-gate-rvalue_static_promotion.rs deleted file mode 100644 index f33d0a71481..00000000000 --- a/src/test/compile-fail/feature-gate-rvalue_static_promotion.rs +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017 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(unused_variables)] -fn main() { - let x: &'static u32 = &42; //~ error: does not live long enough - let y: &'static Option<u32> = &None; //~ error: does not live long enough -} diff --git a/src/test/compile-fail/issue-11493.rs b/src/test/compile-fail/issue-11493.rs index 333ff7118d4..3045c06ca4c 100644 --- a/src/test/compile-fail/issue-11493.rs +++ b/src/test/compile-fail/issue-11493.rs @@ -10,7 +10,9 @@ // This file must never have a trailing newline +fn id<T>(x: T) -> T { x } + fn main() { let x = Some(3); - let y = x.as_ref().unwrap_or(&5); //~ ERROR: borrowed value does not live long enough + let y = x.as_ref().unwrap_or(&id(5)); //~ ERROR: borrowed value does not live long enough } diff --git a/src/test/compile-fail/issue-17545.rs b/src/test/compile-fail/issue-17545.rs index 45bc5ee07a5..9264305e6ea 100644 --- a/src/test/compile-fail/issue-17545.rs +++ b/src/test/compile-fail/issue-17545.rs @@ -10,9 +10,11 @@ #![feature(fn_traits)] +fn id<T>(x: T) -> T { x } + pub fn foo<'a, F: Fn(&'a ())>(bar: F) { bar.call(( - &(), //~ ERROR borrowed value does not live long enough + &id(()), //~ ERROR borrowed value does not live long enough )); } fn main() {} diff --git a/src/test/compile-fail/issue-17718-constants-not-static.rs b/src/test/compile-fail/issue-17718-constants-not-static.rs index db56d2c6cf3..9b7ed463499 100644 --- a/src/test/compile-fail/issue-17718-constants-not-static.rs +++ b/src/test/compile-fail/issue-17718-constants-not-static.rs @@ -8,9 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +fn id<T>(x: T) -> T { x } + const FOO: usize = 3; -fn foo() -> &'static usize { &FOO } +fn foo() -> &'static usize { &id(FOO) } //~^ ERROR: borrowed value does not live long enough fn main() { diff --git a/src/test/compile-fail/issue-27592.rs b/src/test/compile-fail/issue-27592.rs index ccf5eabc111..731d4fb2bf6 100644 --- a/src/test/compile-fail/issue-27592.rs +++ b/src/test/compile-fail/issue-27592.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Regression test for issue #27591. +// Regression test for issue #27592. fn write<'a, F: ::std::ops::FnOnce()->::std::fmt::Arguments<'a> + 'a>(fcn: F) { use std::fmt::Write; @@ -23,7 +23,7 @@ impl ::std::fmt::Write for Stream { } fn main() { - write(|| format_args!("{}", "Hello world")); + write(|| format_args!("{}", String::from("Hello world"))); //~^ ERROR borrowed value does not live long enough //~| ERROR borrowed value does not live long enough } diff --git a/src/test/compile-fail/regions-lifetime-of-struct-or-enum-variant.rs b/src/test/compile-fail/regions-lifetime-of-struct-or-enum-variant.rs index 9c985839c4d..46c486c63a3 100644 --- a/src/test/compile-fail/regions-lifetime-of-struct-or-enum-variant.rs +++ b/src/test/compile-fail/regions-lifetime-of-struct-or-enum-variant.rs @@ -12,6 +12,8 @@ // are treated as rvalues and their lifetime is not bounded to // the static scope. +fn id<T>(x: T) -> T { x } + struct Test; enum MyEnum { @@ -19,12 +21,14 @@ enum MyEnum { } fn structLifetime<'a>() -> &'a Test { - let testValue = &Test; //~ ERROR borrowed value does not live long enough + let testValue = &id(Test); + //~^ ERROR borrowed value does not live long enough testValue } fn variantLifetime<'a>() -> &'a MyEnum { - let testValue = &MyEnum::Variant1; //~ ERROR borrowed value does not live long enough + let testValue = &id(MyEnum::Variant1); + //~^ ERROR borrowed value does not live long enough testValue } diff --git a/src/test/compile-fail/regions-ret.rs b/src/test/compile-fail/regions-ret.rs index 61c98d69d80..c7cd3ced98d 100644 --- a/src/test/compile-fail/regions-ret.rs +++ b/src/test/compile-fail/regions-ret.rs @@ -8,8 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +fn id<T>(x: T) -> T { x } + fn f(_x: &isize) -> &isize { - return &3; //~ ERROR borrowed value does not live long enough + return &id(3); //~ ERROR borrowed value does not live long enough } fn main() { diff --git a/src/test/compile-fail/regions-var-type-out-of-scope.rs b/src/test/compile-fail/regions-var-type-out-of-scope.rs index 8955a26de0b..031091c4523 100644 --- a/src/test/compile-fail/regions-var-type-out-of-scope.rs +++ b/src/test/compile-fail/regions-var-type-out-of-scope.rs @@ -8,13 +8,15 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +fn id<T>(x: T) -> T { x } + fn foo(cond: bool) { // Here we will infer a type that uses the // region of the if stmt then block: let mut x; if cond { - x = &3; //~ ERROR borrowed value does not live long enough + x = &id(3); //~ ERROR borrowed value does not live long enough assert_eq!(*x, 3); } } diff --git a/src/test/compile-fail/static-reference-to-fn-2.rs b/src/test/compile-fail/static-reference-to-fn-2.rs index 460154f25d7..8d9f442b81d 100644 --- a/src/test/compile-fail/static-reference-to-fn-2.rs +++ b/src/test/compile-fail/static-reference-to-fn-2.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +fn id<T>(x: T) -> T { x } + struct StateMachineIter<'a> { statefn: &'a StateMachineFunc<'a> } @@ -23,19 +25,19 @@ impl<'a> Iterator for StateMachineIter<'a> { } fn state1(self_: &mut StateMachineIter) -> Option<&'static str> { - self_.statefn = &(state2 as StateMachineFunc); + self_.statefn = &id(state2 as StateMachineFunc); //~^ ERROR borrowed value does not live long enough return Some("state1"); } fn state2(self_: &mut StateMachineIter) -> Option<(&'static str)> { - self_.statefn = &(state3 as StateMachineFunc); + self_.statefn = &id(state3 as StateMachineFunc); //~^ ERROR borrowed value does not live long enough return Some("state2"); } fn state3(self_: &mut StateMachineIter) -> Option<(&'static str)> { - self_.statefn = &(finished as StateMachineFunc); + self_.statefn = &id(finished as StateMachineFunc); //~^ ERROR borrowed value does not live long enough return Some("state3"); } @@ -46,7 +48,8 @@ fn finished(_: &mut StateMachineIter) -> Option<(&'static str)> { fn state_iter() -> StateMachineIter<'static> { StateMachineIter { - statefn: &(state1 as StateMachineFunc) //~ ERROR borrowed value does not live long enough + statefn: &id(state1 as StateMachineFunc) + //~^ ERROR borrowed value does not live long enough } } diff --git a/src/test/compile-fail/static-region-bound.rs b/src/test/compile-fail/static-region-bound.rs index eca22bfdda0..90ed401659c 100644 --- a/src/test/compile-fail/static-region-bound.rs +++ b/src/test/compile-fail/static-region-bound.rs @@ -10,11 +10,13 @@ #![feature(box_syntax)] +fn id<T>(x: T) -> T { x } + fn f<T:'static>(_: T) {} fn main() { let x: Box<_> = box 3; f(x); - let x = &3; //~ ERROR borrowed value does not live long enough + let x = &id(3); //~ ERROR borrowed value does not live long enough f(x); } |
