mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-25 21:34:18 +00:00
Reinstated shallow disallowing of maybe bounds in trait objects.
This commit is contained in:
parent
a0a61904f4
commit
ce75a23c0d
@ -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 {
|
||||
|
@ -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() {}
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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`.
|
||||
|
@ -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
src/test/ui/traits/wf-trait-object-maybe-bound.stderr
Normal file
32
src/test/ui/traits/wf-trait-object-maybe-bound.stderr
Normal file
@ -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
|
||||
|
@ -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() {}
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user