aboutsummaryrefslogtreecommitdiff
path: root/crates/syntax/src
diff options
context:
space:
mode:
authorLukas Tobias Wirth <[email protected]>2021-05-20 16:27:51 +0100
committerLukas Tobias Wirth <[email protected]>2021-05-20 16:45:59 +0100
commitda7f1eb756ba849b70ccb7e6c961ccf233e19099 (patch)
treedcb4766c1dbd85188ebea29a2d6f9f48d369a76c /crates/syntax/src
parent8bb37737c9e8b7a390ae29d5fb0daaeeb495d2b5 (diff)
Don't compare ast::Visibility by stringifying
Diffstat (limited to 'crates/syntax/src')
-rw-r--r--crates/syntax/src/ast/node_ext.rs23
1 files changed, 23 insertions, 0 deletions
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 {
608 None => VisibilityKind::Pub, 608 None => VisibilityKind::Pub,
609 } 609 }
610 } 610 }
611
612 pub fn is_eq_to(&self, other: &Self) -> bool {
613 match (self.kind(), other.kind()) {
614 (VisibilityKind::In(this), VisibilityKind::In(other)) => {
615 stdx::iter_eq_by(this.segments(), other.segments(), |lhs, rhs| {
616 lhs.kind().zip(rhs.kind()).map_or(false, |it| match it {
617 (PathSegmentKind::CrateKw, PathSegmentKind::CrateKw)
618 | (PathSegmentKind::SelfKw, PathSegmentKind::SelfKw)
619 | (PathSegmentKind::SuperKw, PathSegmentKind::SuperKw) => true,
620 (PathSegmentKind::Name(lhs), PathSegmentKind::Name(rhs)) => {
621 lhs.text() == rhs.text()
622 }
623 _ => false,
624 })
625 })
626 }
627 (VisibilityKind::PubSelf, VisibilityKind::PubSelf)
628 | (VisibilityKind::PubSuper, VisibilityKind::PubSuper)
629 | (VisibilityKind::PubCrate, VisibilityKind::PubCrate)
630 | (VisibilityKind::Pub, VisibilityKind::Pub) => true,
631 _ => false,
632 }
633 }
611} 634}
612 635
613impl ast::LifetimeParam { 636impl ast::LifetimeParam {