Skip to content

Commit 41e3cc4

Browse files
committed
Add some tests around (lack of) object safety of associated types and consts
1 parent 23a76a8 commit 41e3cc4

10 files changed

+141
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait Foo<T> {
2+
const BAR: bool
3+
where //~ ERROR: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `=`, found keyword `where`
4+
Self: Sized;
5+
}
6+
7+
trait Cake {}
8+
impl Cake for () {}
9+
10+
fn foo(_: &dyn Foo<()>) {}
11+
fn bar(_: &dyn Foo<i32>) {}
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `=`, found keyword `where`
2+
--> $DIR/assoc_const_bounds.rs:3:9
3+
|
4+
LL | trait Foo<T> {
5+
| - while parsing this item list starting here
6+
LL | const BAR: bool
7+
| - expected one of 7 possible tokens
8+
LL | where
9+
| ^^^^^ unexpected token
10+
LL | Self: Sized;
11+
LL | }
12+
| - the item list ends here
13+
14+
error: aborting due to previous error
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Foo {
2+
const BAR: bool
3+
where //~ ERROR: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `=`, found keyword `where`
4+
Self: Sized;
5+
}
6+
7+
fn foo(_: &dyn Foo) {}
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error: expected one of `!`, `(`, `+`, `::`, `;`, `<`, or `=`, found keyword `where`
2+
--> $DIR/assoc_const_bounds_sized.rs:3:9
3+
|
4+
LL | trait Foo {
5+
| - while parsing this item list starting here
6+
LL | const BAR: bool
7+
| - expected one of 7 possible tokens
8+
LL | where
9+
| ^^^^^ unexpected token
10+
LL | Self: Sized;
11+
LL | }
12+
| - the item list ends here
13+
14+
error: aborting due to previous error
15+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait Foo<T> {
2+
type Bar
3+
where
4+
T: Cake;
5+
}
6+
7+
trait Cake {}
8+
impl Cake for () {}
9+
10+
fn foo(_: &dyn Foo<()>) {} //~ ERROR: the value of the associated type `Bar` (from trait `Foo`) must be specified
11+
fn bar(_: &dyn Foo<i32>) {} //~ ERROR: the value of the associated type `Bar` (from trait `Foo`) must be specified
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0191]: the value of the associated type `Bar` (from trait `Foo`) must be specified
2+
--> $DIR/assoc_type_bounds.rs:10:16
3+
|
4+
LL | type Bar
5+
| -------- `Bar` defined here
6+
...
7+
LL | fn foo(_: &dyn Foo<()>) {}
8+
| ^^^^^^^ help: specify the associated type: `Foo<(), Bar = Type>`
9+
10+
error[E0191]: the value of the associated type `Bar` (from trait `Foo`) must be specified
11+
--> $DIR/assoc_type_bounds.rs:11:16
12+
|
13+
LL | type Bar
14+
| -------- `Bar` defined here
15+
...
16+
LL | fn bar(_: &dyn Foo<i32>) {}
17+
| ^^^^^^^^ help: specify the associated type: `Foo<i32, Bar = Type>`
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0191`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait Foo<T> {
2+
type Bar
3+
where
4+
Self: Foo<()>;
5+
}
6+
7+
trait Cake {}
8+
impl Cake for () {}
9+
10+
fn foo(_: &dyn Foo<()>) {} //~ ERROR: the value of the associated type `Bar` (from trait `Foo`) must be specified
11+
fn bar(_: &dyn Foo<i32>) {} //~ ERROR: the value of the associated type `Bar` (from trait `Foo`) must be specified
12+
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0191]: the value of the associated type `Bar` (from trait `Foo`) must be specified
2+
--> $DIR/assoc_type_bounds2.rs:10:16
3+
|
4+
LL | type Bar
5+
| -------- `Bar` defined here
6+
...
7+
LL | fn foo(_: &dyn Foo<()>) {}
8+
| ^^^^^^^ help: specify the associated type: `Foo<(), Bar = Type>`
9+
10+
error[E0191]: the value of the associated type `Bar` (from trait `Foo`) must be specified
11+
--> $DIR/assoc_type_bounds2.rs:11:16
12+
|
13+
LL | type Bar
14+
| -------- `Bar` defined here
15+
...
16+
LL | fn bar(_: &dyn Foo<i32>) {}
17+
| ^^^^^^^^ help: specify the associated type: `Foo<i32, Bar = Type>`
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0191`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Foo {
2+
type Bar
3+
where
4+
Self: Sized;
5+
}
6+
7+
fn foo(_: &dyn Foo) {} //~ ERROR: the value of the associated type `Bar` (from trait `Foo`) must be specified
8+
9+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0191]: the value of the associated type `Bar` (from trait `Foo`) must be specified
2+
--> $DIR/assoc_type_bounds_sized.rs:7:16
3+
|
4+
LL | type Bar
5+
| -------- `Bar` defined here
6+
...
7+
LL | fn foo(_: &dyn Foo) {}
8+
| ^^^ help: specify the associated type: `Foo<Bar = Type>`
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0191`.

0 commit comments

Comments
 (0)