Rollup merge of #112929 - oli-obk:what_if_an_impl_item_just_doesnt_wanna_be_impld, r=compiler-errors
Test that we require implementing trait items whose bounds don't hold in the current impl I initially tried to make most of these pass, but that's a big can of worms, so I'm just adding them as tests, considering we have no tests for these things.
This commit is contained in:
commit
1963688f93
1
tests/ui/traits/auxiliary/trivial3.rs
Normal file
1
tests/ui/traits/auxiliary/trivial3.rs
Normal file
@ -0,0 +1 @@
|
||||
pub trait Trait {}
|
3
tests/ui/traits/auxiliary/trivial4.rs
Normal file
3
tests/ui/traits/auxiliary/trivial4.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub trait Trait {}
|
||||
|
||||
impl Trait for () {}
|
18
tests/ui/traits/trivial_impl.rs
Normal file
18
tests/ui/traits/trivial_impl.rs
Normal file
@ -0,0 +1,18 @@
|
||||
//! This test checks that we do need to implement
|
||||
//! all members, even if their where bounds only hold
|
||||
//! due to other impls.
|
||||
|
||||
trait Foo<T> {
|
||||
fn foo()
|
||||
where
|
||||
Self: Foo<()>;
|
||||
}
|
||||
|
||||
impl Foo<()> for () {
|
||||
fn foo() {}
|
||||
}
|
||||
|
||||
impl Foo<u32> for () {}
|
||||
//~^ ERROR: not all trait items implemented, missing: `foo`
|
||||
|
||||
fn main() {}
|
14
tests/ui/traits/trivial_impl.stderr
Normal file
14
tests/ui/traits/trivial_impl.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error[E0046]: not all trait items implemented, missing: `foo`
|
||||
--> $DIR/trivial_impl.rs:15:1
|
||||
|
|
||||
LL | / fn foo()
|
||||
LL | | where
|
||||
LL | | Self: Foo<()>;
|
||||
| |______________________- `foo` from trait
|
||||
...
|
||||
LL | impl Foo<u32> for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0046`.
|
13
tests/ui/traits/trivial_impl2.rs
Normal file
13
tests/ui/traits/trivial_impl2.rs
Normal file
@ -0,0 +1,13 @@
|
||||
//! This test checks that we currently need to implement
|
||||
//! members, even if their where bounds don't hold for the impl type.
|
||||
|
||||
trait Foo<T> {
|
||||
fn foo()
|
||||
where
|
||||
Self: Foo<()>;
|
||||
}
|
||||
|
||||
impl Foo<u32> for () {}
|
||||
//~^ ERROR: not all trait items implemented, missing: `foo`
|
||||
|
||||
fn main() {}
|
14
tests/ui/traits/trivial_impl2.stderr
Normal file
14
tests/ui/traits/trivial_impl2.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error[E0046]: not all trait items implemented, missing: `foo`
|
||||
--> $DIR/trivial_impl2.rs:10:1
|
||||
|
|
||||
LL | / fn foo()
|
||||
LL | | where
|
||||
LL | | Self: Foo<()>;
|
||||
| |______________________- `foo` from trait
|
||||
...
|
||||
LL | impl Foo<u32> for () {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0046`.
|
19
tests/ui/traits/trivial_impl3.rs
Normal file
19
tests/ui/traits/trivial_impl3.rs
Normal file
@ -0,0 +1,19 @@
|
||||
//! Check that we don't break orphan rules.
|
||||
//! The dependency may add an impl for `u8` later,
|
||||
//! which would break this crate. We want to avoid adding
|
||||
//! more ways in which adding an impl can be a breaking change.
|
||||
|
||||
// aux-build:trivial3.rs
|
||||
|
||||
extern crate trivial3;
|
||||
|
||||
pub trait Foo {
|
||||
fn foo()
|
||||
where
|
||||
Self: trivial3::Trait;
|
||||
}
|
||||
|
||||
impl Foo for u8 {}
|
||||
//~^ ERROR not all trait items implemented, missing: `foo`
|
||||
|
||||
fn main() {}
|
14
tests/ui/traits/trivial_impl3.stderr
Normal file
14
tests/ui/traits/trivial_impl3.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error[E0046]: not all trait items implemented, missing: `foo`
|
||||
--> $DIR/trivial_impl3.rs:16:1
|
||||
|
|
||||
LL | / fn foo()
|
||||
LL | | where
|
||||
LL | | Self: trivial3::Trait;
|
||||
| |______________________________- `foo` from trait
|
||||
...
|
||||
LL | impl Foo for u8 {}
|
||||
| ^^^^^^^^^^^^^^^ missing `foo` in implementation
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0046`.
|
21
tests/ui/traits/trivial_impl4.rs
Normal file
21
tests/ui/traits/trivial_impl4.rs
Normal file
@ -0,0 +1,21 @@
|
||||
//! Check that we don't break orphan rules.
|
||||
//! The dependency may add an impl for `u8` later,
|
||||
//! which would break this crate. We want to avoid adding
|
||||
//! more ways in which adding an impl can be a breaking change.
|
||||
//! This test differs from `trivial_impl3` because there actually
|
||||
//! exists any impl for `Trait`, which has an effect on coherence.
|
||||
|
||||
// aux-build:trivial4.rs
|
||||
|
||||
extern crate trivial4;
|
||||
|
||||
pub trait Foo {
|
||||
fn foo()
|
||||
where
|
||||
Self: trivial4::Trait;
|
||||
}
|
||||
|
||||
impl Foo for u8 {}
|
||||
//~^ ERROR not all trait items implemented, missing: `foo`
|
||||
|
||||
fn main() {}
|
14
tests/ui/traits/trivial_impl4.stderr
Normal file
14
tests/ui/traits/trivial_impl4.stderr
Normal file
@ -0,0 +1,14 @@
|
||||
error[E0046]: not all trait items implemented, missing: `foo`
|
||||
--> $DIR/trivial_impl4.rs:18:1
|
||||
|
|
||||
LL | / fn foo()
|
||||
LL | | where
|
||||
LL | | Self: trivial4::Trait;
|
||||
| |______________________________- `foo` from trait
|
||||
...
|
||||
LL | impl Foo for u8 {}
|
||||
| ^^^^^^^^^^^^^^^ missing `foo` in implementation
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0046`.
|
26
tests/ui/traits/trivial_impl_sized.rs
Normal file
26
tests/ui/traits/trivial_impl_sized.rs
Normal file
@ -0,0 +1,26 @@
|
||||
//! This test checks that we currently need to implement
|
||||
//! members, even if their where bounds don't hold for the impl type.
|
||||
|
||||
trait Foo {
|
||||
fn foo()
|
||||
where
|
||||
Self: Sized;
|
||||
}
|
||||
|
||||
impl Foo for () {
|
||||
fn foo() {}
|
||||
}
|
||||
|
||||
// Must not be allowed
|
||||
impl Foo for i32 {}
|
||||
//~^ ERROR: not all trait items implemented, missing: `foo`
|
||||
|
||||
// Should be allowed
|
||||
impl Foo for dyn std::fmt::Debug {}
|
||||
//~^ ERROR: not all trait items implemented, missing: `foo`
|
||||
|
||||
impl Foo for dyn std::fmt::Display {
|
||||
fn foo() {}
|
||||
}
|
||||
|
||||
fn main() {}
|
25
tests/ui/traits/trivial_impl_sized.stderr
Normal file
25
tests/ui/traits/trivial_impl_sized.stderr
Normal file
@ -0,0 +1,25 @@
|
||||
error[E0046]: not all trait items implemented, missing: `foo`
|
||||
--> $DIR/trivial_impl_sized.rs:15:1
|
||||
|
|
||||
LL | / fn foo()
|
||||
LL | | where
|
||||
LL | | Self: Sized;
|
||||
| |____________________- `foo` from trait
|
||||
...
|
||||
LL | impl Foo for i32 {}
|
||||
| ^^^^^^^^^^^^^^^^ missing `foo` in implementation
|
||||
|
||||
error[E0046]: not all trait items implemented, missing: `foo`
|
||||
--> $DIR/trivial_impl_sized.rs:19:1
|
||||
|
|
||||
LL | / fn foo()
|
||||
LL | | where
|
||||
LL | | Self: Sized;
|
||||
| |____________________- `foo` from trait
|
||||
...
|
||||
LL | impl Foo for dyn std::fmt::Debug {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing `foo` in implementation
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0046`.
|
Loading…
Reference in New Issue
Block a user