about summary refs log tree commit diff
path: root/tests/ui/underscore-lifetime
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-07-11 07:35:18 +0200
committerGitHub <noreply@github.com>2025-07-11 07:35:18 +0200
commit3d6eb225e26448b09fdec1ba7222f3e7174c6ac2 (patch)
tree17d044aac71ec4a410ebbb33c8f8349d46d395e1 /tests/ui/underscore-lifetime
parent2730bebbf88ae9473b339bb7f66eb77fb2c9fa6f (diff)
parent3ad95cccf9b3af7e527869a1eb130217971b7a57 (diff)
downloadrust-3d6eb225e26448b09fdec1ba7222f3e7174c6ac2.tar.gz
rust-3d6eb225e26448b09fdec1ba7222f3e7174c6ac2.zip
Rollup merge of #143302 - Kivooeo:tf27, r=tgross35
`tests/ui`: A New Order [27/N]

> [!NOTE]
>
> Intermediate commits are intended to help review, but will be squashed prior to merge.

Some `tests/ui/` housekeeping, to trim down number of tests directly under `tests/ui/`. Part of rust-lang/rust#133895.

r? ``@tgross35``
Diffstat (limited to 'tests/ui/underscore-lifetime')
-rw-r--r--tests/ui/underscore-lifetime/basic-underscore-lifetime-elision.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/ui/underscore-lifetime/basic-underscore-lifetime-elision.rs b/tests/ui/underscore-lifetime/basic-underscore-lifetime-elision.rs
new file mode 100644
index 00000000000..a2e3c8e26d4
--- /dev/null
+++ b/tests/ui/underscore-lifetime/basic-underscore-lifetime-elision.rs
@@ -0,0 +1,38 @@
+//! Checks the correct usage and behavior of the anonymous lifetime `'_` (underscore lifetime)
+
+//@ run-pass
+
+#![allow(dead_code, mismatched_lifetime_syntaxes)]
+
+struct Foo<'a>(&'a u8);
+
+fn foo(x: &u8) -> Foo<'_> {
+    Foo(x)
+}
+
+fn foo2(x: &'_ u8) -> Foo<'_> {
+    Foo(x)
+}
+
+fn foo3(x: &'_ u8) -> Foo {
+    Foo(x)
+}
+
+fn foo4(_: Foo<'_>) {}
+
+struct Foo2<'a, 'b> {
+    a: &'a u8,
+    b: &'b u8,
+}
+fn foo5<'b>(foo: Foo2<'_, 'b>) -> &'b u8 {
+    foo.b
+}
+
+fn main() {
+    let x = &5;
+    let _ = foo(x);
+    let _ = foo2(x);
+    let _ = foo3(x);
+    foo4(Foo(x));
+    let _ = foo5(Foo2 { a: x, b: &6 });
+}