]> git.lizzy.rs Git - rust.git/blob - src/test/ui/specialization/specialization-no-default.rs
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
[rust.git] / src / test / ui / specialization / specialization-no-default.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 // Check a number of scenarios in which one impl tries to override another,
14 // without correctly using `default`.
15
16 ////////////////////////////////////////////////////////////////////////////////
17 // Test 1: one layer of specialization, multiple methods, missing `default`
18 ////////////////////////////////////////////////////////////////////////////////
19
20 trait Foo {
21     fn foo(&self);
22     fn bar(&self);
23 }
24
25 impl<T> Foo for T {
26     fn foo(&self) {}
27     fn bar(&self) {}
28 }
29
30 impl Foo for u8 {}
31 impl Foo for u16 {
32     fn foo(&self) {} //~ ERROR E0520
33 }
34 impl Foo for u32 {
35     fn bar(&self) {} //~ ERROR E0520
36 }
37
38 ////////////////////////////////////////////////////////////////////////////////
39 // Test 2: one layer of specialization, missing `default` on associated type
40 ////////////////////////////////////////////////////////////////////////////////
41
42 trait Bar {
43     type T;
44 }
45
46 impl<T> Bar for T {
47     type T = u8;
48 }
49
50 impl Bar for u8 {
51     type T = (); //~ ERROR E0520
52 }
53
54 ////////////////////////////////////////////////////////////////////////////////
55 // Test 3a: multiple layers of specialization, missing interior `default`
56 ////////////////////////////////////////////////////////////////////////////////
57
58 trait Baz {
59     fn baz(&self);
60 }
61
62 impl<T> Baz for T {
63     default fn baz(&self) {}
64 }
65
66 impl<T: Clone> Baz for T {
67     fn baz(&self) {}
68 }
69
70 impl Baz for i32 {
71     fn baz(&self) {} //~ ERROR E0520
72 }
73
74 ////////////////////////////////////////////////////////////////////////////////
75 // Test 3b: multiple layers of specialization, missing interior `default`,
76 // redundant `default` in bottom layer.
77 ////////////////////////////////////////////////////////////////////////////////
78
79 trait Redundant {
80     fn redundant(&self);
81 }
82
83 impl<T> Redundant for T {
84     default fn redundant(&self) {}
85 }
86
87 impl<T: Clone> Redundant for T {
88     fn redundant(&self) {}
89 }
90
91 impl Redundant for i32 {
92     default fn redundant(&self) {} //~ ERROR E0520
93 }
94
95 fn main() {}