diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:03 +0000 |
commit | 64d98f8ee037282c35007b64c2649055c56af1db (patch) | |
tree | 5492bcf97fce41ee1c0b1cc2add283f3e66cdab0 /tests/ui/traits/alias/bounds.rs | |
parent | Adding debian version 1.67.1+dfsg1-1. (diff) | |
download | rustc-64d98f8ee037282c35007b64c2649055c56af1db.tar.xz rustc-64d98f8ee037282c35007b64c2649055c56af1db.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/traits/alias/bounds.rs')
-rw-r--r-- | tests/ui/traits/alias/bounds.rs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/ui/traits/alias/bounds.rs b/tests/ui/traits/alias/bounds.rs new file mode 100644 index 000000000..b97eb38c5 --- /dev/null +++ b/tests/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>(); +} |