Skip to content

Commit dc29a79

Browse files
committed
Push clauses for auto traits on opaque types
1 parent 113ace7 commit dc29a79

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

chalk-solve/src/clauses.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ fn constituent_types<I: Interner>(db: &dyn RustIrDatabase<I>, ty: &TyKind<I>) ->
7575
TyKind::Alias(_) => panic!("this function should not be called for alias"),
7676
TyKind::Foreign(_) => panic!("constituent_types of foreign types are unknown!"),
7777
TyKind::Error => Vec::new(),
78-
TyKind::OpaqueType(_, _) => unimplemented!(),
79-
TyKind::AssociatedType(_, _) => unimplemented!(),
78+
TyKind::OpaqueType(_, _) => panic!("constituent_types of opaque types are unknown!"),
79+
TyKind::AssociatedType(_, _) => {
80+
panic!("constituent_types of associated types are unknown!")
81+
}
8082
}
8183
}
8284

@@ -176,12 +178,16 @@ pub fn push_auto_trait_impls<I: Interner>(
176178
Ok(())
177179
}
178180

179-
// Unimplemented
180-
TyKind::OpaqueType(_, _) => Ok(()),
181-
TyKind::AssociatedType(_, _) => Ok(()),
181+
TyKind::OpaqueType(opaque_ty_id, _) => {
182+
push_auto_trait_impls_opaque(builder, auto_trait_id, *opaque_ty_id);
183+
Ok(())
184+
}
182185

183186
// No auto traits
184-
TyKind::Placeholder(_) | TyKind::Dyn(_) | TyKind::Alias(_) => Ok(()),
187+
TyKind::AssociatedType(_, _)
188+
| TyKind::Placeholder(_)
189+
| TyKind::Dyn(_)
190+
| TyKind::Alias(_) => Ok(()),
185191

186192
// app_ty implements AutoTrait if all constituents of app_ty implement AutoTrait
187193
_ => {

tests/test/opaque_types.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,40 @@ fn opaque_auto_traits() {
205205
}
206206
}
207207
}
208+
209+
#[test]
210+
fn opaque_auto_traits_indirect() {
211+
test! {
212+
program {
213+
struct Bar { }
214+
struct Baz { }
215+
trait Trait { }
216+
217+
impl Trait for Bar { }
218+
impl Trait for Baz { }
219+
220+
#[auto]
221+
trait Send { }
222+
trait SendDerived where Self: Send { }
223+
224+
impl<T> SendDerived for T where T: Send { }
225+
226+
impl !Send for Baz { }
227+
228+
opaque type Opaque1: Trait = Bar;
229+
opaque type Opaque2: Trait = Baz;
230+
}
231+
232+
goal {
233+
Opaque1: SendDerived
234+
} yields {
235+
"Unique"
236+
}
237+
238+
goal {
239+
Opaque2: SendDerived
240+
} yields {
241+
"No possible solution"
242+
}
243+
}
244+
}

0 commit comments

Comments
 (0)