Skip to content

Commit 24ec364

Browse files
Test mixed default and non-default
1 parent c8da9ee commit 24ec364

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// compile-fail
2+
3+
#![feature(associated_type_defaults)]
4+
5+
// Tests that a trait with one defaulted and one non-defaulted assoc. type behaves properly.
6+
7+
trait Trait {
8+
type Foo = u8;
9+
type Bar;
10+
}
11+
12+
// `Bar` must be specified
13+
impl Trait for () {}
14+
//~^ error: not all trait items implemented, missing: `Bar`
15+
16+
impl Trait for bool {
17+
//~^ error: not all trait items implemented, missing: `Bar`
18+
type Foo = ();
19+
}
20+
21+
impl Trait for u8 {
22+
type Bar = ();
23+
}
24+
25+
impl Trait for u16 {
26+
type Foo = String;
27+
type Bar = bool;
28+
}
29+
30+
fn main() {
31+
let _: <u8 as Trait>::Foo = 0u8;
32+
let _: <u8 as Trait>::Bar = ();
33+
34+
let _: <u16 as Trait>::Foo = String::new();
35+
let _: <u16 as Trait>::Bar = true;
36+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0046]: not all trait items implemented, missing: `Bar`
2+
--> $DIR/defaults-mixed.rs:13:1
3+
|
4+
LL | type Bar;
5+
| --------- `Bar` from trait
6+
...
7+
LL | impl Trait for () {}
8+
| ^^^^^^^^^^^^^^^^^ missing `Bar` in implementation
9+
10+
error[E0046]: not all trait items implemented, missing: `Bar`
11+
--> $DIR/defaults-mixed.rs:16:1
12+
|
13+
LL | type Bar;
14+
| --------- `Bar` from trait
15+
...
16+
LL | impl Trait for bool {
17+
| ^^^^^^^^^^^^^^^^^^^ missing `Bar` in implementation
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0046`.

0 commit comments

Comments
 (0)