mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 11:31:15 +00:00
Remove dead code
This commit is contained in:
parent
23eef0c4ea
commit
2448abdb55
@ -63,13 +63,13 @@ use crate::{BlockId, Lookup, attr::Attrs, db::DefDatabase};
|
|||||||
pub(crate) use crate::item_tree::lower::{lower_use_tree, visibility_from_ast};
|
pub(crate) use crate::item_tree::lower::{lower_use_tree, visibility_from_ast};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||||
pub struct RawVisibilityId(u32);
|
pub(crate) struct RawVisibilityId(u32);
|
||||||
|
|
||||||
impl RawVisibilityId {
|
impl RawVisibilityId {
|
||||||
pub const PUB: Self = RawVisibilityId(u32::MAX);
|
const PUB: Self = RawVisibilityId(u32::MAX);
|
||||||
pub const PRIV_IMPLICIT: Self = RawVisibilityId(u32::MAX - 1);
|
const PRIV_IMPLICIT: Self = RawVisibilityId(u32::MAX - 1);
|
||||||
pub const PRIV_EXPLICIT: Self = RawVisibilityId(u32::MAX - 2);
|
const PRIV_EXPLICIT: Self = RawVisibilityId(u32::MAX - 2);
|
||||||
pub const PUB_CRATE: Self = RawVisibilityId(u32::MAX - 3);
|
const PUB_CRATE: Self = RawVisibilityId(u32::MAX - 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Debug for RawVisibilityId {
|
impl fmt::Debug for RawVisibilityId {
|
||||||
@ -188,12 +188,12 @@ impl ItemTree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the inner attributes of the source file.
|
/// Returns the inner attributes of the source file.
|
||||||
pub fn top_level_raw_attrs(&self) -> &RawAttrs {
|
pub(crate) fn top_level_raw_attrs(&self) -> &RawAttrs {
|
||||||
&self.top_attrs
|
&self.top_attrs
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the inner attributes of the source file.
|
/// Returns the inner attributes of the source file.
|
||||||
pub fn top_level_attrs(&self, db: &dyn DefDatabase, krate: Crate) -> Attrs {
|
pub(crate) fn top_level_attrs(&self, db: &dyn DefDatabase, krate: Crate) -> Attrs {
|
||||||
Attrs::expand_cfg_attr(db, krate, self.top_attrs.clone())
|
Attrs::expand_cfg_attr(db, krate, self.top_attrs.clone())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,17 +278,12 @@ pub struct ItemTreeDataStats {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Trait implemented by all nodes in the item tree.
|
/// Trait implemented by all nodes in the item tree.
|
||||||
pub trait ItemTreeNode: Clone {
|
pub(crate) trait ItemTreeNode: Clone {
|
||||||
type Source: AstIdNode;
|
type Source: AstIdNode;
|
||||||
|
|
||||||
fn ast_id(&self) -> FileAstId<Self::Source>;
|
|
||||||
|
|
||||||
/// Looks up an instance of `Self` in an item tree.
|
|
||||||
fn lookup(tree: &ItemTree, index: FileAstId<Self::Source>) -> &Self;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(type_alias_bounds)]
|
#[allow(type_alias_bounds)]
|
||||||
pub type ItemTreeAstId<T: ItemTreeNode> = FileAstId<T::Source>;
|
pub(crate) type ItemTreeAstId<T: ItemTreeNode> = FileAstId<T::Source>;
|
||||||
|
|
||||||
/// Identifies a particular [`ItemTree`].
|
/// Identifies a particular [`ItemTree`].
|
||||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
||||||
@ -298,11 +293,11 @@ pub struct TreeId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl TreeId {
|
impl TreeId {
|
||||||
pub fn new(file: HirFileId, block: Option<BlockId>) -> Self {
|
pub(crate) fn new(file: HirFileId, block: Option<BlockId>) -> Self {
|
||||||
Self { file, block }
|
Self { file, block }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn item_tree(&self, db: &dyn DefDatabase) -> Arc<ItemTree> {
|
pub(crate) fn item_tree(&self, db: &dyn DefDatabase) -> Arc<ItemTree> {
|
||||||
match self.block {
|
match self.block {
|
||||||
Some(block) => db.block_item_tree(block),
|
Some(block) => db.block_item_tree(block),
|
||||||
None => db.file_item_tree(self.file),
|
None => db.file_item_tree(self.file),
|
||||||
@ -314,7 +309,7 @@ impl TreeId {
|
|||||||
self.file
|
self.file
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_block(self) -> bool {
|
pub(crate) fn is_block(self) -> bool {
|
||||||
self.block.is_some()
|
self.block.is_some()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -347,17 +342,6 @@ macro_rules! mod_items {
|
|||||||
$(
|
$(
|
||||||
impl ItemTreeNode for $typ {
|
impl ItemTreeNode for $typ {
|
||||||
type Source = $ast;
|
type Source = $ast;
|
||||||
|
|
||||||
fn ast_id(&self) -> FileAstId<$ast> {
|
|
||||||
self.ast_id
|
|
||||||
}
|
|
||||||
|
|
||||||
fn lookup(tree: &ItemTree, index: FileAstId<$ast>) -> &Self {
|
|
||||||
match &tree.data[&index.upcast()] {
|
|
||||||
ModItem::$typ(item) => item,
|
|
||||||
_ => panic!("expected item of type `{}` at index `{:?}`", stringify!($typ), index),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Index<FileAstId<$ast>> for ItemTree {
|
impl Index<FileAstId<$ast>> for ItemTree {
|
||||||
@ -430,9 +414,9 @@ impl Index<RawVisibilityId> for ItemTree {
|
|||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct Use {
|
pub struct Use {
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub ast_id: FileAstId<ast::Use>,
|
pub(crate) ast_id: FileAstId<ast::Use>,
|
||||||
pub use_tree: UseTree,
|
pub(crate) use_tree: UseTree,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
@ -494,7 +478,7 @@ pub enum UseTreeKind {
|
|||||||
pub struct ExternCrate {
|
pub struct ExternCrate {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub alias: Option<ImportAlias>,
|
pub alias: Option<ImportAlias>,
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub ast_id: FileAstId<ast::ExternCrate>,
|
pub ast_id: FileAstId<ast::ExternCrate>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -507,14 +491,14 @@ pub struct ExternBlock {
|
|||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct Function {
|
pub struct Function {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub ast_id: FileAstId<ast::Fn>,
|
pub ast_id: FileAstId<ast::Fn>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct Struct {
|
pub struct Struct {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub shape: FieldsShape,
|
pub shape: FieldsShape,
|
||||||
pub ast_id: FileAstId<ast::Struct>,
|
pub ast_id: FileAstId<ast::Struct>,
|
||||||
}
|
}
|
||||||
@ -522,14 +506,14 @@ pub struct Struct {
|
|||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct Union {
|
pub struct Union {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub ast_id: FileAstId<ast::Union>,
|
pub ast_id: FileAstId<ast::Union>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct Enum {
|
pub struct Enum {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub ast_id: FileAstId<ast::Enum>,
|
pub ast_id: FileAstId<ast::Enum>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,28 +552,28 @@ impl VisibilityExplicitness {
|
|||||||
pub struct Const {
|
pub struct Const {
|
||||||
/// `None` for `const _: () = ();`
|
/// `None` for `const _: () = ();`
|
||||||
pub name: Option<Name>,
|
pub name: Option<Name>,
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub ast_id: FileAstId<ast::Const>,
|
pub ast_id: FileAstId<ast::Const>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct Static {
|
pub struct Static {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub ast_id: FileAstId<ast::Static>,
|
pub ast_id: FileAstId<ast::Static>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct Trait {
|
pub struct Trait {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub ast_id: FileAstId<ast::Trait>,
|
pub ast_id: FileAstId<ast::Trait>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct TraitAlias {
|
pub struct TraitAlias {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub ast_id: FileAstId<ast::TraitAlias>,
|
pub ast_id: FileAstId<ast::TraitAlias>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -601,14 +585,14 @@ pub struct Impl {
|
|||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct TypeAlias {
|
pub struct TypeAlias {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub ast_id: FileAstId<ast::TypeAlias>,
|
pub ast_id: FileAstId<ast::TypeAlias>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct Mod {
|
pub struct Mod {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub(crate) kind: ModKind,
|
pub(crate) kind: ModKind,
|
||||||
pub ast_id: FileAstId<ast::Module>,
|
pub ast_id: FileAstId<ast::Module>,
|
||||||
}
|
}
|
||||||
@ -641,7 +625,7 @@ pub struct MacroRules {
|
|||||||
#[derive(Debug, Clone, Eq, PartialEq)]
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
||||||
pub struct Macro2 {
|
pub struct Macro2 {
|
||||||
pub name: Name,
|
pub name: Name,
|
||||||
pub visibility: RawVisibilityId,
|
pub(crate) visibility: RawVisibilityId,
|
||||||
pub ast_id: FileAstId<ast::MacroDef>,
|
pub ast_id: FileAstId<ast::MacroDef>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ use crate::{
|
|||||||
db::DefDatabase,
|
db::DefDatabase,
|
||||||
item_scope::{GlobId, ImportId, ImportOrExternCrate, PerNsGlobImports},
|
item_scope::{GlobId, ImportId, ImportOrExternCrate, PerNsGlobImports},
|
||||||
item_tree::{
|
item_tree::{
|
||||||
self, FieldsShape, ImportAlias, ImportKind, ItemTree, ItemTreeAstId, ItemTreeNode, Macro2,
|
self, FieldsShape, ImportAlias, ImportKind, ItemTree, ItemTreeAstId, Macro2, MacroCall,
|
||||||
MacroCall, MacroRules, Mod, ModItemId, ModKind, TreeId, UseTreeKind,
|
MacroRules, Mod, ModItemId, ModKind, TreeId, UseTreeKind,
|
||||||
},
|
},
|
||||||
macro_call_as_call_id,
|
macro_call_as_call_id,
|
||||||
nameres::{
|
nameres::{
|
||||||
@ -1436,9 +1436,9 @@ impl DefCollector<'_> {
|
|||||||
|
|
||||||
let item_tree = tree.item_tree(self.db);
|
let item_tree = tree.item_tree(self.db);
|
||||||
let ast_adt_id: FileAstId<ast::Adt> = match *mod_item {
|
let ast_adt_id: FileAstId<ast::Adt> = match *mod_item {
|
||||||
ModItemId::Struct(strukt) => item_tree[strukt].ast_id().upcast(),
|
ModItemId::Struct(strukt) => item_tree[strukt].ast_id.upcast(),
|
||||||
ModItemId::Union(union) => item_tree[union].ast_id().upcast(),
|
ModItemId::Union(union) => item_tree[union].ast_id.upcast(),
|
||||||
ModItemId::Enum(enum_) => item_tree[enum_].ast_id().upcast(),
|
ModItemId::Enum(enum_) => item_tree[enum_].ast_id.upcast(),
|
||||||
_ => {
|
_ => {
|
||||||
let diag = DefDiagnostic::invalid_derive_target(
|
let diag = DefDiagnostic::invalid_derive_target(
|
||||||
directive.module_id,
|
directive.module_id,
|
||||||
@ -1889,7 +1889,7 @@ impl ModCollector<'_, '_> {
|
|||||||
if let Some(proc_macro) = attrs.parse_proc_macro_decl(&it.name) {
|
if let Some(proc_macro) = attrs.parse_proc_macro_decl(&it.name) {
|
||||||
self.def_collector.export_proc_macro(
|
self.def_collector.export_proc_macro(
|
||||||
proc_macro,
|
proc_macro,
|
||||||
InFile::new(self.file_id(), self.item_tree[id].ast_id()),
|
InFile::new(self.file_id(), self.item_tree[id].ast_id),
|
||||||
fn_id,
|
fn_id,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -2369,7 +2369,7 @@ impl ModCollector<'_, '_> {
|
|||||||
}
|
}
|
||||||
.intern(self.def_collector.db);
|
.intern(self.def_collector.db);
|
||||||
self.def_collector.def_map.macro_def_to_macro_id.insert(
|
self.def_collector.def_map.macro_def_to_macro_id.insert(
|
||||||
InFile::new(self.file_id(), self.item_tree[id].ast_id()).erase(),
|
InFile::new(self.file_id(), self.item_tree[id].ast_id).erase(),
|
||||||
macro_id.into(),
|
macro_id.into(),
|
||||||
);
|
);
|
||||||
self.def_collector.define_macro_rules(
|
self.def_collector.define_macro_rules(
|
||||||
@ -2437,7 +2437,7 @@ impl ModCollector<'_, '_> {
|
|||||||
}
|
}
|
||||||
.intern(self.def_collector.db);
|
.intern(self.def_collector.db);
|
||||||
self.def_collector.def_map.macro_def_to_macro_id.insert(
|
self.def_collector.def_map.macro_def_to_macro_id.insert(
|
||||||
InFile::new(self.file_id(), self.item_tree[id].ast_id()).erase(),
|
InFile::new(self.file_id(), self.item_tree[id].ast_id).erase(),
|
||||||
macro_id.into(),
|
macro_id.into(),
|
||||||
);
|
);
|
||||||
self.def_collector.define_macro_def(
|
self.def_collector.define_macro_def(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user