Skip to content

Commit 18295ee

Browse files
committed
integrate orphan check
1 parent c4a1079 commit 18295ee

File tree

2 files changed

+38
-4
lines changed

2 files changed

+38
-4
lines changed

crates/formality-check/src/coherence.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use anyhow::bail;
2+
use fn_error_context::context;
23
use formality_prove::Env;
34
use formality_rust::grammar::{Crate, TraitImpl};
45
use formality_types::{
@@ -38,8 +39,18 @@ impl Check<'_> {
3839
Ok(())
3940
}
4041

41-
fn orphan_check(&self, _impl_a: &TraitImpl) -> Fallible<()> {
42-
Ok(())
42+
#[context("orphan_check({impl_a:?})")]
43+
fn orphan_check(&self, impl_a: &TraitImpl) -> Fallible<()> {
44+
let mut env = Env::default();
45+
46+
let a = env.instantiate_universally(&impl_a.binder);
47+
let trait_ref = a.trait_ref();
48+
49+
self.prove_goal(
50+
&env.with_coherence_mode(true),
51+
&a.where_clauses,
52+
trait_ref.is_local(),
53+
)
4354
}
4455

4556
#[tracing::instrument(level = "Debug", skip(self))]

tests/coherence.rs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn test_u32_not_u32_impls() {
108108
source: "failed to disprove {! Foo((rigid (scalar u32)))} given {}, got {Constraints { env: Env { variables: [], coherence_mode: false }, known_true: true, substitution: {} }}",
109109
},
110110
)
111-
"#]] // FIXME
111+
"#]]
112112
.assert_debug_eq(&test_program_ok(
113113
"[
114114
crate core {
@@ -130,7 +130,7 @@ fn test_T_where_Foo_not_u32_impls() {
130130
source: "failed to disprove {! Foo(!ty_1)} given {Foo(!ty_1)}, got {Constraints { env: Env { variables: [?ty_1], coherence_mode: false }, known_true: true, substitution: {?ty_1 => (rigid (scalar u32))} }}",
131131
},
132132
)
133-
"#]] // FIXME
133+
"#]]
134134
.assert_debug_eq(&test_program_ok(
135135
"[
136136
crate core {
@@ -164,3 +164,26 @@ fn test_non_local() {
164164
]",
165165
));
166166
}
167+
168+
#[test]
169+
fn test_orphan() {
170+
expect_test::expect![[r#"
171+
Err(
172+
Error {
173+
context: "orphan_check(impl <> CoreTrait < > for (rigid (adt CoreStruct)) where [] { })",
174+
source: "failed to prove {@ IsLocal(CoreTrait((rigid (adt CoreStruct))))} given {}, got {}",
175+
},
176+
)
177+
"#]]
178+
.assert_debug_eq(&test_program_ok(
179+
"[
180+
crate core {
181+
trait CoreTrait<> where [] {}
182+
struct CoreStruct<> where [] {}
183+
},
184+
crate foo {
185+
impl<> CoreTrait<> for CoreStruct<> where [] {}
186+
}
187+
]",
188+
));
189+
}

0 commit comments

Comments
 (0)