From da7f1eb756ba849b70ccb7e6c961ccf233e19099 Mon Sep 17 00:00:00 2001 From: Lukas Tobias Wirth Date: Thu, 20 May 2021 17:27:51 +0200 Subject: Don't compare ast::Visibility by stringifying --- crates/syntax/src/ast/node_ext.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'crates/syntax/src') diff --git a/crates/syntax/src/ast/node_ext.rs b/crates/syntax/src/ast/node_ext.rs index bef49238f..df8f98b5b 100644 --- a/crates/syntax/src/ast/node_ext.rs +++ b/crates/syntax/src/ast/node_ext.rs @@ -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 { -- cgit v1.2.3