diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /src/test/ui/traits/alias/bounds.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/test/ui/traits/alias/bounds.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/test/ui/traits/alias/bounds.rs b/src/test/ui/traits/alias/bounds.rs new file mode 100644 index 000000000..b97eb38c5 --- /dev/null +++ b/src/test/ui/traits/alias/bounds.rs @@ -0,0 +1,57 @@ +// run-pass + +#![feature(trait_alias)] + +use std::marker::PhantomData; + +trait Empty {} +trait EmptyAlias = Empty; +trait CloneDefault = Clone + Default; +trait SendSyncAlias = Send + Sync; +trait WhereSendAlias = where Self: Send; +trait SendEqAlias<T> = Send where T: PartialEq<Self>; +trait I32Iterator = Iterator<Item = i32>; + +#[allow(dead_code)] +struct Foo<T: SendSyncAlias>(PhantomData<T>); +#[allow(dead_code)] +struct Bar<T>(PhantomData<T>) where T: SendSyncAlias; + +impl dyn EmptyAlias {} + +impl<T: SendSyncAlias> Empty for T {} + +fn a<T: CloneDefault>() -> (T, T) { + let one = T::default(); + let two = one.clone(); + (one, two) +} + +fn b(x: &impl SendEqAlias<i32>) -> bool { + 22_i32 == *x +} + +fn c<T: I32Iterator>(x: &mut T) -> Option<i32> { + x.next() +} + +fn d<T: SendSyncAlias>() { + is_send_and_sync::<T>(); +} + +fn is_send_and_sync<T: Send + Sync>() {} + +fn main() { + let both = a::<i32>(); + assert_eq!(both.0, 0); + assert_eq!(both.1, 0); + let both: (i32, i32) = a(); + assert_eq!(both.0, 0); + assert_eq!(both.1, 0); + + assert!(b(&22)); + + assert_eq!(c(&mut vec![22].into_iter()), Some(22)); + + d::<i32>(); +} |