about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authortrevyn <230691+trevyn@users.noreply.github.com>2024-01-20 01:22:52 +0400
committertrevyn <230691+trevyn@users.noreply.github.com>2024-01-20 01:22:52 +0400
commit0943a6b188e11339d217d43f39322f51d2d8187d (patch)
tree4cf60d929405b70eac46b90bb146f3365af79f6b /tests
parent88189a71e4e4376eea82ac61db6a539612eb200a (diff)
downloadrust-0943a6b188e11339d217d43f39322f51d2d8187d.tar.gz
rust-0943a6b188e11339d217d43f39322f51d2d8187d.zip
add test issue-117965
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/single-use-lifetime/issue-117965.rs18
-rw-r--r--tests/ui/single-use-lifetime/issue-117965.stderr21
2 files changed, 39 insertions, 0 deletions
diff --git a/tests/ui/single-use-lifetime/issue-117965.rs b/tests/ui/single-use-lifetime/issue-117965.rs
new file mode 100644
index 00000000000..5eb2a03e13d
--- /dev/null
+++ b/tests/ui/single-use-lifetime/issue-117965.rs
@@ -0,0 +1,18 @@
+#![deny(single_use_lifetimes)]
+
+pub enum Data<'a> {
+    Borrowed(&'a str),
+    Owned(String),
+}
+
+impl<'a> Data<'a> {
+    pub fn get<'b: 'a>(&'b self) -> &'a str {
+        //~^ ERROR lifetime parameter `'b` only used once
+        match &self {
+            Self::Borrowed(val) => val,
+            Self::Owned(val) => &val,
+        }
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/single-use-lifetime/issue-117965.stderr b/tests/ui/single-use-lifetime/issue-117965.stderr
new file mode 100644
index 00000000000..e789e183546
--- /dev/null
+++ b/tests/ui/single-use-lifetime/issue-117965.stderr
@@ -0,0 +1,21 @@
+error: lifetime parameter `'b` only used once
+  --> $DIR/issue-117965.rs:9:16
+   |
+LL |     pub fn get<'b: 'a>(&'b self) -> &'a str {
+   |                ^^       -- ...is used only here
+   |                |
+   |                this lifetime...
+   |
+note: the lint level is defined here
+  --> $DIR/issue-117965.rs:1:9
+   |
+LL | #![deny(single_use_lifetimes)]
+   |         ^^^^^^^^^^^^^^^^^^^^
+help: elide the single-use lifetime
+   |
+LL -     pub fn get<'b: 'a>(&'b self) -> &'a str {
+LL +     pub fn get(&self) -> &'a str {
+   |
+
+error: aborting due to 1 previous error
+