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 --- .../specialization/specialization-default-types.rs | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 tests/ui/specialization/specialization-default-types.rs (limited to 'tests/ui/specialization/specialization-default-types.rs') diff --git a/tests/ui/specialization/specialization-default-types.rs b/tests/ui/specialization/specialization-default-types.rs new file mode 100644 index 000000000..346471f11 --- /dev/null +++ b/tests/ui/specialization/specialization-default-types.rs @@ -0,0 +1,35 @@ +// It should not be possible to use the concrete value of a defaulted +// associated type in the impl defining it -- otherwise, what happens +// if it's overridden? + +#![feature(specialization)] //~ WARN the feature `specialization` is incomplete + +trait Example { + type Output; + fn generate(self) -> Self::Output; +} + +impl Example for T { + default type Output = Box; + default fn generate(self) -> Self::Output { + Box::new(self) //~ ERROR mismatched types + } +} + +impl Example for bool { + type Output = bool; + fn generate(self) -> bool { self } +} + +fn trouble(t: T) -> Box { + Example::generate(t) //~ ERROR mismatched types +} + +fn weaponize() -> bool { + let b: Box = trouble(true); + *b +} + +fn main() { + weaponize(); +} -- cgit v1.2.3