diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-07-27 01:33:01 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2019-07-27 18:56:16 +0300 |
| commit | 9be35f82c1abf2ecbab489bca9eca138ea648312 (patch) | |
| tree | 69888506e34af447d9748c0d542de3ba1dd76210 /src/test/ui/chalkify | |
| parent | ca9faa52f5ada0054b1fa27d97aedf448afb059b (diff) | |
| download | rust-9be35f82c1abf2ecbab489bca9eca138ea648312.tar.gz rust-9be35f82c1abf2ecbab489bca9eca138ea648312.zip | |
tests: Move run-pass tests without naming conflicts to ui
Diffstat (limited to 'src/test/ui/chalkify')
| -rw-r--r-- | src/test/ui/chalkify/builtin-copy-clone.rs | 44 | ||||
| -rw-r--r-- | src/test/ui/chalkify/inherent_impl.rs | 42 | ||||
| -rw-r--r-- | src/test/ui/chalkify/projection.rs | 25 | ||||
| -rw-r--r-- | src/test/ui/chalkify/super_trait.rs | 19 | ||||
| -rw-r--r-- | src/test/ui/chalkify/trait_implied_bound.rs | 18 | ||||
| -rw-r--r-- | src/test/ui/chalkify/type_implied_bound.rs | 29 |
6 files changed, 177 insertions, 0 deletions
diff --git a/src/test/ui/chalkify/builtin-copy-clone.rs b/src/test/ui/chalkify/builtin-copy-clone.rs new file mode 100644 index 00000000000..d403514b553 --- /dev/null +++ b/src/test/ui/chalkify/builtin-copy-clone.rs @@ -0,0 +1,44 @@ +// run-pass +// compile-flags: -Z chalk + +// Test that `Clone` is correctly implemented for builtin types. + +#[derive(Copy, Clone)] +struct S(i32); + +fn test_clone<T: Clone>(arg: T) { + let _ = arg.clone(); +} + +fn test_copy<T: Copy>(arg: T) { + let _ = arg; + let _ = arg; +} + +fn test_copy_clone<T: Copy + Clone>(arg: T) { + test_copy(arg); + test_clone(arg); +} + +fn foo() { } + +fn main() { + test_copy_clone(foo); + let f: fn() = foo; + test_copy_clone(f); + // FIXME: add closures when they're considered WF + test_copy_clone([1; 56]); + test_copy_clone((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)); + test_copy_clone((1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, true, 'a', 1.1)); + test_copy_clone(()); + test_copy_clone(((1, 1), (1, 1, 1), (1.1, 1, 1, 'a'), ())); + + let a = ( + (S(1), S(0)), + ( + (S(0), S(0), S(1)), + S(0) + ) + ); + test_copy_clone(a); +} diff --git a/src/test/ui/chalkify/inherent_impl.rs b/src/test/ui/chalkify/inherent_impl.rs new file mode 100644 index 00000000000..44e120c1eeb --- /dev/null +++ b/src/test/ui/chalkify/inherent_impl.rs @@ -0,0 +1,42 @@ +// run-pass +// compile-flags: -Z chalk + +trait Foo { } + +impl Foo for i32 { } + +struct S<T: Foo> { + x: T, +} + +fn only_foo<T: Foo>(_x: &T) { } + +impl<T> S<T> { + // Test that we have the correct environment inside an inherent method. + fn dummy_foo(&self) { + only_foo(&self.x) + } +} + +trait Bar { } +impl Bar for u32 { } + +fn only_bar<T: Bar>() { } + +impl<T> S<T> { + // Test that the environment of `dummy_bar` adds up with the environment + // of the inherent impl. + fn dummy_bar<U: Bar>(&self) { + only_foo(&self.x); + only_bar::<U>(); + } +} + +fn main() { + let s = S { + x: 5, + }; + + s.dummy_foo(); + s.dummy_bar::<u32>(); +} diff --git a/src/test/ui/chalkify/projection.rs b/src/test/ui/chalkify/projection.rs new file mode 100644 index 00000000000..d6a8dd7a4a2 --- /dev/null +++ b/src/test/ui/chalkify/projection.rs @@ -0,0 +1,25 @@ +// run-pass +// compile-flags: -Z chalk + +trait Foo { } + +trait Bar { + type Item: Foo; +} + +impl Foo for i32 { } +impl Bar for i32 { + type Item = i32; +} + +fn only_foo<T: Foo>() { } + +fn only_bar<T: Bar>() { + // `T` implements `Bar` hence `<T as Bar>::Item` must also implement `Bar` + only_foo::<T::Item>() +} + +fn main() { + only_bar::<i32>(); + only_foo::<<i32 as Bar>::Item>(); +} diff --git a/src/test/ui/chalkify/super_trait.rs b/src/test/ui/chalkify/super_trait.rs new file mode 100644 index 00000000000..eeff9fd9b80 --- /dev/null +++ b/src/test/ui/chalkify/super_trait.rs @@ -0,0 +1,19 @@ +// run-pass +// compile-flags: -Z chalk + +trait Foo { } +trait Bar: Foo { } + +impl Foo for i32 { } +impl Bar for i32 { } + +fn only_foo<T: Foo>() { } + +fn only_bar<T: Bar>() { + // `T` implements `Bar` hence `T` must also implement `Foo` + only_foo::<T>() +} + +fn main() { + only_bar::<i32>() +} diff --git a/src/test/ui/chalkify/trait_implied_bound.rs b/src/test/ui/chalkify/trait_implied_bound.rs new file mode 100644 index 00000000000..8a2e1cf5990 --- /dev/null +++ b/src/test/ui/chalkify/trait_implied_bound.rs @@ -0,0 +1,18 @@ +// run-pass +// compile-flags: -Z chalk + +trait Foo { } +trait Bar<U> where U: Foo { } + +impl Foo for i32 { } +impl Bar<i32> for i32 { } + +fn only_foo<T: Foo>() { } + +fn only_bar<U, T: Bar<U>>() { + only_foo::<U>() +} + +fn main() { + only_bar::<i32, i32>() +} diff --git a/src/test/ui/chalkify/type_implied_bound.rs b/src/test/ui/chalkify/type_implied_bound.rs new file mode 100644 index 00000000000..8673f5319bd --- /dev/null +++ b/src/test/ui/chalkify/type_implied_bound.rs @@ -0,0 +1,29 @@ +// run-pass +// compile-flags: -Z chalk + +trait Eq { } +trait Hash: Eq { } + +impl Eq for i32 { } +impl Hash for i32 { } + +struct Set<T: Hash> { + _x: T, +} + +fn only_eq<T: Eq>() { } + +fn take_a_set<T>(_: &Set<T>) { + // `Set<T>` is an input type of `take_a_set`, hence we know that + // `T` must implement `Hash`, and we know in turn that `T` must + // implement `Eq`. + only_eq::<T>() +} + +fn main() { + let set = Set { + _x: 5, + }; + + take_a_set(&set); +} |
