rust/tests/ui/regions/regions-lifetime-of-struct-or-enum-variant.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

27 lines
531 B
Rust
Raw Normal View History

// 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 }
struct Test;
enum MyEnum {
Variant1
}
fn structLifetime<'a>() -> &'a Test {
2017-08-13 08:46:49 +00:00
let testValue = &id(Test);
testValue
//~^ ERROR cannot return value referencing temporary value
}
fn variantLifetime<'a>() -> &'a MyEnum {
2017-08-13 08:46:49 +00:00
let testValue = &id(MyEnum::Variant1);
testValue
//~^ ERROR cannot return value referencing temporary value
}
fn main() {}