//! Defines hir-level representation of visibility (e.g. `pub` and `pub(crate)`).
use hir_expand::{hygiene::Hygiene, InFile};
use ra_syntax::ast;
use crate::{
db::DefDatabase,
path::{ModPath, PathKind},
AssocContainerId, ModuleId,
};
/// Visibility of an item, not yet resolved.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum RawVisibility {
/// `pub(in module)`, `pub(crate)` or `pub(super)`. Also private, which is
/// equivalent to `pub(self)`.
Module(ModPath),
/// `pub`.
Public,
}
impl RawVisibility {
pub(crate) const fn private() -> RawVisibility {
let path = ModPath { kind: PathKind::Super(0), segments: Vec::new() };
RawVisibility::Module(path)
}
pub(crate) fn default_for_container(container_id: AssocContainerId) -> Self {
match container_id {
AssocContainerId::TraitId(_) => RawVisibility::Public,
_ => RawVisibility::private(),
}
}
pub(crate) fn from_ast_with_default(
db: &dyn DefDatabase,
default: RawVisibility,
node: InFile