summaryrefslogtreecommitdiffstats
path: root/src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs')
-rw-r--r--src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs45
1 files changed, 45 insertions, 0 deletions
diff --git a/src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs b/src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs
new file mode 100644
index 000000000..7a2eba518
--- /dev/null
+++ b/src/test/ui/lifetimes/lifetime-elision-return-type-requires-explicit-lifetime.rs
@@ -0,0 +1,45 @@
+// Lifetime annotation needed because we have no arguments.
+fn f() -> &isize { //~ ERROR missing lifetime specifier
+ panic!()
+}
+
+// Lifetime annotation needed because we have two by-reference parameters.
+fn g(_x: &isize, _y: &isize) -> &isize { //~ ERROR missing lifetime specifier
+ panic!()
+}
+
+struct Foo<'a> {
+ x: &'a isize,
+}
+
+// Lifetime annotation needed because we have two lifetimes: one as a parameter
+// and one on the reference.
+fn h(_x: &Foo) -> &isize { //~ ERROR missing lifetime specifier
+ panic!()
+}
+
+fn i(_x: isize) -> &isize { //~ ERROR missing lifetime specifier
+ panic!()
+}
+
+// Cases which used to work but now don't.
+
+type StaticStr = &'static str; // hides 'static
+trait WithLifetime<'a> {
+ type Output; // can hide 'a
+}
+
+// This worked because the type of the first argument contains
+// 'static, although StaticStr doesn't even have parameters.
+fn j(_x: StaticStr) -> &isize { //~ ERROR missing lifetime specifier
+ panic!()
+}
+
+// This worked because the compiler resolved the argument type
+// to <T as WithLifetime<'a>>::Output which has the hidden 'a.
+fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &isize {
+//~^ ERROR missing lifetime specifier
+ panic!()
+}
+
+fn main() {}