mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Intern ModPath within RawVisibility
This commit is contained in:
parent
5548aecdca
commit
e052b3e9a6
4 changed files with 31 additions and 20 deletions
|
@ -323,7 +323,7 @@ impl TraitAliasData {
|
||||||
pub struct ImplData {
|
pub struct ImplData {
|
||||||
pub target_trait: Option<Interned<TraitRef>>,
|
pub target_trait: Option<Interned<TraitRef>>,
|
||||||
pub self_ty: Interned<TypeRef>,
|
pub self_ty: Interned<TypeRef>,
|
||||||
pub items: Vec<AssocItemId>,
|
pub items: Box<[AssocItemId]>,
|
||||||
pub is_negative: bool,
|
pub is_negative: bool,
|
||||||
pub is_unsafe: bool,
|
pub is_unsafe: bool,
|
||||||
// box it as the vec is usually empty anyways
|
// box it as the vec is usually empty anyways
|
||||||
|
|
|
@ -193,6 +193,7 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
|
||||||
#[salsa::invoke(Attrs::fields_attrs_query)]
|
#[salsa::invoke(Attrs::fields_attrs_query)]
|
||||||
fn fields_attrs(&self, def: VariantId) -> Arc<ArenaMap<LocalFieldId, Attrs>>;
|
fn fields_attrs(&self, def: VariantId) -> Arc<ArenaMap<LocalFieldId, Attrs>>;
|
||||||
|
|
||||||
|
// should this really be a query?
|
||||||
#[salsa::invoke(crate::attr::fields_attrs_source_map)]
|
#[salsa::invoke(crate::attr::fields_attrs_source_map)]
|
||||||
fn fields_attrs_source_map(
|
fn fields_attrs_source_map(
|
||||||
&self,
|
&self,
|
||||||
|
|
|
@ -616,24 +616,30 @@ impl Index<RawVisibilityId> for ItemTree {
|
||||||
type Output = RawVisibility;
|
type Output = RawVisibility;
|
||||||
fn index(&self, index: RawVisibilityId) -> &Self::Output {
|
fn index(&self, index: RawVisibilityId) -> &Self::Output {
|
||||||
static VIS_PUB: RawVisibility = RawVisibility::Public;
|
static VIS_PUB: RawVisibility = RawVisibility::Public;
|
||||||
static VIS_PRIV_IMPLICIT: RawVisibility = RawVisibility::Module(
|
static VIS_PRIV_IMPLICIT: OnceCell<RawVisibility> = OnceCell::new();
|
||||||
ModPath::from_kind(PathKind::SELF),
|
static VIS_PRIV_EXPLICIT: OnceCell<RawVisibility> = OnceCell::new();
|
||||||
VisibilityExplicitness::Implicit,
|
static VIS_PUB_CRATE: OnceCell<RawVisibility> = OnceCell::new();
|
||||||
);
|
|
||||||
static VIS_PRIV_EXPLICIT: RawVisibility = RawVisibility::Module(
|
|
||||||
ModPath::from_kind(PathKind::SELF),
|
|
||||||
VisibilityExplicitness::Explicit,
|
|
||||||
);
|
|
||||||
static VIS_PUB_CRATE: RawVisibility = RawVisibility::Module(
|
|
||||||
ModPath::from_kind(PathKind::Crate),
|
|
||||||
VisibilityExplicitness::Explicit,
|
|
||||||
);
|
|
||||||
|
|
||||||
match index {
|
match index {
|
||||||
RawVisibilityId::PRIV_IMPLICIT => &VIS_PRIV_IMPLICIT,
|
RawVisibilityId::PRIV_IMPLICIT => VIS_PRIV_IMPLICIT.get_or_init(|| {
|
||||||
RawVisibilityId::PRIV_EXPLICIT => &VIS_PRIV_EXPLICIT,
|
RawVisibility::Module(
|
||||||
|
Interned::new(ModPath::from_kind(PathKind::SELF)),
|
||||||
|
VisibilityExplicitness::Implicit,
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
RawVisibilityId::PRIV_EXPLICIT => VIS_PRIV_EXPLICIT.get_or_init(|| {
|
||||||
|
RawVisibility::Module(
|
||||||
|
Interned::new(ModPath::from_kind(PathKind::SELF)),
|
||||||
|
VisibilityExplicitness::Explicit,
|
||||||
|
)
|
||||||
|
}),
|
||||||
RawVisibilityId::PUB => &VIS_PUB,
|
RawVisibilityId::PUB => &VIS_PUB,
|
||||||
RawVisibilityId::PUB_CRATE => &VIS_PUB_CRATE,
|
RawVisibilityId::PUB_CRATE => VIS_PUB_CRATE.get_or_init(|| {
|
||||||
|
RawVisibility::Module(
|
||||||
|
Interned::new(ModPath::from_kind(PathKind::Crate)),
|
||||||
|
VisibilityExplicitness::Explicit,
|
||||||
|
)
|
||||||
|
}),
|
||||||
_ => &self.data().vis.arena[Idx::from_raw(index.0.into())],
|
_ => &self.data().vis.arena[Idx::from_raw(index.0.into())],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
|
use intern::Interned;
|
||||||
use la_arena::ArenaMap;
|
use la_arena::ArenaMap;
|
||||||
use span::SyntaxContextId;
|
use span::SyntaxContextId;
|
||||||
use syntax::ast;
|
use syntax::ast;
|
||||||
|
@ -20,14 +21,17 @@ use crate::{
|
||||||
pub enum RawVisibility {
|
pub enum RawVisibility {
|
||||||
/// `pub(in module)`, `pub(crate)` or `pub(super)`. Also private, which is
|
/// `pub(in module)`, `pub(crate)` or `pub(super)`. Also private, which is
|
||||||
/// equivalent to `pub(self)`.
|
/// equivalent to `pub(self)`.
|
||||||
Module(ModPath, VisibilityExplicitness),
|
Module(Interned<ModPath>, VisibilityExplicitness),
|
||||||
/// `pub`.
|
/// `pub`.
|
||||||
Public,
|
Public,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RawVisibility {
|
impl RawVisibility {
|
||||||
pub(crate) const fn private() -> RawVisibility {
|
pub(crate) fn private() -> RawVisibility {
|
||||||
RawVisibility::Module(ModPath::from_kind(PathKind::SELF), VisibilityExplicitness::Implicit)
|
RawVisibility::Module(
|
||||||
|
Interned::new(ModPath::from_kind(PathKind::SELF)),
|
||||||
|
VisibilityExplicitness::Implicit,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_ast(
|
pub(crate) fn from_ast(
|
||||||
|
@ -60,7 +64,7 @@ impl RawVisibility {
|
||||||
ast::VisibilityKind::PubSelf => ModPath::from_kind(PathKind::SELF),
|
ast::VisibilityKind::PubSelf => ModPath::from_kind(PathKind::SELF),
|
||||||
ast::VisibilityKind::Pub => return RawVisibility::Public,
|
ast::VisibilityKind::Pub => return RawVisibility::Public,
|
||||||
};
|
};
|
||||||
RawVisibility::Module(path, VisibilityExplicitness::Explicit)
|
RawVisibility::Module(Interned::new(path), VisibilityExplicitness::Explicit)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resolve(
|
pub fn resolve(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue