Specialization already rejects defining opaque types

This commit is contained in:
Oli Scherer 2024-02-21 11:30:57 +00:00
parent 150448d2e0
commit b8bd981545
3 changed files with 71 additions and 0 deletions

View File

@ -0,0 +1,31 @@
// Test that specializing on opaque types is allowed
//@ check-pass
#![feature(min_specialization, type_alias_impl_trait)]
trait SpecTrait<U> {
fn f();
}
impl<U> SpecTrait<U> for () {
default fn f() {}
}
type Opaque = impl Tuple;
trait Tuple {}
impl Tuple for () {}
impl SpecTrait<Opaque> for () {
fn f() {}
}
impl SpecTrait<u32> for () {
fn f() {}
}
fn foo() -> Opaque {}
fn main() {}

View File

@ -0,0 +1,28 @@
// Test that specializing on opaque types is allowed
#![feature(min_specialization, type_alias_impl_trait)]
trait SpecTrait<U, V> {
fn f();
}
impl<U> SpecTrait<U, ()> for () {
default fn f() {}
}
type Opaque = impl Tuple;
trait Tuple {}
impl Tuple for () {}
// FIXME: this passes if we use `<(), ()>` here instead of `<(), Opaque>`,
// even though there can't be more overlap from the opaque version
impl SpecTrait<(), Opaque> for () {
//~^ ERROR: conflicting implementations
fn f() {}
}
fn foo() -> Opaque {}
fn main() {}

View File

@ -0,0 +1,12 @@
error[E0119]: conflicting implementations of trait `SpecTrait<(), ()>` for type `()`
--> $DIR/impl-on-opaque2.rs:21:1
|
LL | impl<U> SpecTrait<U, ()> for () {
| ------------------------------- first implementation here
...
LL | impl SpecTrait<(), Opaque> for () {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0119`.