]> git.lizzy.rs Git - rust.git/blob - src/test/ui/specialization/specialization-default-types.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / specialization / specialization-default-types.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // It should not be possible to use the concrete value of a defaulted
12 // associated type in the impl defining it -- otherwise, what happens
13 // if it's overridden?
14
15 #![feature(specialization)]
16
17 trait Example {
18     type Output;
19     fn generate(self) -> Self::Output;
20 }
21
22 impl<T> Example for T {
23     default type Output = Box<T>;
24     default fn generate(self) -> Self::Output {
25         Box::new(self) //~ ERROR mismatched types
26     }
27 }
28
29 impl Example for bool {
30     type Output = bool;
31     fn generate(self) -> bool { self }
32 }
33
34 fn trouble<T>(t: T) -> Box<T> {
35     Example::generate(t) //~ ERROR mismatched types
36 }
37
38 fn weaponize() -> bool {
39     let b: Box<bool> = trouble(true);
40     *b
41 }
42
43 fn main() {
44     weaponize();
45 }