diff options
Diffstat (limited to 'tests/ui/regions/regions-lifetime-of-struct-or-enum-variant.rs')
-rw-r--r-- | tests/ui/regions/regions-lifetime-of-struct-or-enum-variant.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/ui/regions/regions-lifetime-of-struct-or-enum-variant.rs b/tests/ui/regions/regions-lifetime-of-struct-or-enum-variant.rs new file mode 100644 index 000000000..1b25294c7 --- /dev/null +++ b/tests/ui/regions/regions-lifetime-of-struct-or-enum-variant.rs @@ -0,0 +1,26 @@ +// This tests verifies that unary structs and enum variants +// 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 { + Variant1 +} + +fn structLifetime<'a>() -> &'a Test { + let testValue = &id(Test); + testValue + //~^ ERROR cannot return value referencing temporary value +} + +fn variantLifetime<'a>() -> &'a MyEnum { + let testValue = &id(MyEnum::Variant1); + testValue + //~^ ERROR cannot return value referencing temporary value +} + + +fn main() {} |