diff options
| author | Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> | 2023-01-05 09:13:28 +0100 |
|---|---|---|
| committer | Albert Larsan <74931857+albertlarsan68@users.noreply.github.com> | 2023-01-11 09:32:08 +0000 |
| commit | cf2dff2b1e3fa55fa5415d524200070d0d7aacfe (patch) | |
| tree | 40a88d9a46aaf3e8870676eb2538378b75a263eb /tests/ui/specialization/defaultimpl/specialization-no-default.rs | |
| parent | ca855e6e42787ecd062d81d53336fe6788ef51a9 (diff) | |
| download | rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.tar.gz rust-cf2dff2b1e3fa55fa5415d524200070d0d7aacfe.zip | |
Move /src/test to /tests
Diffstat (limited to 'tests/ui/specialization/defaultimpl/specialization-no-default.rs')
| -rw-r--r-- | tests/ui/specialization/defaultimpl/specialization-no-default.rs | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/ui/specialization/defaultimpl/specialization-no-default.rs b/tests/ui/specialization/defaultimpl/specialization-no-default.rs new file mode 100644 index 00000000000..661724eef8a --- /dev/null +++ b/tests/ui/specialization/defaultimpl/specialization-no-default.rs @@ -0,0 +1,77 @@ +#![feature(specialization)] //~ WARN the feature `specialization` is incomplete + +// Check a number of scenarios in which one impl tries to override another, +// without correctly using `default`. + +// Test 1: one layer of specialization, multiple methods, missing `default` + +trait Foo { + fn foo(&self); + fn bar(&self); +} + +impl<T> Foo for T { + fn foo(&self) {} + fn bar(&self) {} +} + +impl Foo for u8 {} +impl Foo for u16 { + fn foo(&self) {} //~ ERROR E0520 +} +impl Foo for u32 { + fn bar(&self) {} //~ ERROR E0520 +} + +// Test 2: one layer of specialization, missing `default` on associated type + +trait Bar { + type T; +} + +impl<T> Bar for T { + type T = u8; +} + +impl Bar for u8 { + type T = (); //~ ERROR E0520 +} + +// Test 3a: multiple layers of specialization, missing interior `default` + +trait Baz { + fn baz(&self); +} + +default impl<T> Baz for T { + fn baz(&self) {} +} + +impl<T: Clone> Baz for T { + fn baz(&self) {} +} + +impl Baz for i32 { + fn baz(&self) {} //~ ERROR E0520 +} + +// Test 3b: multiple layers of specialization, missing interior `default`, +// redundant `default` in bottom layer. + +trait Redundant { + fn redundant(&self); +} + +default impl<T> Redundant for T { + fn redundant(&self) {} +} + +impl<T: Clone> Redundant for T { + fn redundant(&self) {} +} + +default impl Redundant for i32 { + fn redundant(&self) {} //~ ERROR E0520 +} + +fn main() {} |
