Skip to content

Commit 18cf44b

Browse files
committed
Do not ICE when closure is involved in TAIT
Fix rust-lang#83613.
1 parent b8dda53 commit 18cf44b

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

compiler/rustc_trait_selection/src/traits/coherence.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,11 @@ fn ty_is_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> bool {
586586
false
587587
}
588588

589+
ty::Closure(..) => {
590+
// Similar to the `Opaque` case (#83613).
591+
false
592+
}
593+
589594
ty::Dynamic(ref tt, ..) => {
590595
if let Some(principal) = tt.principal() {
591596
def_id_is_local(principal.def_id(), in_crate)
@@ -596,7 +601,7 @@ fn ty_is_local_constructor(ty: Ty<'_>, in_crate: InCrate) -> bool {
596601

597602
ty::Error(_) => true,
598603

599-
ty::Closure(..) | ty::Generator(..) | ty::GeneratorWitness(..) => {
604+
ty::Generator(..) | ty::GeneratorWitness(..) => {
600605
bug!("ty_is_local invoked on unexpected type: {:?}", ty)
601606
}
602607
}
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![feature(min_type_alias_impl_trait)]
2+
trait OpaqueTrait {}
3+
impl<T> OpaqueTrait for T {}
4+
type OpaqueType = impl OpaqueTrait;
5+
fn mk_opaque() -> OpaqueType {
6+
|| 0
7+
}
8+
trait AnotherTrait {}
9+
impl<T: Send> AnotherTrait for T {}
10+
impl AnotherTrait for OpaqueType {}
11+
//~^ ERROR conflicting implementations of trait `AnotherTrait` for type `impl OpaqueTrait`
12+
//~| ERROR cannot implement trait on type alias impl trait
13+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0119]: conflicting implementations of trait `AnotherTrait` for type `impl OpaqueTrait`
2+
--> $DIR/issue-83613.rs:10:1
3+
|
4+
LL | impl<T: Send> AnotherTrait for T {}
5+
| -------------------------------- first implementation here
6+
LL | impl AnotherTrait for OpaqueType {}
7+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `impl OpaqueTrait`
8+
9+
error: cannot implement trait on type alias impl trait
10+
--> $DIR/issue-83613.rs:10:1
11+
|
12+
LL | impl AnotherTrait for OpaqueType {}
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14+
|
15+
note: type alias impl trait defined here
16+
--> $DIR/issue-83613.rs:4:19
17+
|
18+
LL | type OpaqueType = impl OpaqueTrait;
19+
| ^^^^^^^^^^^^^^^^
20+
21+
error: aborting due to 2 previous errors
22+
23+
For more information about this error, try `rustc --explain E0119`.

0 commit comments

Comments
 (0)