Skip to content

Commit

Permalink
Reinstated shallow disallowing of maybe bounds in trait objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Regueiro committed May 20, 2019
1 parent a0a6190 commit ce75a23
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/librustc_passes/ast_validation.rs
Expand Up @@ -504,6 +504,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
any_lifetime_bounds = true;
}
}
self.no_questions_in_bounds(bounds, "trait object types", false);
}
TyKind::ImplTrait(_, ref bounds) => {
if self.is_impl_trait_banned {
Expand Down
5 changes: 4 additions & 1 deletion src/test/ui/maybe-bounds.rs
@@ -1,6 +1,9 @@
trait Tr: ?Sized {} //~ ERROR `?Trait` is not permitted in supertraits
trait Tr: ?Sized {}
//~^ ERROR `?Trait` is not permitted in supertraits

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

fn main() {}
14 changes: 13 additions & 1 deletion src/test/ui/maybe-bounds.stderr
Expand Up @@ -6,5 +6,17 @@ LL | trait Tr: ?Sized {}
|
= note: traits are `?Sized` by default

error: aborting due to previous error
error: `?Trait` is not permitted in trait object types
--> $DIR/maybe-bounds.rs:4:20
|
LL | type A1 = dyn Tr + (?Sized);
| ^^^^^^^^

error: `?Trait` is not permitted in trait object types
--> $DIR/maybe-bounds.rs:6:28
|
LL | type A2 = dyn for<'a> Tr + (?Sized);
| ^^^^^^^^

error: aborting due to 3 previous errors

2 changes: 2 additions & 0 deletions src/test/ui/parser/trait-object-trait-parens.rs
Expand Up @@ -4,7 +4,9 @@ fn f<T: (Copy) + (?Sized) + (for<'a> Trait<'a>)>() {}

fn main() {
let _: Box<(Copy) + (?Sized) + (for<'a> Trait<'a>)>;
//~^ ERROR `?Trait` is not permitted in trait object types
let _: Box<(?Sized) + (for<'a> Trait<'a>) + (Copy)>;
let _: Box<(for<'a> Trait<'a>) + (Copy) + (?Sized)>;
//~^ ERROR use of undeclared lifetime name `'a`
//~| ERROR `?Trait` is not permitted in trait object types
}
16 changes: 14 additions & 2 deletions src/test/ui/parser/trait-object-trait-parens.stderr
@@ -1,9 +1,21 @@
error: `?Trait` is not permitted in trait object types
--> $DIR/trait-object-trait-parens.rs:6:25
|
LL | let _: Box<(Copy) + (?Sized) + (for<'a> Trait<'a>)>;
| ^^^^^^^^

error: `?Trait` is not permitted in trait object types
--> $DIR/trait-object-trait-parens.rs:9:47
|
LL | let _: Box<(for<'a> Trait<'a>) + (Copy) + (?Sized)>;
| ^^^^^^^^

error[E0261]: use of undeclared lifetime name `'a`
--> $DIR/trait-object-trait-parens.rs:8:31
--> $DIR/trait-object-trait-parens.rs:9:31
|
LL | let _: Box<(for<'a> Trait<'a>) + (Copy) + (?Sized)>;
| ^^ undeclared lifetime

error: aborting due to previous error
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0261`.
7 changes: 6 additions & 1 deletion src/test/ui/traits/wf-trait-object-maybe-bound.rs
@@ -1,15 +1,20 @@
// compile-pass
// compile-fail

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

trait Foo {}

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

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

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

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

fn main() {}
32 changes: 32 additions & 0 deletions src/test/ui/traits/wf-trait-object-maybe-bound.stderr
@@ -0,0 +1,32 @@
error: `?Trait` is not permitted in trait object types
--> $DIR/wf-trait-object-maybe-bound.rs:7:15
|
LL | type _0 = dyn ?Sized + Foo;
| ^^^^^^

error: `?Trait` is not permitted in trait object types
--> $DIR/wf-trait-object-maybe-bound.rs:10:21
|
LL | type _1 = dyn Foo + ?Sized;
| ^^^^^^

error: `?Trait` is not permitted in trait object types
--> $DIR/wf-trait-object-maybe-bound.rs:13:21
|
LL | type _2 = dyn Foo + ?Sized + ?Sized;
| ^^^^^^

error: `?Trait` is not permitted in trait object types
--> $DIR/wf-trait-object-maybe-bound.rs:13:30
|
LL | type _2 = dyn Foo + ?Sized + ?Sized;
| ^^^^^^

error: `?Trait` is not permitted in trait object types
--> $DIR/wf-trait-object-maybe-bound.rs:17:15
|
LL | type _3 = dyn ?Sized + Foo;
| ^^^^^^

error: aborting due to 5 previous errors

1 change: 1 addition & 0 deletions src/test/ui/traits/wf-trait-object-only-maybe-bound.rs
Expand Up @@ -2,5 +2,6 @@

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

fn main() {}
8 changes: 7 additions & 1 deletion src/test/ui/traits/wf-trait-object-only-maybe-bound.stderr
@@ -1,8 +1,14 @@
error: `?Trait` is not permitted in trait object types
--> $DIR/wf-trait-object-only-maybe-bound.rs:3:15
|
LL | type _0 = dyn ?Sized;
| ^^^^^^

error[E0224]: at least one non-builtin trait is required for an object type
--> $DIR/wf-trait-object-only-maybe-bound.rs:3:11
|
LL | type _0 = dyn ?Sized;
| ^^^^^^^^^^

error: aborting due to previous error
error: aborting due to 2 previous errors

0 comments on commit ce75a23

Please sign in to comment.