From 218caa410aa38c29984be31a5229b9fa717560ee Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:13 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- .../ui/specialization/specialization-no-default.rs | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 tests/ui/specialization/specialization-no-default.rs (limited to 'tests/ui/specialization/specialization-no-default.rs') diff --git a/tests/ui/specialization/specialization-no-default.rs b/tests/ui/specialization/specialization-no-default.rs new file mode 100644 index 000000000..ae739b235 --- /dev/null +++ b/tests/ui/specialization/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 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 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); +} + +impl Baz for T { + default fn baz(&self) {} +} + +impl 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); +} + +impl Redundant for T { + default fn redundant(&self) {} +} + +impl Redundant for T { + fn redundant(&self) {} +} + +impl Redundant for i32 { + default fn redundant(&self) {} //~ ERROR E0520 +} + +fn main() {} -- cgit v1.2.3