about summary refs log tree commit diff
path: root/tests/ui/lifetimes
diff options
context:
space:
mode:
authorKivooeo <Kivooeo123@gmail.com>2025-07-24 17:45:27 +0500
committerKivooeo <Kivooeo123@gmail.com>2025-08-05 19:02:23 +0500
commit62c92f30cf02fc56b8a774c77097f1111dc2f4ea (patch)
treefe8c9846c6ca02b176ea9adcb8a348bd5ead1846 /tests/ui/lifetimes
parent0f353363965ebf05e0757f7679c800b39c51a07e (diff)
downloadrust-62c92f30cf02fc56b8a774c77097f1111dc2f4ea.tar.gz
rust-62c92f30cf02fc56b8a774c77097f1111dc2f4ea.zip
moved 35 tests to organized locations
Diffstat (limited to 'tests/ui/lifetimes')
-rw-r--r--tests/ui/lifetimes/explicit-lifetime-required-14285.rs17
-rw-r--r--tests/ui/lifetimes/lifetime-bound-whitespace-13703.rs5
-rw-r--r--tests/ui/lifetimes/missing-lifetime-specifier-13497.rs8
-rw-r--r--tests/ui/lifetimes/ref-pattern-lifetime-annotation-13665.rs14
-rw-r--r--tests/ui/lifetimes/return-reference-local-variable-13497-2.rs7
-rw-r--r--tests/ui/lifetimes/trait-object-constructor-14821.rs21
6 files changed, 72 insertions, 0 deletions
diff --git a/tests/ui/lifetimes/explicit-lifetime-required-14285.rs b/tests/ui/lifetimes/explicit-lifetime-required-14285.rs
new file mode 100644
index 00000000000..2ba9ff71773
--- /dev/null
+++ b/tests/ui/lifetimes/explicit-lifetime-required-14285.rs
@@ -0,0 +1,17 @@
+trait Foo {
+    fn dummy(&self) { }
+}
+
+struct A;
+
+impl Foo for A {}
+
+struct B<'a>(&'a (dyn Foo + 'a));
+
+fn foo<'a>(a: &dyn Foo) -> B<'a> {
+    B(a)    //~ ERROR explicit lifetime required in the type of `a` [E0621]
+}
+
+fn main() {
+    let _test = foo(&A);
+}
diff --git a/tests/ui/lifetimes/lifetime-bound-whitespace-13703.rs b/tests/ui/lifetimes/lifetime-bound-whitespace-13703.rs
new file mode 100644
index 00000000000..b385e6b9d2e
--- /dev/null
+++ b/tests/ui/lifetimes/lifetime-bound-whitespace-13703.rs
@@ -0,0 +1,5 @@
+//@ check-pass
+
+pub struct Foo<'a, 'b: 'a> { foo: &'a &'b isize }
+pub fn foo<'a, 'b>(x: Foo<'a, 'b>, _o: Option<&   &   ()>) { let _y = x.foo; }
+fn main() {}
diff --git a/tests/ui/lifetimes/missing-lifetime-specifier-13497.rs b/tests/ui/lifetimes/missing-lifetime-specifier-13497.rs
new file mode 100644
index 00000000000..4b2795aa841
--- /dev/null
+++ b/tests/ui/lifetimes/missing-lifetime-specifier-13497.rs
@@ -0,0 +1,8 @@
+fn read_lines_borrowed1() -> Vec<
+    &str //~ ERROR missing lifetime specifier
+> {
+    let rawLines: Vec<String> = vec!["foo  ".to_string(), "  bar".to_string()];
+    rawLines.iter().map(|l| l.trim()).collect()
+}
+
+fn main() {}
diff --git a/tests/ui/lifetimes/ref-pattern-lifetime-annotation-13665.rs b/tests/ui/lifetimes/ref-pattern-lifetime-annotation-13665.rs
new file mode 100644
index 00000000000..e1d8be16f45
--- /dev/null
+++ b/tests/ui/lifetimes/ref-pattern-lifetime-annotation-13665.rs
@@ -0,0 +1,14 @@
+//@ run-pass
+
+fn foo<'r>() {
+  let maybe_value_ref: Option<&'r u8> = None;
+
+  let _ = maybe_value_ref.map(|& ref v| v);
+  let _ = maybe_value_ref.map(|& ref v| -> &'r u8 {v});
+  let _ = maybe_value_ref.map(|& ref v: &'r u8| -> &'r u8 {v});
+  let _ = maybe_value_ref.map(|& ref v: &'r u8| {v});
+}
+
+fn main() {
+  foo();
+}
diff --git a/tests/ui/lifetimes/return-reference-local-variable-13497-2.rs b/tests/ui/lifetimes/return-reference-local-variable-13497-2.rs
new file mode 100644
index 00000000000..c82da0f0096
--- /dev/null
+++ b/tests/ui/lifetimes/return-reference-local-variable-13497-2.rs
@@ -0,0 +1,7 @@
+fn read_lines_borrowed<'a>() -> Vec<&'a str> {
+    let rawLines: Vec<String> = vec!["foo  ".to_string(), "  bar".to_string()];
+    rawLines //~ ERROR cannot return value referencing local variable `rawLines`
+        .iter().map(|l| l.trim()).collect()
+}
+
+fn main() {}
diff --git a/tests/ui/lifetimes/trait-object-constructor-14821.rs b/tests/ui/lifetimes/trait-object-constructor-14821.rs
new file mode 100644
index 00000000000..b11a885b3a0
--- /dev/null
+++ b/tests/ui/lifetimes/trait-object-constructor-14821.rs
@@ -0,0 +1,21 @@
+//@ run-pass
+#![allow(dead_code)]
+#![allow(unused_variables)]
+trait SomeTrait {}
+struct Meow;
+impl SomeTrait for Meow {}
+
+struct Foo<'a> {
+    x: &'a dyn SomeTrait,
+    y: &'a dyn SomeTrait,
+}
+
+impl<'a> Foo<'a> {
+    pub fn new<'b>(x: &'b dyn SomeTrait, y: &'b dyn SomeTrait) -> Foo<'b> { Foo { x: x, y: y } }
+}
+
+fn main() {
+    let r = Meow;
+    let s = Meow;
+    let q = Foo::new(&r as &dyn SomeTrait, &s as &dyn SomeTrait);
+}