]> git.lizzy.rs Git - rust.git/blob - tests/ui/specialization/specialization-default-types.rs
Rollup merge of #106638 - RalfJung:realstd, r=thomcc
[rust.git] / tests / ui / specialization / specialization-default-types.rs
1 // It should not be possible to use the concrete value of a defaulted
2 // associated type in the impl defining it -- otherwise, what happens
3 // if it's overridden?
4
5 #![feature(specialization)] //~ WARN the feature `specialization` is incomplete
6
7 trait Example {
8     type Output;
9     fn generate(self) -> Self::Output;
10 }
11
12 impl<T> Example for T {
13     default type Output = Box<T>;
14     default fn generate(self) -> Self::Output {
15         Box::new(self) //~ ERROR mismatched types
16     }
17 }
18
19 impl Example for bool {
20     type Output = bool;
21     fn generate(self) -> bool { self }
22 }
23
24 fn trouble<T>(t: T) -> Box<T> {
25     Example::generate(t) //~ ERROR mismatched types
26 }
27
28 fn weaponize() -> bool {
29     let b: Box<bool> = trouble(true);
30     *b
31 }
32
33 fn main() {
34     weaponize();
35 }