]>
git.proxmox.com Git - rustc.git/blob - vendor/chalk-solve-0.14.0/src/coherence/orphan.rs
1 use crate::coherence
::CoherenceError
;
2 use crate::ext
::GoalExt
;
3 use crate::solve
::SolverChoice
;
4 use crate::RustIrDatabase
;
6 use chalk_ir
::interner
::Interner
;
8 use tracing
::{debug, instrument}
;
10 // Test if a local impl violates the orphan rules.
12 // For `impl<T> Trait for MyType<T>` we generate:
14 // forall<T> { LocalImplAllowed(MyType<T>: Trait) }
16 // This must be provable in order to pass the orphan check.
17 #[instrument(level = "debug", skip(db, solver_choice))]
18 pub fn perform_orphan_check
<I
: Interner
>(
19 db
: &dyn RustIrDatabase
<I
>,
20 solver_choice
: SolverChoice
,
22 ) -> Result
<(), CoherenceError
<I
>> {
23 let impl_datum
= db
.impl_datum(impl_id
);
24 debug
!("impl_datum={:#?}", impl_datum
);
26 let impl_allowed
: Goal
<I
> = impl_datum
28 .map_ref(|bound_impl
| {
29 // Ignoring the polarization of the impl's polarized trait ref
30 DomainGoal
::LocalImplAllowed(bound_impl
.trait_ref
.clone())
34 let canonical_goal
= &impl_allowed
.into_closed_goal(db
.interner());
35 let is_allowed
= solver_choice
37 .solve(db
, canonical_goal
)
39 debug
!("overlaps = {:?}", is_allowed
);
42 let trait_id
= impl_datum
.trait_id();
43 Err(CoherenceError
::FailedOrphanCheck(trait_id
))?
;