Skip to content

Commit ce75a23

Browse files
author
Alexander Regueiro
committed
Reinstated shallow disallowing of maybe bounds in trait objects.
1 parent a0a6190 commit ce75a23

9 files changed

+80
-6
lines changed

Diff for: src/librustc_passes/ast_validation.rs

+1
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
504504
any_lifetime_bounds = true;
505505
}
506506
}
507+
self.no_questions_in_bounds(bounds, "trait object types", false);
507508
}
508509
TyKind::ImplTrait(_, ref bounds) => {
509510
if self.is_impl_trait_banned {

Diff for: src/test/ui/maybe-bounds.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
trait Tr: ?Sized {} //~ ERROR `?Trait` is not permitted in supertraits
1+
trait Tr: ?Sized {}
2+
//~^ ERROR `?Trait` is not permitted in supertraits
23

34
type A1 = dyn Tr + (?Sized);
5+
//~^ ERROR `?Trait` is not permitted in trait object types
46
type A2 = dyn for<'a> Tr + (?Sized);
7+
//~^ ERROR `?Trait` is not permitted in trait object types
58

69
fn main() {}

Diff for: src/test/ui/maybe-bounds.stderr

+13-1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,17 @@ LL | trait Tr: ?Sized {}
66
|
77
= note: traits are `?Sized` by default
88

9-
error: aborting due to previous error
9+
error: `?Trait` is not permitted in trait object types
10+
--> $DIR/maybe-bounds.rs:4:20
11+
|
12+
LL | type A1 = dyn Tr + (?Sized);
13+
| ^^^^^^^^
14+
15+
error: `?Trait` is not permitted in trait object types
16+
--> $DIR/maybe-bounds.rs:6:28
17+
|
18+
LL | type A2 = dyn for<'a> Tr + (?Sized);
19+
| ^^^^^^^^
20+
21+
error: aborting due to 3 previous errors
1022

Diff for: src/test/ui/parser/trait-object-trait-parens.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ fn f<T: (Copy) + (?Sized) + (for<'a> Trait<'a>)>() {}
44

55
fn main() {
66
let _: Box<(Copy) + (?Sized) + (for<'a> Trait<'a>)>;
7+
//~^ ERROR `?Trait` is not permitted in trait object types
78
let _: Box<(?Sized) + (for<'a> Trait<'a>) + (Copy)>;
89
let _: Box<(for<'a> Trait<'a>) + (Copy) + (?Sized)>;
910
//~^ ERROR use of undeclared lifetime name `'a`
11+
//~| ERROR `?Trait` is not permitted in trait object types
1012
}

Diff for: src/test/ui/parser/trait-object-trait-parens.stderr

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
1+
error: `?Trait` is not permitted in trait object types
2+
--> $DIR/trait-object-trait-parens.rs:6:25
3+
|
4+
LL | let _: Box<(Copy) + (?Sized) + (for<'a> Trait<'a>)>;
5+
| ^^^^^^^^
6+
7+
error: `?Trait` is not permitted in trait object types
8+
--> $DIR/trait-object-trait-parens.rs:9:47
9+
|
10+
LL | let _: Box<(for<'a> Trait<'a>) + (Copy) + (?Sized)>;
11+
| ^^^^^^^^
12+
113
error[E0261]: use of undeclared lifetime name `'a`
2-
--> $DIR/trait-object-trait-parens.rs:8:31
14+
--> $DIR/trait-object-trait-parens.rs:9:31
315
|
416
LL | let _: Box<(for<'a> Trait<'a>) + (Copy) + (?Sized)>;
517
| ^^ undeclared lifetime
618

7-
error: aborting due to previous error
19+
error: aborting due to 3 previous errors
820

921
For more information about this error, try `rustc --explain E0261`.

Diff for: src/test/ui/traits/wf-trait-object-maybe-bound.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1-
// compile-pass
1+
// compile-fail
22

33
// Test that `dyn ... + ?Sized + ...` is okay (though `?Sized` has no effect in trait objects).
44

55
trait Foo {}
66

77
type _0 = dyn ?Sized + Foo;
8+
//~^ ERROR `?Trait` is not permitted in trait object types
89

910
type _1 = dyn Foo + ?Sized;
11+
//~^ ERROR `?Trait` is not permitted in trait object types
1012

1113
type _2 = dyn Foo + ?Sized + ?Sized;
14+
//~^ ERROR `?Trait` is not permitted in trait object types
15+
//~| ERROR `?Trait` is not permitted in trait object types
1216

1317
type _3 = dyn ?Sized + Foo;
18+
//~^ ERROR `?Trait` is not permitted in trait object types
1419

1520
fn main() {}
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
error: `?Trait` is not permitted in trait object types
2+
--> $DIR/wf-trait-object-maybe-bound.rs:7:15
3+
|
4+
LL | type _0 = dyn ?Sized + Foo;
5+
| ^^^^^^
6+
7+
error: `?Trait` is not permitted in trait object types
8+
--> $DIR/wf-trait-object-maybe-bound.rs:10:21
9+
|
10+
LL | type _1 = dyn Foo + ?Sized;
11+
| ^^^^^^
12+
13+
error: `?Trait` is not permitted in trait object types
14+
--> $DIR/wf-trait-object-maybe-bound.rs:13:21
15+
|
16+
LL | type _2 = dyn Foo + ?Sized + ?Sized;
17+
| ^^^^^^
18+
19+
error: `?Trait` is not permitted in trait object types
20+
--> $DIR/wf-trait-object-maybe-bound.rs:13:30
21+
|
22+
LL | type _2 = dyn Foo + ?Sized + ?Sized;
23+
| ^^^^^^
24+
25+
error: `?Trait` is not permitted in trait object types
26+
--> $DIR/wf-trait-object-maybe-bound.rs:17:15
27+
|
28+
LL | type _3 = dyn ?Sized + Foo;
29+
| ^^^^^^
30+
31+
error: aborting due to 5 previous errors
32+

Diff for: src/test/ui/traits/wf-trait-object-only-maybe-bound.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22

33
type _0 = dyn ?Sized;
44
//~^ ERROR at least one non-builtin trait is required for an object type [E0224]
5+
//~| ERROR ?Trait` is not permitted in trait object types
56

67
fn main() {}
+7-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1+
error: `?Trait` is not permitted in trait object types
2+
--> $DIR/wf-trait-object-only-maybe-bound.rs:3:15
3+
|
4+
LL | type _0 = dyn ?Sized;
5+
| ^^^^^^
6+
17
error[E0224]: at least one non-builtin trait is required for an object type
28
--> $DIR/wf-trait-object-only-maybe-bound.rs:3:11
39
|
410
LL | type _0 = dyn ?Sized;
511
| ^^^^^^^^^^
612

7-
error: aborting due to previous error
13+
error: aborting due to 2 previous errors
814

0 commit comments

Comments
 (0)