diff options
Diffstat (limited to 'tests/ui/traits/auxiliary')
-rw-r--r-- | tests/ui/traits/auxiliary/anon_trait_static_method_lib.rs | 9 | ||||
-rw-r--r-- | tests/ui/traits/auxiliary/go_trait.rs | 43 | ||||
-rw-r--r-- | tests/ui/traits/auxiliary/issue_89119_intercrate_caching.rs | 60 | ||||
-rw-r--r-- | tests/ui/traits/auxiliary/trait_safety_lib.rs | 9 | ||||
-rw-r--r-- | tests/ui/traits/auxiliary/traitimpl.rs | 7 |
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) {} +} |