about summary refs log tree commit diff
path: root/tests/ui/traits
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/traits
parent0f353363965ebf05e0757f7679c800b39c51a07e (diff)
downloadrust-62c92f30cf02fc56b8a774c77097f1111dc2f4ea.tar.gz
rust-62c92f30cf02fc56b8a774c77097f1111dc2f4ea.zip
moved 35 tests to organized locations
Diffstat (limited to 'tests/ui/traits')
-rw-r--r--tests/ui/traits/impl-trait-chain-14229.rs21
-rw-r--r--tests/ui/traits/matcher-lifetime-inference-14919.rs54
-rw-r--r--tests/ui/traits/pointer-type-impls-14254.rs92
-rw-r--r--tests/ui/traits/reader-wrapper-trait-14901.rs18
-rw-r--r--tests/ui/traits/trait-bound-mismatch-14853.rs20
5 files changed, 205 insertions, 0 deletions
diff --git a/tests/ui/traits/impl-trait-chain-14229.rs b/tests/ui/traits/impl-trait-chain-14229.rs
new file mode 100644
index 00000000000..eb6324da3b6
--- /dev/null
+++ b/tests/ui/traits/impl-trait-chain-14229.rs
@@ -0,0 +1,21 @@
+//@ run-pass
+trait Foo: Sized {
+    fn foo(self) {}
+}
+
+trait Bar: Sized {
+    fn bar(self) {}
+}
+
+struct S;
+
+impl<'l> Foo for &'l S {}
+
+impl<T: Foo> Bar for T {}
+
+fn main() {
+    let s = S;
+    s.foo();
+    (&s).bar();
+    s.bar();
+}
diff --git a/tests/ui/traits/matcher-lifetime-inference-14919.rs b/tests/ui/traits/matcher-lifetime-inference-14919.rs
new file mode 100644
index 00000000000..3a834b13d07
--- /dev/null
+++ b/tests/ui/traits/matcher-lifetime-inference-14919.rs
@@ -0,0 +1,54 @@
+//@ run-pass
+#![allow(unused_must_use)]
+#![allow(dead_code)]
+
+trait Matcher {
+    fn next_match(&mut self) -> Option<(usize, usize)>;
+}
+
+struct CharPredMatcher<'a, 'b> {
+    str: &'a str,
+    pred: Box<dyn FnMut(char) -> bool + 'b>,
+}
+
+impl<'a, 'b> Matcher for CharPredMatcher<'a, 'b> {
+    fn next_match(&mut self) -> Option<(usize, usize)> {
+        None
+    }
+}
+
+trait IntoMatcher<'a, T> {
+    fn into_matcher(self, _: &'a str) -> T;
+}
+
+impl<'a, 'b, F> IntoMatcher<'a, CharPredMatcher<'a, 'b>> for F where F: FnMut(char) -> bool + 'b {
+    fn into_matcher(self, s: &'a str) -> CharPredMatcher<'a, 'b> {
+        CharPredMatcher {
+            str: s,
+            pred: Box::new(self),
+        }
+    }
+}
+
+struct MatchIndices<M> {
+    matcher: M
+}
+
+impl<M: Matcher> Iterator for MatchIndices<M> {
+    type Item = (usize, usize);
+
+    fn next(&mut self) -> Option<(usize, usize)> {
+        self.matcher.next_match()
+    }
+}
+
+fn match_indices<'a, M, T: IntoMatcher<'a, M>>(s: &'a str, from: T) -> MatchIndices<M> {
+    let string_matcher = from.into_matcher(s);
+    MatchIndices { matcher: string_matcher }
+}
+
+fn main() {
+    let s = "abcbdef";
+    match_indices(s, |c: char| c == 'b')
+        .collect::<Vec<_>>();
+}
diff --git a/tests/ui/traits/pointer-type-impls-14254.rs b/tests/ui/traits/pointer-type-impls-14254.rs
new file mode 100644
index 00000000000..90ad375c262
--- /dev/null
+++ b/tests/ui/traits/pointer-type-impls-14254.rs
@@ -0,0 +1,92 @@
+//@ check-pass
+
+trait Foo: Sized {
+    fn bar(&self);
+    fn baz(&self) { }
+    fn bah(_: Option<Self>) { }
+}
+
+struct BarTy {
+    x : isize,
+    y : f64,
+}
+
+impl BarTy {
+    fn a() {}
+    fn b(&self) {}
+}
+
+// If these fail, it's necessary to update rustc_resolve and the cfail tests.
+impl Foo for *const BarTy {
+    fn bar(&self) {
+        self.baz();
+        BarTy::a();
+        Foo::bah(None::<*const BarTy>);
+    }
+}
+
+// If these fail, it's necessary to update rustc_resolve and the cfail tests.
+impl<'a> Foo for &'a BarTy {
+    fn bar(&self) {
+        self.baz();
+        self.x;
+        self.y;
+        BarTy::a();
+        Foo::bah(None::<&BarTy>);
+        self.b();
+    }
+}
+
+// If these fail, it's necessary to update rustc_resolve and the cfail tests.
+impl<'a> Foo for &'a mut BarTy {
+    fn bar(&self) {
+        self.baz();
+        self.x;
+        self.y;
+        BarTy::a();
+        Foo::bah(None::<&mut BarTy>);
+        self.b();
+    }
+}
+
+// If these fail, it's necessary to update rustc_resolve and the cfail tests.
+impl Foo for Box<BarTy> {
+    fn bar(&self) {
+        self.baz();
+        Foo::bah(None::<Box<BarTy>>);
+    }
+}
+
+// If these fail, it's necessary to update rustc_resolve and the cfail tests.
+impl Foo for *const isize {
+    fn bar(&self) {
+        self.baz();
+        Foo::bah(None::<*const isize>);
+    }
+}
+
+// If these fail, it's necessary to update rustc_resolve and the cfail tests.
+impl<'a> Foo for &'a isize {
+    fn bar(&self) {
+        self.baz();
+        Foo::bah(None::<&isize>);
+    }
+}
+
+// If these fail, it's necessary to update rustc_resolve and the cfail tests.
+impl<'a> Foo for &'a mut isize {
+    fn bar(&self) {
+        self.baz();
+        Foo::bah(None::<&mut isize>);
+    }
+}
+
+// If these fail, it's necessary to update rustc_resolve and the cfail tests.
+impl Foo for Box<isize> {
+    fn bar(&self) {
+        self.baz();
+        Foo::bah(None::<Box<isize>>);
+    }
+}
+
+fn main() {}
diff --git a/tests/ui/traits/reader-wrapper-trait-14901.rs b/tests/ui/traits/reader-wrapper-trait-14901.rs
new file mode 100644
index 00000000000..ddc12b9ef3c
--- /dev/null
+++ b/tests/ui/traits/reader-wrapper-trait-14901.rs
@@ -0,0 +1,18 @@
+//@ check-pass
+pub trait Reader {}
+
+enum Wrapper<'a> {
+    WrapReader(&'a (dyn Reader + 'a))
+}
+
+trait Wrap<'a> {
+    fn wrap(self) -> Wrapper<'a>;
+}
+
+impl<'a, R: Reader> Wrap<'a> for &'a mut R {
+    fn wrap(self) -> Wrapper<'a> {
+        Wrapper::WrapReader(self as &'a mut dyn Reader)
+    }
+}
+
+pub fn main() {}
diff --git a/tests/ui/traits/trait-bound-mismatch-14853.rs b/tests/ui/traits/trait-bound-mismatch-14853.rs
new file mode 100644
index 00000000000..4ce6e3174d0
--- /dev/null
+++ b/tests/ui/traits/trait-bound-mismatch-14853.rs
@@ -0,0 +1,20 @@
+use std::fmt::Debug;
+
+trait Str {}
+
+trait Something: Sized {
+    fn yay<T: Debug>(_: Option<Self>, thing: &[T]);
+}
+
+struct X { data: u32 }
+
+impl Something for X {
+    fn yay<T: Str>(_:Option<X>, thing: &[T]) {
+    //~^ ERROR E0276
+    }
+}
+
+fn main() {
+    let arr = &["one", "two", "three"];
+    println!("{:?}", Something::yay(None::<X>, arr));
+}