Don't compare ast::Visibility by stringifying

This commit is contained in:
Lukas Tobias Wirth 2021-05-20 17:27:51 +02:00
parent 8bb37737c9
commit da7f1eb756
4 changed files with 74 additions and 6 deletions

View file

@ -608,6 +608,29 @@ impl ast::Visibility {
None => VisibilityKind::Pub,
}
}
pub fn is_eq_to(&self, other: &Self) -> bool {
match (self.kind(), other.kind()) {
(VisibilityKind::In(this), VisibilityKind::In(other)) => {
stdx::iter_eq_by(this.segments(), other.segments(), |lhs, rhs| {
lhs.kind().zip(rhs.kind()).map_or(false, |it| match it {
(PathSegmentKind::CrateKw, PathSegmentKind::CrateKw)
| (PathSegmentKind::SelfKw, PathSegmentKind::SelfKw)
| (PathSegmentKind::SuperKw, PathSegmentKind::SuperKw) => true,
(PathSegmentKind::Name(lhs), PathSegmentKind::Name(rhs)) => {
lhs.text() == rhs.text()
}
_ => false,
})
})
}
(VisibilityKind::PubSelf, VisibilityKind::PubSelf)
| (VisibilityKind::PubSuper, VisibilityKind::PubSuper)
| (VisibilityKind::PubCrate, VisibilityKind::PubCrate)
| (VisibilityKind::Pub, VisibilityKind::Pub) => true,
_ => false,
}
}
}
impl ast::LifetimeParam {