summaryrefslogtreecommitdiffstats
path: root/src/test/ui/single-use-lifetime/fn-types.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/single-use-lifetime/fn-types.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/ui/single-use-lifetime/fn-types.rs')
-rw-r--r--src/test/ui/single-use-lifetime/fn-types.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/test/ui/single-use-lifetime/fn-types.rs b/src/test/ui/single-use-lifetime/fn-types.rs
new file mode 100644
index 000000000..018535f64
--- /dev/null
+++ b/src/test/ui/single-use-lifetime/fn-types.rs
@@ -0,0 +1,16 @@
+#![deny(single_use_lifetimes)]
+#![allow(dead_code)]
+#![allow(unused_variables)]
+
+// Test that we DO warn when lifetime name is used only
+// once in a fn argument.
+
+struct Foo {
+ a: for<'a> fn(&'a u32), //~ ERROR `'a` only used once
+ b: for<'a> fn(&'a u32, &'a u32), // OK, used twice.
+ c: for<'a> fn(&'a u32) -> &'a u32, // OK, used twice.
+ d: for<'a> fn() -> &'a u32, // OK, used only in return type.
+ //~^ ERROR return type references lifetime `'a`, which is not constrained by the fn input types
+}
+
+fn main() { }