about summary refs log tree commit diff
path: root/tests/ui/lifetimes
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2025-08-01 09:59:03 +0200
committerGitHub <noreply@github.com>2025-08-01 09:59:03 +0200
commit37ad0776acbf15b7082bcfed25132193787aab13 (patch)
tree1db017f85a5c62792fdc09e282797925e93dd3d9 /tests/ui/lifetimes
parent6c02dd4eae83befde07dc4782395e2005055e9fa (diff)
parenta4a5bf5a71bd0c3fb52a28f81d88ce1755b3bc30 (diff)
downloadrust-37ad0776acbf15b7082bcfed25132193787aab13.tar.gz
rust-37ad0776acbf15b7082bcfed25132193787aab13.zip
Rollup merge of #144397 - Kivooeo:issue2, r=jieyouxu
`tests/ui/issues/`: The Issues Strike Back [2/N]

Some `tests/ui/issues/` housekeeping, to trim down number of tests directly under `tests/ui/issues/`. Part of https://github.com/rust-lang/rust/issues/133895.

r? ``@jieyouxu``
Diffstat (limited to 'tests/ui/lifetimes')
-rw-r--r--tests/ui/lifetimes/iterator-trait-lifetime-error-13058.rs29
-rw-r--r--tests/ui/lifetimes/iterator-trait-lifetime-error-13058.stderr14
-rw-r--r--tests/ui/lifetimes/lifetime-inference-destructuring-arg.rs26
-rw-r--r--tests/ui/lifetimes/matcher-trait-equality-13323.rs60
-rw-r--r--tests/ui/lifetimes/struct-lifetime-field-assignment-13405.rs21
-rw-r--r--tests/ui/lifetimes/unsafe-transmute-in-find-11740.rs28
6 files changed, 178 insertions, 0 deletions
diff --git a/tests/ui/lifetimes/iterator-trait-lifetime-error-13058.rs b/tests/ui/lifetimes/iterator-trait-lifetime-error-13058.rs
new file mode 100644
index 00000000000..6cfe440b43d
--- /dev/null
+++ b/tests/ui/lifetimes/iterator-trait-lifetime-error-13058.rs
@@ -0,0 +1,29 @@
+//! Regression test for https://github.com/rust-lang/rust/issues/13058
+
+use std::ops::Range;
+
+trait Itble<'r, T, I: Iterator<Item=T>> { fn iter(&'r self) -> I; }
+
+impl<'r> Itble<'r, usize, Range<usize>> for (usize, usize) {
+    fn iter(&'r self) -> Range<usize> {
+        let &(min, max) = self;
+        min..max
+    }
+}
+
+fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &T) -> bool
+{
+    let cont_iter = cont.iter();
+//~^ ERROR explicit lifetime required in the type of `cont` [E0621]
+    let result = cont_iter.fold(Some(0), |state, val| {
+        state.map_or(None, |mask| {
+            let bit = 1 << val;
+            if mask & bit == 0 {Some(mask|bit)} else {None}
+        })
+    });
+    result.is_some()
+}
+
+fn main() {
+    check(&(3, 5));
+}
diff --git a/tests/ui/lifetimes/iterator-trait-lifetime-error-13058.stderr b/tests/ui/lifetimes/iterator-trait-lifetime-error-13058.stderr
new file mode 100644
index 00000000000..e6564e36b21
--- /dev/null
+++ b/tests/ui/lifetimes/iterator-trait-lifetime-error-13058.stderr
@@ -0,0 +1,14 @@
+error[E0621]: explicit lifetime required in the type of `cont`
+  --> $DIR/iterator-trait-lifetime-error-13058.rs:16:21
+   |
+LL |     let cont_iter = cont.iter();
+   |                     ^^^^^^^^^^^ lifetime `'r` required
+   |
+help: add explicit lifetime `'r` to the type of `cont`
+   |
+LL | fn check<'r, I: Iterator<Item=usize>, T: Itble<'r, usize, I>>(cont: &'r T) -> bool
+   |                                                                      ++
+
+error: aborting due to 1 previous error
+
+For more information about this error, try `rustc --explain E0621`.
diff --git a/tests/ui/lifetimes/lifetime-inference-destructuring-arg.rs b/tests/ui/lifetimes/lifetime-inference-destructuring-arg.rs
new file mode 100644
index 00000000000..7a019a71d75
--- /dev/null
+++ b/tests/ui/lifetimes/lifetime-inference-destructuring-arg.rs
@@ -0,0 +1,26 @@
+//! Regression test for https://github.com/rust-lang/rust/issues/13167
+
+//@ check-pass
+//@ revisions: current next
+//@ ignore-compare-mode-next-solver (explicit revisions)
+//@[next] compile-flags: -Znext-solver
+
+use std::slice;
+
+pub struct PhfMapEntries<'a, T: 'a> {
+    iter: slice::Iter<'a, (&'static str, T)>,
+}
+
+impl<'a, T> Iterator for PhfMapEntries<'a, T> {
+    type Item = (&'static str, &'a T);
+
+    fn next(&mut self) -> Option<(&'static str, &'a T)> {
+        self.iter.by_ref().map(|&(key, ref value)| (key, value)).next()
+    }
+
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        self.iter.size_hint()
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/lifetimes/matcher-trait-equality-13323.rs b/tests/ui/lifetimes/matcher-trait-equality-13323.rs
new file mode 100644
index 00000000000..efd56294b39
--- /dev/null
+++ b/tests/ui/lifetimes/matcher-trait-equality-13323.rs
@@ -0,0 +1,60 @@
+//! Regression test for https://github.com/rust-lang/rust/issues/13323
+
+//@ run-pass
+
+struct StrWrap {
+    s: String
+}
+
+impl StrWrap {
+    fn new(s: &str) -> StrWrap {
+        StrWrap { s: s.to_string() }
+    }
+
+    fn get_s<'a>(&'a self) -> &'a str {
+        &self.s
+    }
+}
+
+struct MyStruct {
+    s: StrWrap
+}
+
+impl MyStruct {
+    fn new(s: &str) -> MyStruct {
+        MyStruct { s: StrWrap::new(s) }
+    }
+
+    fn get_str_wrap<'a>(&'a self) -> &'a StrWrap {
+        &self.s
+    }
+}
+
+trait Matcher<T> {
+    fn matches(&self, actual: T) -> bool;
+}
+
+fn assert_that<T, U: Matcher<T>>(actual: T, matcher: &U) {
+    assert!(matcher.matches(actual));
+}
+
+struct EqualTo<T> {
+    expected: T
+}
+
+impl<T: Eq> Matcher<T> for EqualTo<T> {
+    fn matches(&self, actual: T) -> bool {
+        self.expected.eq(&actual)
+    }
+}
+
+fn equal_to<T: Eq>(expected: T) -> Box<EqualTo<T>> {
+    Box::new(EqualTo { expected: expected })
+}
+
+pub fn main() {
+    let my_struct = MyStruct::new("zomg");
+    let s = my_struct.get_str_wrap();
+
+    assert_that(s.get_s(), &*equal_to("zomg"));
+}
diff --git a/tests/ui/lifetimes/struct-lifetime-field-assignment-13405.rs b/tests/ui/lifetimes/struct-lifetime-field-assignment-13405.rs
new file mode 100644
index 00000000000..9482d89681b
--- /dev/null
+++ b/tests/ui/lifetimes/struct-lifetime-field-assignment-13405.rs
@@ -0,0 +1,21 @@
+//! Regression test for https://github.com/rust-lang/rust/issues/13405
+
+//@ check-pass
+#![allow(dead_code)]
+#![allow(unused_variables)]
+
+struct Foo<'a> {
+    i: &'a bool,
+    j: Option<&'a isize>,
+}
+
+impl<'a> Foo<'a> {
+    fn bar(&mut self, j: &isize) {
+        let child = Foo {
+            i: self.i,
+            j: Some(j)
+        };
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/lifetimes/unsafe-transmute-in-find-11740.rs b/tests/ui/lifetimes/unsafe-transmute-in-find-11740.rs
new file mode 100644
index 00000000000..eeecd2e9e40
--- /dev/null
+++ b/tests/ui/lifetimes/unsafe-transmute-in-find-11740.rs
@@ -0,0 +1,28 @@
+//! Regression test for https://github.com/rust-lang/rust/issues/11740
+
+//@ check-pass
+
+struct Attr {
+    name: String,
+    value: String,
+}
+
+struct Element {
+    attrs: Vec<Box<Attr>>,
+}
+
+impl Element {
+    pub unsafe fn get_attr<'a>(&'a self, name: &str) {
+        self.attrs
+            .iter()
+            .find(|attr| {
+                      let attr: &&Box<Attr> = std::mem::transmute(attr);
+                      true
+                  });
+    }
+}
+
+fn main() {
+    let element = Element { attrs: Vec::new() };
+    unsafe { let () = element.get_attr("foo"); };
+}