summaryrefslogtreecommitdiffstats
path: root/src/test/ui/single-use-lifetime/one-use-in-fn-return.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/ui/single-use-lifetime/one-use-in-fn-return.rs')
-rw-r--r--src/test/ui/single-use-lifetime/one-use-in-fn-return.rs23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/ui/single-use-lifetime/one-use-in-fn-return.rs b/src/test/ui/single-use-lifetime/one-use-in-fn-return.rs
new file mode 100644
index 000000000..1ade01eed
--- /dev/null
+++ b/src/test/ui/single-use-lifetime/one-use-in-fn-return.rs
@@ -0,0 +1,23 @@
+// Test that we DO NOT warn when lifetime name is used only
+// once in a fn return type -- using `'_` is not legal there,
+// as it must refer back to an argument.
+//
+// (Normally, using `'static` would be preferred, but there are
+// times when that is not what you want.)
+
+// check-pass
+
+#![deny(single_use_lifetimes)]
+
+// OK: used only in return type
+fn b<'a>() -> &'a u32 {
+ &22
+}
+
+pub trait Tfv<'a> {}
+impl Tfv<'_> for () {}
+
+// Do NOT lint if used in return type.
+pub fn i<'a>() -> impl Tfv<'a> {}
+
+fn main() {}