]> git.lizzy.rs Git - rust.git/blob - src/test/ui/specialization/specialization-default-projection.rs
Auto merge of #75936 - sdroege:chunks-exact-construction-bounds-check, r=nagisa
[rust.git] / src / test / ui / specialization / specialization-default-projection.rs
1 #![feature(specialization)] //~ WARN the feature `specialization` is incomplete
2
3 // Make sure we can't project defaulted associated types
4
5 trait Foo {
6     type Assoc;
7 }
8
9 impl<T> Foo for T {
10     default type Assoc = ();
11 }
12
13 impl Foo for u8 {
14     type Assoc = String;
15 }
16
17 fn generic<T>() -> <T as Foo>::Assoc {
18     // `T` could be some downstream crate type that specializes (or,
19     // for that matter, `u8`).
20
21     () //~ ERROR mismatched types
22 }
23
24 fn monomorphic() -> () {
25     // Even though we know that `()` is not specialized in a
26     // downstream crate, typeck refuses to project here.
27
28     generic::<()>() //~ ERROR mismatched types
29 }
30
31 fn main() {
32     // No error here, we CAN project from `u8`, as there is no `default`
33     // in that impl.
34     let s: String = generic::<u8>();
35     println!("{}", s); // bad news if this all compiles
36 }