2014-01-24 19:48:10 +00:00
|
|
|
// This tests verifies that unary structs and enum variants
|
|
|
|
// are treated as rvalues and their lifetime is not bounded to
|
|
|
|
// the static scope.
|
|
|
|
|
2017-08-13 08:46:49 +00:00
|
|
|
fn id<T>(x: T) -> T { x }
|
|
|
|
|
2014-01-24 19:48:10 +00:00
|
|
|
struct Test;
|
|
|
|
|
|
|
|
enum MyEnum {
|
|
|
|
Variant1
|
|
|
|
}
|
|
|
|
|
2014-07-18 04:44:59 +00:00
|
|
|
fn structLifetime<'a>() -> &'a Test {
|
2017-08-13 08:46:49 +00:00
|
|
|
let testValue = &id(Test);
|
2014-01-24 19:48:10 +00:00
|
|
|
testValue
|
2019-04-22 07:40:08 +00:00
|
|
|
//~^ ERROR cannot return value referencing temporary value
|
2014-01-24 19:48:10 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 04:44:59 +00:00
|
|
|
fn variantLifetime<'a>() -> &'a MyEnum {
|
2017-08-13 08:46:49 +00:00
|
|
|
let testValue = &id(MyEnum::Variant1);
|
2014-01-24 19:48:10 +00:00
|
|
|
testValue
|
2019-04-22 07:40:08 +00:00
|
|
|
//~^ ERROR cannot return value referencing temporary value
|
2014-01-24 19:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn main() {}
|