Skip to content

Commit 318b372

Browse files
committed
Specialization already rejects defining opaque types
1 parent 3d1085c commit 318b372

File tree

3 files changed

+71
-0
lines changed

3 files changed

+71
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Test that specializing on opaque types is allowed
2+
3+
//@ check-pass
4+
5+
#![feature(min_specialization, type_alias_impl_trait)]
6+
7+
trait SpecTrait<U> {
8+
fn f();
9+
}
10+
11+
impl<U> SpecTrait<U> for () {
12+
default fn f() {}
13+
}
14+
15+
type Opaque = impl Tuple;
16+
17+
trait Tuple {}
18+
19+
impl Tuple for () {}
20+
21+
impl SpecTrait<Opaque> for () {
22+
fn f() {}
23+
}
24+
25+
impl SpecTrait<u32> for () {
26+
fn f() {}
27+
}
28+
29+
fn foo() -> Opaque {}
30+
31+
fn main() {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Test that specializing on opaque types is allowed
2+
3+
#![feature(min_specialization, type_alias_impl_trait)]
4+
5+
trait SpecTrait<U, V> {
6+
fn f();
7+
}
8+
9+
impl<U> SpecTrait<U, ()> for () {
10+
default fn f() {}
11+
}
12+
13+
type Opaque = impl Tuple;
14+
15+
trait Tuple {}
16+
17+
impl Tuple for () {}
18+
19+
// FIXME: this passes if we use `<(), ()>` here instead of `<(), Opaque>`,
20+
// even though there can't be more overlap from the opaque version
21+
impl SpecTrait<(), Opaque> for () {
22+
//~^ ERROR: conflicting implementations
23+
fn f() {}
24+
}
25+
26+
fn foo() -> Opaque {}
27+
28+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0119]: conflicting implementations of trait `SpecTrait<(), ()>` for type `()`
2+
--> $DIR/impl-on-opaque2.rs:21:1
3+
|
4+
LL | impl<U> SpecTrait<U, ()> for () {
5+
| ------------------------------- first implementation here
6+
...
7+
LL | impl SpecTrait<(), Opaque> for () {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `()`
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)