Skip to content

Commit ce3cff4

Browse files
committed
Add more tests
1 parent 62fbbac commit ce3cff4

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed

tests/ui/object-safety/assoc_type_bounds_sized.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! This test checks that associated types only need to be
2+
//! mentioned in trait objects, if they don't require `Self: Sized`.
3+
14
// check-pass
25

36
trait Foo {
@@ -8,4 +11,14 @@ trait Foo {
811

912
fn foo(_: &dyn Foo) {}
1013

14+
trait Other: Sized {}
15+
16+
trait Boo {
17+
type Assoc
18+
where
19+
Self: Other;
20+
}
21+
22+
fn boo(_: &dyn Boo) {}
23+
1124
fn main() {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! This test checks that even if some associated types have
2+
//! `where Self: Sized` bounds, those without still need to be
3+
//! mentioned in trait objects.
4+
5+
trait Foo {
6+
type Bar
7+
where
8+
Self: Sized;
9+
type Bop;
10+
}
11+
12+
fn foo(_: &dyn Foo) {}
13+
//~^ ERROR the value of the associated type `Bop` (from trait `Foo`) must be specified
14+
15+
trait Bar {
16+
type Bop;
17+
type Bar
18+
where
19+
Self: Sized;
20+
}
21+
22+
fn bar(_: &dyn Bar) {}
23+
//~^ ERROR the value of the associated type `Bop` (from trait `Bar`) must be specified
24+
25+
fn main() {}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0191]: the value of the associated type `Bop` (from trait `Foo`) must be specified
2+
--> $DIR/assoc_type_bounds_sized_others.rs:12:16
3+
|
4+
LL | type Bop;
5+
| -------- `Bop` defined here
6+
...
7+
LL | fn foo(_: &dyn Foo) {}
8+
| ^^^ help: specify the associated type: `Foo<Bop = Type>`
9+
10+
error[E0191]: the value of the associated type `Bop` (from trait `Bar`) must be specified
11+
--> $DIR/assoc_type_bounds_sized_others.rs:22:16
12+
|
13+
LL | type Bop;
14+
| -------- `Bop` defined here
15+
...
16+
LL | fn bar(_: &dyn Bar) {}
17+
| ^^^ help: specify the associated type: `Bar<Bop = Type>`
18+
19+
error: aborting due to 2 previous errors
20+
21+
For more information about this error, try `rustc --explain E0191`.

0 commit comments

Comments
 (0)