summaryrefslogtreecommitdiffstats
path: root/tests/ui/traits/auxiliary
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/traits/auxiliary
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/traits/auxiliary')
-rw-r--r--tests/ui/traits/auxiliary/anon_trait_static_method_lib.rs9
-rw-r--r--tests/ui/traits/auxiliary/go_trait.rs43
-rw-r--r--tests/ui/traits/auxiliary/issue_89119_intercrate_caching.rs60
-rw-r--r--tests/ui/traits/auxiliary/trait_safety_lib.rs9
-rw-r--r--tests/ui/traits/auxiliary/traitimpl.rs7
5 files changed, 128 insertions, 0 deletions
diff --git a/tests/ui/traits/auxiliary/anon_trait_static_method_lib.rs b/tests/ui/traits/auxiliary/anon_trait_static_method_lib.rs
new file mode 100644
index 000000000..dceec7e3e
--- /dev/null
+++ b/tests/ui/traits/auxiliary/anon_trait_static_method_lib.rs
@@ -0,0 +1,9 @@
+pub struct Foo {
+ pub x: isize
+}
+
+impl Foo {
+ pub fn new() -> Foo {
+ Foo { x: 3 }
+ }
+}
diff --git a/tests/ui/traits/auxiliary/go_trait.rs b/tests/ui/traits/auxiliary/go_trait.rs
new file mode 100644
index 000000000..aa0ec2289
--- /dev/null
+++ b/tests/ui/traits/auxiliary/go_trait.rs
@@ -0,0 +1,43 @@
+#![feature(specialization)]
+
+// Common code used for tests that model the Fn/FnMut/FnOnce hierarchy.
+
+pub trait Go {
+ fn go(&self, arg: isize);
+}
+
+pub fn go<G:Go>(this: &G, arg: isize) {
+ this.go(arg)
+}
+
+pub trait GoMut {
+ fn go_mut(&mut self, arg: isize);
+}
+
+pub fn go_mut<G:GoMut>(this: &mut G, arg: isize) {
+ this.go_mut(arg)
+}
+
+pub trait GoOnce {
+ fn go_once(self, arg: isize);
+}
+
+pub fn go_once<G:GoOnce>(this: G, arg: isize) {
+ this.go_once(arg)
+}
+
+impl<G> GoMut for G
+ where G : Go
+{
+ default fn go_mut(&mut self, arg: isize) {
+ go(&*self, arg)
+ }
+}
+
+impl<G> GoOnce for G
+ where G : GoMut
+{
+ default fn go_once(mut self, arg: isize) {
+ go_mut(&mut self, arg)
+ }
+}
diff --git a/tests/ui/traits/auxiliary/issue_89119_intercrate_caching.rs b/tests/ui/traits/auxiliary/issue_89119_intercrate_caching.rs
new file mode 100644
index 000000000..769e89731
--- /dev/null
+++ b/tests/ui/traits/auxiliary/issue_89119_intercrate_caching.rs
@@ -0,0 +1,60 @@
+// This is the auxiliary crate for the regression test for issue #89119, minimized
+// from `zvariant-2.8.0`.
+
+use std::convert::TryFrom;
+use std::borrow::Cow;
+
+pub struct Str<'a>(Cow<'a, str>);
+impl<'a> Str<'a> {
+ pub fn to_owned(&self) -> Str<'static> {
+ todo!()
+ }
+}
+
+pub enum Value<'a> {
+ Str(Str<'a>),
+ Value(Box<Value<'a>>),
+}
+impl<'a> Value<'a> {
+ pub fn to_owned(&self) -> Value<'static> {
+ match self {
+ Value::Str(v) => Value::Str(v.to_owned()),
+ Value::Value(v) => {
+ let o = OwnedValue::from(&**v);
+ Value::Value(Box::new(o.into_inner()))
+ }
+ }
+ }
+}
+
+struct OwnedValue(Value<'static>);
+impl OwnedValue {
+ pub(crate) fn into_inner(self) -> Value<'static> {
+ todo!()
+ }
+}
+impl<'a, T> TryFrom<OwnedValue> for Vec<T>
+where
+ T: TryFrom<Value<'a>, Error = ()>,
+{
+ type Error = ();
+ fn try_from(_: OwnedValue) -> Result<Self, Self::Error> {
+ todo!()
+ }
+}
+impl TryFrom<OwnedValue> for Vec<OwnedValue> {
+ type Error = ();
+ fn try_from(_: OwnedValue) -> Result<Self, Self::Error> {
+ todo!()
+ }
+}
+impl<'a> From<Value<'a>> for OwnedValue {
+ fn from(_: Value<'a>) -> Self {
+ todo!()
+ }
+}
+impl<'a> From<&Value<'a>> for OwnedValue {
+ fn from(_: &Value<'a>) -> Self {
+ todo!()
+ }
+}
diff --git a/tests/ui/traits/auxiliary/trait_safety_lib.rs b/tests/ui/traits/auxiliary/trait_safety_lib.rs
new file mode 100644
index 000000000..6fc432ed4
--- /dev/null
+++ b/tests/ui/traits/auxiliary/trait_safety_lib.rs
@@ -0,0 +1,9 @@
+// Simple smoke test that unsafe traits can be compiled etc.
+
+pub unsafe trait Foo {
+ fn foo(&self) -> isize;
+}
+
+unsafe impl Foo for isize {
+ fn foo(&self) -> isize { *self }
+}
diff --git a/tests/ui/traits/auxiliary/traitimpl.rs b/tests/ui/traits/auxiliary/traitimpl.rs
new file mode 100644
index 000000000..fda5314cd
--- /dev/null
+++ b/tests/ui/traits/auxiliary/traitimpl.rs
@@ -0,0 +1,7 @@
+// Test inherent trait impls work cross-crait.
+
+pub trait Bar<'a> : 'a {}
+
+impl<'a> Bar<'a> {
+ pub fn bar(&self) {}
+}