]>
git.proxmox.com Git - rustc.git/blob - vendor/chalk-ir/src/could_match.rs
1 use crate::interner
::HasInterner
;
2 use crate::zip
::{Zip, Zipper}
;
5 /// A fast check to see whether two things could ever possibly match.
6 pub trait CouldMatch
<T
: ?Sized
+ HasInterner
> {
7 fn could_match(&self, interner
: &T
::Interner
, other
: &T
) -> bool
;
10 #[allow(unreachable_code, unused_variables)]
11 impl<T
, I
> CouldMatch
<T
> for T
13 T
: Zip
<I
> + ?Sized
+ HasInterner
<Interner
= I
>,
16 fn could_match(&self, interner
: &I
, other
: &T
) -> bool
{
17 return Zip
::zip_with(&mut MatchZipper { interner }
, self, other
).is_ok();
19 struct MatchZipper
<'i
, I
> {
23 impl<'i
, I
: Interner
> Zipper
<'i
, I
> for MatchZipper
<'i
, I
> {
24 fn zip_tys(&mut self, a
: &Ty
<I
>, b
: &Ty
<I
>) -> Fallible
<()> {
25 let interner
= self.interner
;
26 let could_match
= match (a
.data(interner
), b
.data(interner
)) {
27 (&TyData
::Apply(ref a
), &TyData
::Apply(ref b
)) => {
28 let names_could_match
= a
.name
== b
.name
;
33 .zip(b
.substitution
.iter(interner
))
34 .all(|(p_a
, p_b
)| p_a
.could_match(interner
, &p_b
))
47 fn zip_lifetimes(&mut self, _
: &Lifetime
<I
>, _
: &Lifetime
<I
>) -> Fallible
<()> {
51 fn zip_binders
<T
>(&mut self, a
: &Binders
<T
>, b
: &Binders
<T
>) -> Fallible
<()>
53 T
: HasInterner
+ Zip
<I
>,
55 Zip
::zip_with(self, &a
.value
, &b
.value
)
58 fn interner(&self) -> &'i I
{
65 impl<I
: Interner
> CouldMatch
<DomainGoal
<I
>> for ProgramClauseData
<I
> {
66 fn could_match(&self, interner
: &I
, other
: &DomainGoal
<I
>) -> bool
{
68 ProgramClauseData
::Implies(implication
) => {
69 implication
.consequence
.could_match(interner
, other
)
72 ProgramClauseData
::ForAll(clause
) => {
73 clause
.value
.consequence
.could_match(interner
, other
)
79 impl<I
: Interner
> CouldMatch
<DomainGoal
<I
>> for ProgramClause
<I
> {
80 fn could_match(&self, interner
: &I
, other
: &DomainGoal
<I
>) -> bool
{
81 self.data(interner
).could_match(interner
, other
)