]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/specialization/specialization-default-projection.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / specialization / specialization-default-projection.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 #![feature(specialization)]
12
13 // Make sure we can't project defaulted associated types
14
15 trait Foo {
16 type Assoc;
17 }
18
19 impl<T> Foo for T {
20 default type Assoc = ();
21 }
22
23 impl Foo for u8 {
24 type Assoc = String;
25 }
26
27 fn generic<T>() -> <T as Foo>::Assoc {
28 // `T` could be some downstream crate type that specializes (or,
29 // for that matter, `u8`).
30
31 () //~ ERROR mismatched types
32 }
33
34 fn monomorphic() -> () {
35 // Even though we know that `()` is not specialized in a
36 // downstream crate, typeck refuses to project here.
37
38 generic::<()>() //~ ERROR mismatched types
39 }
40
41 fn main() {
42 // No error here, we CAN project from `u8`, as there is no `default`
43 // in that impl.
44 let s: String = generic::<u8>();
45 println!("{}", s); // bad news if this all compiles
46 }