Add infrastructure for visibility on syntax and hir_def level

This commit is contained in:
Florian Diebold 2019-12-24 20:32:42 +01:00
parent 97f01396ed
commit 069bf55cca
5 changed files with 163 additions and 2 deletions

View file

@ -413,3 +413,32 @@ impl ast::TraitDef {
self.syntax().children_with_tokens().any(|t| t.kind() == T![auto])
}
}
pub enum VisibilityKind {
In(ast::Path),
PubCrate,
PubSuper,
Pub,
}
impl ast::Visibility {
pub fn kind(&self) -> VisibilityKind {
if let Some(path) = children(self).next() {
VisibilityKind::In(path)
} else if self.is_pub_crate() {
VisibilityKind::PubCrate
} else if self.is_pub_super() {
VisibilityKind::PubSuper
} else {
VisibilityKind::Pub
}
}
fn is_pub_crate(&self) -> bool {
self.syntax().children_with_tokens().any(|it| it.kind() == T![crate])
}
fn is_pub_super(&self) -> bool {
self.syntax().children_with_tokens().any(|it| it.kind() == T![super])
}
}