Wrap remaining self/super/crate in Name{Ref}

This commit is contained in:
Lukas Wirth
2021-01-15 21:07:38 +01:00
parent 8a869e870a
commit 98718e0544
28 changed files with 237 additions and 169 deletions

View File

@@ -198,6 +198,13 @@ impl ast::Path {
pub fn parent_path(&self) -> Option<ast::Path> {
self.syntax().parent().and_then(ast::Path::cast)
}
pub fn as_single_segment(&self) -> Option<ast::PathSegment> {
match self.qualifier() {
Some(_) => None,
None => self.segment(),
}
}
}
impl ast::UseTreeList {
@@ -448,16 +455,22 @@ pub enum VisibilityKind {
impl ast::Visibility {
pub fn kind(&self) -> VisibilityKind {
if let Some(path) = support::children(self.syntax()).next() {
VisibilityKind::In(path)
} else if self.crate_token().is_some() {
VisibilityKind::PubCrate
} else if self.super_token().is_some() {
VisibilityKind::PubSuper
} else if self.self_token().is_some() {
VisibilityKind::PubSelf
} else {
VisibilityKind::Pub
match self.path() {
Some(path) => {
if let Some(segment) =
path.as_single_segment().filter(|it| it.coloncolon_token().is_none())
{
if segment.crate_token().is_some() {
return VisibilityKind::PubCrate;
} else if segment.super_token().is_some() {
return VisibilityKind::PubSuper;
} else if segment.self_token().is_some() {
return VisibilityKind::PubSelf;
}
}
VisibilityKind::In(path)
}
None => VisibilityKind::Pub,
}
}
}