diff options
| author | Jonas Schievink <jonasschievink@gmail.com> | 2019-09-19 00:54:47 +0200 |
|---|---|---|
| committer | Jonas Schievink <jonasschievink@gmail.com> | 2019-10-05 15:33:26 +0200 |
| commit | 33d23cdf042af4a2b8acd32098114ad7e8ac8f5e (patch) | |
| tree | 0edd18e01bc2cff8c761eb5d19c2388eb609d594 | |
| parent | 98f02b23628d3b46e25f83634d5db2ffbe8ee725 (diff) | |
| download | rust-33d23cdf042af4a2b8acd32098114ad7e8ac8f5e.tar.gz rust-33d23cdf042af4a2b8acd32098114ad7e8ac8f5e.zip | |
Extend test and fix nits
| -rw-r--r-- | src/test/ui/specialization/specialization-default-methods-fail.rs | 20 | ||||
| -rw-r--r-- | src/test/ui/specialization/specialization-default-methods-fail.stderr | 60 |
2 files changed, 72 insertions, 8 deletions
diff --git a/src/test/ui/specialization/specialization-default-methods-fail.rs b/src/test/ui/specialization/specialization-default-methods-fail.rs index c5098214188..403f718d7dd 100644 --- a/src/test/ui/specialization/specialization-default-methods-fail.rs +++ b/src/test/ui/specialization/specialization-default-methods-fail.rs @@ -1,11 +1,11 @@ -// compile-fail - -#![feature(specialization)] +#![feature(specialization, associated_type_defaults)] // Test that attempting to override a non-default method or one not in the -// parent impl causes an error +// parent impl causes an error. trait Foo { + type Ty = (); + const CONST: u8 = 123; fn foo(&self) -> bool { true } } @@ -16,6 +16,8 @@ trait Foo { // Box<i32> Box<i64> Vec<()> Vec<bool> impl<T> Foo for Box<T> { + type Ty = bool; + const CONST: u8 = 0; fn foo(&self) -> bool { false } } @@ -24,18 +26,26 @@ impl Foo for Box<i32> {} // Can't override a non-`default` fn impl Foo for Box<i64> { + type Ty = Vec<()>; +//~^ error: `Ty` specializes an item from a parent `impl`, but that item is not marked `default` + const CONST: u8 = 42; +//~^ error: `CONST` specializes an item from a parent `impl`, but that item is not marked `default` fn foo(&self) -> bool { true } //~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default` } -// Doesn't mention the method = provided body is used and the method is final +// Doesn't mention the item = provided body/value is used and the method is final. impl<T> Foo for Vec<T> {} // Allowed impl Foo for Vec<()> {} impl Foo for Vec<bool> { + type Ty = Vec<()>; +//~^ error: `Ty` specializes an item from a parent `impl`, but that item is not marked `default` + const CONST: u8 = 42; +//~^ error: `CONST` specializes an item from a parent `impl`, but that item is not marked `default` fn foo(&self) -> bool { true } //~^ error: `foo` specializes an item from a parent `impl`, but that item is not marked `default` } diff --git a/src/test/ui/specialization/specialization-default-methods-fail.stderr b/src/test/ui/specialization/specialization-default-methods-fail.stderr index f962ccca83d..f215191a8ce 100644 --- a/src/test/ui/specialization/specialization-default-methods-fail.stderr +++ b/src/test/ui/specialization/specialization-default-methods-fail.stderr @@ -1,7 +1,39 @@ +error[E0520]: `Ty` specializes an item from a parent `impl`, but that item is not marked `default` + --> $DIR/specialization-default-methods-fail.rs:29:5 + | +LL | / impl<T> Foo for Box<T> { +LL | | type Ty = bool; +LL | | const CONST: u8 = 0; +LL | | fn foo(&self) -> bool { false } +LL | | } + | |_- parent `impl` is here +... +LL | type Ty = Vec<()>; + | ^^^^^^^^^^^^^^^^^^ cannot specialize default item `Ty` + | + = note: to specialize, `Ty` in the parent `impl` must be marked `default` + +error[E0520]: `CONST` specializes an item from a parent `impl`, but that item is not marked `default` + --> $DIR/specialization-default-methods-fail.rs:31:5 + | +LL | / impl<T> Foo for Box<T> { +LL | | type Ty = bool; +LL | | const CONST: u8 = 0; +LL | | fn foo(&self) -> bool { false } +LL | | } + | |_- parent `impl` is here +... +LL | const CONST: u8 = 42; + | ^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `CONST` + | + = note: to specialize, `CONST` in the parent `impl` must be marked `default` + error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default` - --> $DIR/specialization-default-methods-fail.rs:27:5 + --> $DIR/specialization-default-methods-fail.rs:33:5 | LL | / impl<T> Foo for Box<T> { +LL | | type Ty = bool; +LL | | const CONST: u8 = 0; LL | | fn foo(&self) -> bool { false } LL | | } | |_- parent `impl` is here @@ -11,8 +43,30 @@ LL | fn foo(&self) -> bool { true } | = note: to specialize, `foo` in the parent `impl` must be marked `default` +error[E0520]: `Ty` specializes an item from a parent `impl`, but that item is not marked `default` + --> $DIR/specialization-default-methods-fail.rs:45:5 + | +LL | impl<T> Foo for Vec<T> {} + | ------------------------- parent `impl` is here +... +LL | type Ty = Vec<()>; + | ^^^^^^^^^^^^^^^^^^ cannot specialize default item `Ty` + | + = note: to specialize, `Ty` in the parent `impl` must be marked `default` + +error[E0520]: `CONST` specializes an item from a parent `impl`, but that item is not marked `default` + --> $DIR/specialization-default-methods-fail.rs:47:5 + | +LL | impl<T> Foo for Vec<T> {} + | ------------------------- parent `impl` is here +... +LL | const CONST: u8 = 42; + | ^^^^^^^^^^^^^^^^^^^^^ cannot specialize default item `CONST` + | + = note: to specialize, `CONST` in the parent `impl` must be marked `default` + error[E0520]: `foo` specializes an item from a parent `impl`, but that item is not marked `default` - --> $DIR/specialization-default-methods-fail.rs:39:5 + --> $DIR/specialization-default-methods-fail.rs:49:5 | LL | impl<T> Foo for Vec<T> {} | ------------------------- parent `impl` is here @@ -22,6 +76,6 @@ LL | fn foo(&self) -> bool { true } | = note: to specialize, `foo` in the parent `impl` must be marked `default` -error: aborting due to 2 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0520`. |
