2020-03-25 09:33:01 -05:00
|
|
|
//! A simplified AST that only contains items.
|
2021-05-23 16:09:38 -05:00
|
|
|
//!
|
|
|
|
//! This is the primary IR used throughout `hir_def`. It is the input to the name resolution
|
|
|
|
//! algorithm, as well as to the queries defined in `adt.rs`, `data.rs`, and most things in
|
|
|
|
//! `attr.rs`.
|
|
|
|
//!
|
|
|
|
//! `ItemTree`s are built per `HirFileId`, from the syntax tree of the parsed file. This means that
|
|
|
|
//! they are crate-independent: they don't know which `#[cfg]`s are active or which module they
|
|
|
|
//! belong to, since those concepts don't exist at this level (a single `ItemTree` might be part of
|
|
|
|
//! multiple crates, or might be included into the same crate twice via `#[path]`).
|
|
|
|
//!
|
|
|
|
//! One important purpose of this layer is to provide an "invalidation barrier" for incremental
|
|
|
|
//! computations: when typing inside an item body, the `ItemTree` of the modified file is typically
|
|
|
|
//! unaffected, so we don't have to recompute name resolution results or item data (see `data.rs`).
|
|
|
|
//!
|
|
|
|
//! The `ItemTree` for the currently open file can be displayed by using the VS Code command
|
2022-08-01 06:47:09 -05:00
|
|
|
//! "rust-analyzer: Debug ItemTree".
|
2021-05-23 16:09:38 -05:00
|
|
|
//!
|
|
|
|
//! Compared to rustc's architecture, `ItemTree` has properties from both rustc's AST and HIR: many
|
|
|
|
//! syntax-level Rust features are already desugared to simpler forms in the `ItemTree`, but name
|
|
|
|
//! resolution has not yet been performed. `ItemTree`s are per-file, while rustc's AST and HIR are
|
|
|
|
//! per-crate, because we are interested in incrementally computing it.
|
|
|
|
//!
|
|
|
|
//! The representation of items in the `ItemTree` should generally mirror the surface syntax: it is
|
|
|
|
//! usually a bad idea to desugar a syntax-level construct to something that is structurally
|
|
|
|
//! different here. Name resolution needs to be able to process attributes and expand macros
|
|
|
|
//! (including attribute macros), and having a 1-to-1 mapping between syntax and the `ItemTree`
|
|
|
|
//! avoids introducing subtle bugs.
|
|
|
|
//!
|
|
|
|
//! In general, any item in the `ItemTree` stores its `AstId`, which allows mapping it back to its
|
|
|
|
//! surface syntax.
|
2023-12-21 02:18:06 -06:00
|
|
|
//!
|
|
|
|
//! Note that we cannot store [`span::Span`]s inside of this, as typing in an item invalidates its
|
|
|
|
//! encompassing span!
|
2020-03-25 09:33:01 -05:00
|
|
|
|
2020-06-16 07:52:43 -05:00
|
|
|
mod lower;
|
2021-05-21 16:45:27 -05:00
|
|
|
mod pretty;
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests;
|
2020-06-16 07:52:43 -05:00
|
|
|
|
|
|
|
use std::{
|
2020-06-16 12:20:29 -05:00
|
|
|
fmt::{self, Debug},
|
|
|
|
hash::{Hash, Hasher},
|
2024-01-15 03:24:14 -06:00
|
|
|
ops::{Index, Range},
|
2020-06-16 07:52:43 -05:00
|
|
|
};
|
|
|
|
|
2024-02-20 03:40:39 -06:00
|
|
|
use ast::{AstNode, StructKind};
|
2023-12-18 06:30:41 -06:00
|
|
|
use base_db::CrateId;
|
2020-06-16 07:52:43 -05:00
|
|
|
use either::Either;
|
2020-03-25 09:33:01 -05:00
|
|
|
use hir_expand::{
|
2023-07-04 02:16:15 -05:00
|
|
|
ast_id_map::{AstIdNode, FileAstId},
|
2023-01-09 12:29:28 -06:00
|
|
|
attrs::RawAttrs,
|
2024-02-20 03:40:39 -06:00
|
|
|
name::Name,
|
2021-09-05 14:30:06 -05:00
|
|
|
ExpandTo, HirFileId, InFile,
|
2020-03-25 09:33:01 -05:00
|
|
|
};
|
2023-01-09 12:29:28 -06:00
|
|
|
use intern::Interned;
|
2021-10-04 22:10:25 -05:00
|
|
|
use la_arena::{Arena, Idx, IdxRange, RawIdx};
|
2021-01-21 10:04:50 -06:00
|
|
|
use profile::Count;
|
2020-06-16 07:52:43 -05:00
|
|
|
use rustc_hash::FxHashMap;
|
2020-06-24 09:50:23 -05:00
|
|
|
use smallvec::SmallVec;
|
2023-12-20 05:53:46 -06:00
|
|
|
use span::Span;
|
2021-12-21 10:14:57 -06:00
|
|
|
use stdx::never;
|
2021-04-03 13:58:42 -05:00
|
|
|
use syntax::{ast, match_ast, SyntaxKind};
|
2023-05-02 09:12:22 -05:00
|
|
|
use triomphe::Arc;
|
2020-03-25 09:33:01 -05:00
|
|
|
|
|
|
|
use crate::{
|
2023-01-09 12:29:28 -06:00
|
|
|
attr::Attrs,
|
2020-06-11 12:46:56 -05:00
|
|
|
db::DefDatabase,
|
2023-07-27 20:17:10 -05:00
|
|
|
generics::{GenericParams, LifetimeParamData, TypeOrConstParamData},
|
2024-02-20 03:40:39 -06:00
|
|
|
path::{GenericArgs, ImportAlias, ModPath, Path, PathKind},
|
2021-03-24 11:00:29 -05:00
|
|
|
type_ref::{Mutability, TraitRef, TypeBound, TypeRef},
|
2024-02-02 04:22:54 -06:00
|
|
|
visibility::{RawVisibility, VisibilityExplicitness},
|
2023-08-10 13:10:19 -05:00
|
|
|
BlockId, Lookup,
|
2020-03-25 09:33:01 -05:00
|
|
|
};
|
2020-06-24 08:36:18 -05:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Eq, PartialEq)]
|
|
|
|
pub struct RawVisibilityId(u32);
|
|
|
|
|
|
|
|
impl RawVisibilityId {
|
|
|
|
pub const PUB: Self = RawVisibilityId(u32::max_value());
|
2024-01-11 04:36:10 -06:00
|
|
|
pub const PRIV_IMPLICIT: Self = RawVisibilityId(u32::max_value() - 1);
|
|
|
|
pub const PRIV_EXPLICIT: Self = RawVisibilityId(u32::max_value() - 2);
|
|
|
|
pub const PUB_CRATE: Self = RawVisibilityId(u32::max_value() - 3);
|
2020-06-24 08:36:18 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
impl fmt::Debug for RawVisibilityId {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
|
|
let mut f = f.debug_tuple("RawVisibilityId");
|
|
|
|
match *self {
|
|
|
|
Self::PUB => f.field(&"pub"),
|
2024-01-11 04:36:10 -06:00
|
|
|
Self::PRIV_IMPLICIT | Self::PRIV_EXPLICIT => f.field(&"pub(self)"),
|
2020-06-24 08:36:18 -05:00
|
|
|
Self::PUB_CRATE => f.field(&"pub(crate)"),
|
|
|
|
_ => f.field(&self.0),
|
|
|
|
};
|
|
|
|
f.finish()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-23 12:42:19 -05:00
|
|
|
/// The item tree of a source file.
|
2021-01-25 06:12:53 -06:00
|
|
|
#[derive(Debug, Default, Eq, PartialEq)]
|
2020-06-23 12:42:19 -05:00
|
|
|
pub struct ItemTree {
|
2021-01-21 10:04:50 -06:00
|
|
|
_c: Count<Self>,
|
|
|
|
|
2020-06-23 12:42:19 -05:00
|
|
|
top_level: SmallVec<[ModItem; 1]>,
|
2020-12-17 17:23:46 -06:00
|
|
|
attrs: FxHashMap<AttrOwner, RawAttrs>,
|
2020-06-23 12:42:19 -05:00
|
|
|
|
|
|
|
data: Option<Box<ItemTreeData>>,
|
|
|
|
}
|
|
|
|
|
2020-03-25 09:33:01 -05:00
|
|
|
impl ItemTree {
|
2021-03-12 19:24:26 -06:00
|
|
|
pub(crate) fn file_item_tree_query(db: &dyn DefDatabase, file_id: HirFileId) -> Arc<ItemTree> {
|
2024-01-17 20:27:38 -06:00
|
|
|
let _p = tracing::span!(tracing::Level::INFO, "file_item_tree_query", ?file_id).entered();
|
|
|
|
|
2023-04-16 12:20:48 -05:00
|
|
|
let syntax = db.parse_or_expand(file_id);
|
2020-06-11 12:46:56 -05:00
|
|
|
|
2021-12-21 10:14:57 -06:00
|
|
|
let ctx = lower::Ctx::new(db, file_id);
|
2020-06-15 12:16:02 -05:00
|
|
|
let mut top_attrs = None;
|
2020-06-23 06:46:38 -05:00
|
|
|
let mut item_tree = match_ast! {
|
2020-06-11 12:46:56 -05:00
|
|
|
match syntax {
|
|
|
|
ast::SourceFile(file) => {
|
2023-11-24 09:38:48 -06:00
|
|
|
top_attrs = Some(RawAttrs::new(db.upcast(), &file, ctx.span_map()));
|
2020-06-23 06:46:38 -05:00
|
|
|
ctx.lower_module_items(&file)
|
|
|
|
},
|
|
|
|
ast::MacroItems(items) => {
|
|
|
|
ctx.lower_module_items(&items)
|
|
|
|
},
|
2020-12-15 00:39:15 -06:00
|
|
|
ast::MacroStmts(stmts) => {
|
2021-01-28 11:00:10 -06:00
|
|
|
// The produced statements can include items, which should be added as top-level
|
|
|
|
// items.
|
|
|
|
ctx.lower_macro_stmts(stmts)
|
2020-12-15 00:39:15 -06:00
|
|
|
},
|
2020-06-23 06:46:38 -05:00
|
|
|
_ => {
|
2023-12-14 07:11:12 -06:00
|
|
|
if never!(syntax.kind() == SyntaxKind::ERROR, "{:?} from {:?} {}", file_id, syntax, syntax) {
|
|
|
|
return Default::default();
|
|
|
|
}
|
2023-02-07 08:21:37 -06:00
|
|
|
panic!("cannot create item tree for file {file_id:?} from {syntax:?} {syntax}");
|
2020-06-11 12:46:56 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-06-23 12:42:19 -05:00
|
|
|
if let Some(attrs) = top_attrs {
|
|
|
|
item_tree.attrs.insert(AttrOwner::TopLevel, attrs);
|
|
|
|
}
|
2020-06-24 09:14:58 -05:00
|
|
|
item_tree.shrink_to_fit();
|
2020-06-22 08:07:06 -05:00
|
|
|
Arc::new(item_tree)
|
|
|
|
}
|
|
|
|
|
2023-08-10 11:52:27 -05:00
|
|
|
pub(crate) fn block_item_tree_query(db: &dyn DefDatabase, block: BlockId) -> Arc<ItemTree> {
|
2023-08-10 13:10:19 -05:00
|
|
|
let loc = block.lookup(db);
|
2023-08-10 11:52:27 -05:00
|
|
|
let block = loc.ast_id.to_node(db.upcast());
|
|
|
|
|
|
|
|
let ctx = lower::Ctx::new(db, loc.ast_id.file_id);
|
2023-08-10 12:22:46 -05:00
|
|
|
let mut item_tree = ctx.lower_block(&block);
|
|
|
|
item_tree.shrink_to_fit();
|
|
|
|
Arc::new(item_tree)
|
2023-08-10 11:52:27 -05:00
|
|
|
}
|
|
|
|
|
2022-03-23 12:09:53 -05:00
|
|
|
/// Returns an iterator over all items located at the top level of the `HirFileId` this
|
|
|
|
/// `ItemTree` was created from.
|
|
|
|
pub fn top_level_items(&self) -> &[ModItem] {
|
|
|
|
&self.top_level
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Returns the inner attributes of the source file.
|
|
|
|
pub fn top_level_attrs(&self, db: &dyn DefDatabase, krate: CrateId) -> Attrs {
|
2023-01-09 12:29:28 -06:00
|
|
|
Attrs::filter(
|
|
|
|
db,
|
|
|
|
krate,
|
|
|
|
self.attrs.get(&AttrOwner::TopLevel).unwrap_or(&RawAttrs::EMPTY).clone(),
|
|
|
|
)
|
2022-03-23 12:09:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn raw_attrs(&self, of: AttrOwner) -> &RawAttrs {
|
|
|
|
self.attrs.get(&of).unwrap_or(&RawAttrs::EMPTY)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn attrs(&self, db: &dyn DefDatabase, krate: CrateId, of: AttrOwner) -> Attrs {
|
2023-01-09 12:29:28 -06:00
|
|
|
Attrs::filter(db, krate, self.raw_attrs(of).clone())
|
2022-03-23 12:09:53 -05:00
|
|
|
}
|
|
|
|
|
2023-05-24 11:04:29 -05:00
|
|
|
pub fn pretty_print(&self, db: &dyn DefDatabase) -> String {
|
2023-09-06 08:21:41 -05:00
|
|
|
pretty::print_item_tree(db, self)
|
2022-03-23 12:09:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn data(&self) -> &ItemTreeData {
|
|
|
|
self.data.as_ref().expect("attempted to access data of empty ItemTree")
|
|
|
|
}
|
|
|
|
|
|
|
|
fn data_mut(&mut self) -> &mut ItemTreeData {
|
|
|
|
self.data.get_or_insert_with(Box::default)
|
|
|
|
}
|
|
|
|
|
2020-06-24 09:14:58 -05:00
|
|
|
fn shrink_to_fit(&mut self) {
|
|
|
|
if let Some(data) = &mut self.data {
|
|
|
|
let ItemTreeData {
|
2023-08-02 07:19:38 -05:00
|
|
|
uses,
|
2020-06-24 09:14:58 -05:00
|
|
|
extern_crates,
|
2021-05-21 11:27:25 -05:00
|
|
|
extern_blocks,
|
2020-06-24 09:14:58 -05:00
|
|
|
functions,
|
2021-03-17 10:29:57 -05:00
|
|
|
params,
|
2020-06-24 09:14:58 -05:00
|
|
|
structs,
|
|
|
|
fields,
|
|
|
|
unions,
|
|
|
|
enums,
|
|
|
|
variants,
|
|
|
|
consts,
|
|
|
|
statics,
|
|
|
|
traits,
|
2023-03-03 09:24:07 -06:00
|
|
|
trait_aliases,
|
2020-06-24 09:14:58 -05:00
|
|
|
impls,
|
|
|
|
type_aliases,
|
|
|
|
mods,
|
|
|
|
macro_calls,
|
2020-12-15 08:37:37 -06:00
|
|
|
macro_rules,
|
2020-12-15 11:43:19 -06:00
|
|
|
macro_defs,
|
2020-06-24 09:14:58 -05:00
|
|
|
vis,
|
|
|
|
} = &mut **data;
|
|
|
|
|
2023-08-02 07:19:38 -05:00
|
|
|
uses.shrink_to_fit();
|
2020-06-24 09:14:58 -05:00
|
|
|
extern_crates.shrink_to_fit();
|
2021-05-21 11:27:25 -05:00
|
|
|
extern_blocks.shrink_to_fit();
|
2020-06-24 09:14:58 -05:00
|
|
|
functions.shrink_to_fit();
|
2021-03-17 10:29:57 -05:00
|
|
|
params.shrink_to_fit();
|
2020-06-24 09:14:58 -05:00
|
|
|
structs.shrink_to_fit();
|
|
|
|
fields.shrink_to_fit();
|
|
|
|
unions.shrink_to_fit();
|
|
|
|
enums.shrink_to_fit();
|
|
|
|
variants.shrink_to_fit();
|
|
|
|
consts.shrink_to_fit();
|
|
|
|
statics.shrink_to_fit();
|
|
|
|
traits.shrink_to_fit();
|
2023-03-03 09:24:07 -06:00
|
|
|
trait_aliases.shrink_to_fit();
|
2020-06-24 09:14:58 -05:00
|
|
|
impls.shrink_to_fit();
|
|
|
|
type_aliases.shrink_to_fit();
|
|
|
|
mods.shrink_to_fit();
|
|
|
|
macro_calls.shrink_to_fit();
|
2020-12-15 08:37:37 -06:00
|
|
|
macro_rules.shrink_to_fit();
|
2020-12-15 11:43:19 -06:00
|
|
|
macro_defs.shrink_to_fit();
|
2020-06-24 09:14:58 -05:00
|
|
|
|
|
|
|
vis.arena.shrink_to_fit();
|
|
|
|
}
|
|
|
|
}
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2020-06-24 09:50:23 -05:00
|
|
|
#[derive(Default, Debug, Eq, PartialEq)]
|
|
|
|
struct ItemVisibilities {
|
|
|
|
arena: Arena<RawVisibility>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ItemVisibilities {
|
|
|
|
fn alloc(&mut self, vis: RawVisibility) -> RawVisibilityId {
|
|
|
|
match &vis {
|
|
|
|
RawVisibility::Public => RawVisibilityId::PUB,
|
2024-01-11 04:36:10 -06:00
|
|
|
RawVisibility::Module(path, explicitiy) if path.segments().is_empty() => {
|
|
|
|
match (&path.kind, explicitiy) {
|
2024-02-02 04:22:54 -06:00
|
|
|
(PathKind::Super(0), VisibilityExplicitness::Explicit) => {
|
2024-01-11 04:36:10 -06:00
|
|
|
RawVisibilityId::PRIV_EXPLICIT
|
|
|
|
}
|
2024-02-02 04:22:54 -06:00
|
|
|
(PathKind::Super(0), VisibilityExplicitness::Implicit) => {
|
2024-01-11 04:36:10 -06:00
|
|
|
RawVisibilityId::PRIV_IMPLICIT
|
|
|
|
}
|
|
|
|
(PathKind::Crate, _) => RawVisibilityId::PUB_CRATE,
|
|
|
|
_ => RawVisibilityId(self.arena.alloc(vis).into_raw().into()),
|
|
|
|
}
|
|
|
|
}
|
2020-06-24 09:50:23 -05:00
|
|
|
_ => RawVisibilityId(self.arena.alloc(vis).into_raw().into()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static VIS_PUB: RawVisibility = RawVisibility::Public;
|
2024-01-11 04:36:10 -06:00
|
|
|
static VIS_PRIV_IMPLICIT: RawVisibility =
|
2024-02-02 04:22:54 -06:00
|
|
|
RawVisibility::Module(ModPath::from_kind(PathKind::Super(0)), VisibilityExplicitness::Implicit);
|
2024-01-11 04:36:10 -06:00
|
|
|
static VIS_PRIV_EXPLICIT: RawVisibility =
|
2024-02-02 04:22:54 -06:00
|
|
|
RawVisibility::Module(ModPath::from_kind(PathKind::Super(0)), VisibilityExplicitness::Explicit);
|
2024-01-11 04:36:10 -06:00
|
|
|
static VIS_PUB_CRATE: RawVisibility =
|
2024-02-02 04:22:54 -06:00
|
|
|
RawVisibility::Module(ModPath::from_kind(PathKind::Crate), VisibilityExplicitness::Explicit);
|
2020-06-24 09:50:23 -05:00
|
|
|
|
|
|
|
#[derive(Default, Debug, Eq, PartialEq)]
|
|
|
|
struct ItemTreeData {
|
2023-08-02 07:19:38 -05:00
|
|
|
uses: Arena<Use>,
|
2020-06-24 09:50:23 -05:00
|
|
|
extern_crates: Arena<ExternCrate>,
|
2021-05-21 11:27:25 -05:00
|
|
|
extern_blocks: Arena<ExternBlock>,
|
2020-06-24 09:50:23 -05:00
|
|
|
functions: Arena<Function>,
|
2021-03-17 10:29:57 -05:00
|
|
|
params: Arena<Param>,
|
2020-06-24 09:50:23 -05:00
|
|
|
structs: Arena<Struct>,
|
|
|
|
fields: Arena<Field>,
|
|
|
|
unions: Arena<Union>,
|
|
|
|
enums: Arena<Enum>,
|
|
|
|
variants: Arena<Variant>,
|
|
|
|
consts: Arena<Const>,
|
|
|
|
statics: Arena<Static>,
|
|
|
|
traits: Arena<Trait>,
|
2023-03-03 09:24:07 -06:00
|
|
|
trait_aliases: Arena<TraitAlias>,
|
2020-06-24 09:50:23 -05:00
|
|
|
impls: Arena<Impl>,
|
|
|
|
type_aliases: Arena<TypeAlias>,
|
|
|
|
mods: Arena<Mod>,
|
|
|
|
macro_calls: Arena<MacroCall>,
|
2020-12-15 08:37:37 -06:00
|
|
|
macro_rules: Arena<MacroRules>,
|
2023-12-21 02:18:06 -06:00
|
|
|
macro_defs: Arena<Macro2>,
|
2020-06-24 09:50:23 -05:00
|
|
|
|
|
|
|
vis: ItemVisibilities,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Eq, PartialEq, Hash)]
|
2020-06-25 07:39:27 -05:00
|
|
|
pub enum AttrOwner {
|
2020-06-24 09:50:23 -05:00
|
|
|
/// Attributes on an item.
|
|
|
|
ModItem(ModItem),
|
|
|
|
/// Inner attributes of the source file.
|
|
|
|
TopLevel,
|
2020-06-25 07:39:27 -05:00
|
|
|
|
2024-01-15 03:24:14 -06:00
|
|
|
Variant(FileItemTreeId<Variant>),
|
2020-06-25 07:39:27 -05:00
|
|
|
Field(Idx<Field>),
|
2021-03-17 10:29:57 -05:00
|
|
|
Param(Idx<Param>),
|
2023-07-27 20:17:10 -05:00
|
|
|
TypeOrConstParamData(Idx<TypeOrConstParamData>),
|
|
|
|
LifetimeParamData(Idx<LifetimeParamData>),
|
2020-06-24 09:50:23 -05:00
|
|
|
}
|
|
|
|
|
2020-06-25 07:39:27 -05:00
|
|
|
macro_rules! from_attrs {
|
2023-07-27 20:17:10 -05:00
|
|
|
( $( $var:ident($t:ty) ),+ $(,)? ) => {
|
2020-06-25 07:39:27 -05:00
|
|
|
$(
|
|
|
|
impl From<$t> for AttrOwner {
|
|
|
|
fn from(t: $t) -> AttrOwner {
|
|
|
|
AttrOwner::$var(t)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-07-27 20:17:10 -05:00
|
|
|
from_attrs!(
|
|
|
|
ModItem(ModItem),
|
2024-01-15 03:24:14 -06:00
|
|
|
Variant(FileItemTreeId<Variant>),
|
2023-07-27 20:17:10 -05:00
|
|
|
Field(Idx<Field>),
|
|
|
|
Param(Idx<Param>),
|
|
|
|
TypeOrConstParamData(Idx<TypeOrConstParamData>),
|
|
|
|
LifetimeParamData(Idx<LifetimeParamData>),
|
|
|
|
);
|
2020-06-25 07:39:27 -05:00
|
|
|
|
2024-02-10 04:37:59 -06:00
|
|
|
/// Trait implemented by all nodes in the item tree.
|
|
|
|
pub trait ItemTreeNode: Clone {
|
|
|
|
type Source: AstIdNode;
|
2020-06-23 11:46:08 -05:00
|
|
|
|
|
|
|
fn ast_id(&self) -> FileAstId<Self::Source>;
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
/// Looks up an instance of `Self` in an item tree.
|
2020-06-16 12:20:29 -05:00
|
|
|
fn lookup(tree: &ItemTree, index: Idx<Self>) -> &Self;
|
2024-02-10 04:37:59 -06:00
|
|
|
fn attr_owner(id: FileItemTreeId<Self>) -> AttrOwner;
|
2020-06-16 12:20:29 -05:00
|
|
|
}
|
2024-02-10 05:40:23 -06:00
|
|
|
pub trait GenericsItemTreeNode: ItemTreeNode {
|
|
|
|
fn generic_params(&self) -> &Interned<GenericParams>;
|
|
|
|
}
|
2020-06-16 12:20:29 -05:00
|
|
|
|
2024-01-15 03:24:14 -06:00
|
|
|
pub struct FileItemTreeId<N>(Idx<N>);
|
2023-11-16 11:39:36 -06:00
|
|
|
|
2024-01-15 03:24:14 -06:00
|
|
|
impl<N> FileItemTreeId<N> {
|
|
|
|
pub fn range_iter(range: Range<Self>) -> impl Iterator<Item = Self> {
|
|
|
|
(range.start.index().into_raw().into_u32()..range.end.index().into_raw().into_u32())
|
|
|
|
.map(RawIdx::from_u32)
|
|
|
|
.map(Idx::from_raw)
|
|
|
|
.map(Self)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<N> FileItemTreeId<N> {
|
2023-11-16 11:39:36 -06:00
|
|
|
pub fn index(&self) -> Idx<N> {
|
|
|
|
self.0
|
|
|
|
}
|
2020-06-16 12:20:29 -05:00
|
|
|
}
|
|
|
|
|
2024-01-15 03:24:14 -06:00
|
|
|
impl<N> Clone for FileItemTreeId<N> {
|
2020-06-16 12:20:29 -05:00
|
|
|
fn clone(&self) -> Self {
|
2024-02-09 07:37:42 -06:00
|
|
|
*self
|
2020-06-16 12:20:29 -05:00
|
|
|
}
|
|
|
|
}
|
2024-01-15 03:24:14 -06:00
|
|
|
impl<N> Copy for FileItemTreeId<N> {}
|
2020-06-16 12:20:29 -05:00
|
|
|
|
2024-01-15 03:24:14 -06:00
|
|
|
impl<N> PartialEq for FileItemTreeId<N> {
|
2020-06-16 12:20:29 -05:00
|
|
|
fn eq(&self, other: &FileItemTreeId<N>) -> bool {
|
2023-11-16 11:39:36 -06:00
|
|
|
self.0 == other.0
|
2020-06-16 12:20:29 -05:00
|
|
|
}
|
|
|
|
}
|
2024-01-15 03:24:14 -06:00
|
|
|
impl<N> Eq for FileItemTreeId<N> {}
|
2020-06-16 12:20:29 -05:00
|
|
|
|
2024-01-15 03:24:14 -06:00
|
|
|
impl<N> Hash for FileItemTreeId<N> {
|
2020-06-16 12:20:29 -05:00
|
|
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
2023-11-16 11:39:36 -06:00
|
|
|
self.0.hash(state)
|
2020-06-16 12:20:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-15 03:24:14 -06:00
|
|
|
impl<N> fmt::Debug for FileItemTreeId<N> {
|
2020-06-16 12:20:29 -05:00
|
|
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
2023-11-16 11:39:36 -06:00
|
|
|
self.0.fmt(f)
|
2020-06-16 12:20:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-19 07:53:18 -05:00
|
|
|
/// Identifies a particular [`ItemTree`].
|
|
|
|
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
|
|
|
pub struct TreeId {
|
|
|
|
file: HirFileId,
|
|
|
|
block: Option<BlockId>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TreeId {
|
|
|
|
pub(crate) fn new(file: HirFileId, block: Option<BlockId>) -> Self {
|
|
|
|
Self { file, block }
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn item_tree(&self, db: &dyn DefDatabase) -> Arc<ItemTree> {
|
|
|
|
match self.block {
|
2023-08-10 12:22:46 -05:00
|
|
|
Some(block) => db.block_item_tree_query(block),
|
2021-07-19 07:53:18 -05:00
|
|
|
None => db.file_item_tree(self.file),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub(crate) fn file_id(self) -> HirFileId {
|
|
|
|
self.file
|
|
|
|
}
|
2021-11-25 17:17:20 -06:00
|
|
|
|
|
|
|
pub(crate) fn is_block(self) -> bool {
|
|
|
|
self.block.is_some()
|
|
|
|
}
|
2021-07-19 07:53:18 -05:00
|
|
|
}
|
|
|
|
|
2021-03-12 17:34:01 -06:00
|
|
|
#[derive(Debug)]
|
2024-01-15 03:24:14 -06:00
|
|
|
pub struct ItemTreeId<N> {
|
2021-07-19 07:53:18 -05:00
|
|
|
tree: TreeId,
|
2021-03-12 17:34:01 -06:00
|
|
|
pub value: FileItemTreeId<N>,
|
|
|
|
}
|
|
|
|
|
2024-01-15 03:24:14 -06:00
|
|
|
impl<N> ItemTreeId<N> {
|
2021-07-19 07:53:18 -05:00
|
|
|
pub fn new(tree: TreeId, idx: FileItemTreeId<N>) -> Self {
|
|
|
|
Self { tree, value: idx }
|
2021-03-12 17:34:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn file_id(self) -> HirFileId {
|
2021-07-19 07:53:18 -05:00
|
|
|
self.tree.file
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn tree_id(self) -> TreeId {
|
|
|
|
self.tree
|
2021-03-12 17:34:01 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn item_tree(self, db: &dyn DefDatabase) -> Arc<ItemTree> {
|
2021-07-19 07:53:18 -05:00
|
|
|
self.tree.item_tree(db)
|
2021-03-12 17:34:01 -06:00
|
|
|
}
|
2024-01-15 03:58:05 -06:00
|
|
|
|
|
|
|
pub fn resolved<R>(self, db: &dyn DefDatabase, cb: impl FnOnce(&N) -> R) -> R
|
|
|
|
where
|
|
|
|
ItemTree: Index<FileItemTreeId<N>, Output = N>,
|
|
|
|
{
|
|
|
|
cb(&self.tree.item_tree(db)[self.value])
|
|
|
|
}
|
2021-03-12 17:34:01 -06:00
|
|
|
}
|
|
|
|
|
2024-01-15 03:24:14 -06:00
|
|
|
impl<N> Copy for ItemTreeId<N> {}
|
|
|
|
impl<N> Clone for ItemTreeId<N> {
|
2021-03-12 17:34:01 -06:00
|
|
|
fn clone(&self) -> Self {
|
|
|
|
*self
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-15 03:24:14 -06:00
|
|
|
impl<N> PartialEq for ItemTreeId<N> {
|
2021-03-12 17:34:01 -06:00
|
|
|
fn eq(&self, other: &Self) -> bool {
|
2021-07-19 07:53:18 -05:00
|
|
|
self.tree == other.tree && self.value == other.value
|
2021-03-12 17:34:01 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-01-15 03:24:14 -06:00
|
|
|
impl<N> Eq for ItemTreeId<N> {}
|
2021-03-12 17:34:01 -06:00
|
|
|
|
2024-01-15 03:24:14 -06:00
|
|
|
impl<N> Hash for ItemTreeId<N> {
|
2021-03-12 17:34:01 -06:00
|
|
|
fn hash<H: Hasher>(&self, state: &mut H) {
|
2021-07-19 07:53:18 -05:00
|
|
|
self.tree.hash(state);
|
2021-03-12 17:34:01 -06:00
|
|
|
self.value.hash(state);
|
|
|
|
}
|
|
|
|
}
|
2020-06-16 12:20:29 -05:00
|
|
|
|
2020-06-23 11:41:32 -05:00
|
|
|
macro_rules! mod_items {
|
2024-02-10 05:40:23 -06:00
|
|
|
( $( $typ:ident $(<$generic_params:ident>)? in $fld:ident -> $ast:ty ),+ $(,)? ) => {
|
2020-06-23 11:41:32 -05:00
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
|
|
|
|
pub enum ModItem {
|
|
|
|
$(
|
|
|
|
$typ(FileItemTreeId<$typ>),
|
|
|
|
)+
|
|
|
|
}
|
|
|
|
|
|
|
|
$(
|
|
|
|
impl From<FileItemTreeId<$typ>> for ModItem {
|
|
|
|
fn from(id: FileItemTreeId<$typ>) -> ModItem {
|
|
|
|
ModItem::$typ(id)
|
|
|
|
}
|
2020-06-16 12:20:29 -05:00
|
|
|
}
|
2020-06-23 11:41:32 -05:00
|
|
|
)+
|
2020-06-22 08:07:06 -05:00
|
|
|
|
2020-06-23 11:41:32 -05:00
|
|
|
$(
|
2024-02-10 04:37:59 -06:00
|
|
|
impl ItemTreeNode for $typ {
|
2020-06-23 11:46:08 -05:00
|
|
|
type Source = $ast;
|
|
|
|
|
|
|
|
fn ast_id(&self) -> FileAstId<Self::Source> {
|
|
|
|
self.ast_id
|
|
|
|
}
|
|
|
|
|
2020-06-23 11:41:32 -05:00
|
|
|
fn lookup(tree: &ItemTree, index: Idx<Self>) -> &Self {
|
2020-06-23 12:42:19 -05:00
|
|
|
&tree.data().$fld[index]
|
2020-06-23 11:41:32 -05:00
|
|
|
}
|
2020-06-22 08:07:06 -05:00
|
|
|
|
2024-02-10 04:37:59 -06:00
|
|
|
fn attr_owner(id: FileItemTreeId<Self>) -> AttrOwner {
|
|
|
|
AttrOwner::ModItem(ModItem::$typ(id))
|
2020-06-22 08:07:06 -05:00
|
|
|
}
|
|
|
|
}
|
2020-06-22 12:15:54 -05:00
|
|
|
|
2020-06-23 11:41:32 -05:00
|
|
|
impl Index<Idx<$typ>> for ItemTree {
|
|
|
|
type Output = $typ;
|
|
|
|
|
|
|
|
fn index(&self, index: Idx<$typ>) -> &Self::Output {
|
2020-06-23 12:42:19 -05:00
|
|
|
&self.data().$fld[index]
|
2020-06-23 11:41:32 -05:00
|
|
|
}
|
2020-06-17 11:43:41 -05:00
|
|
|
}
|
2024-02-10 05:40:23 -06:00
|
|
|
|
|
|
|
$(
|
|
|
|
impl GenericsItemTreeNode for $typ {
|
|
|
|
fn generic_params(&self) -> &Interned<GenericParams> {
|
|
|
|
&self.$generic_params
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)?
|
2020-06-23 11:41:32 -05:00
|
|
|
)+
|
|
|
|
};
|
2020-06-17 11:43:41 -05:00
|
|
|
}
|
|
|
|
|
2020-06-23 11:41:32 -05:00
|
|
|
mod_items! {
|
2023-08-02 07:19:38 -05:00
|
|
|
Use in uses -> ast::Use,
|
2020-07-30 05:26:57 -05:00
|
|
|
ExternCrate in extern_crates -> ast::ExternCrate,
|
2021-05-21 11:27:25 -05:00
|
|
|
ExternBlock in extern_blocks -> ast::ExternBlock,
|
2024-02-10 05:40:23 -06:00
|
|
|
Function<explicit_generic_params> in functions -> ast::Fn,
|
|
|
|
Struct<generic_params> in structs -> ast::Struct,
|
|
|
|
Union<generic_params> in unions -> ast::Union,
|
|
|
|
Enum<generic_params> in enums -> ast::Enum,
|
2020-07-30 11:02:20 -05:00
|
|
|
Const in consts -> ast::Const,
|
|
|
|
Static in statics -> ast::Static,
|
2024-02-10 05:40:23 -06:00
|
|
|
Trait<generic_params> in traits -> ast::Trait,
|
|
|
|
TraitAlias<generic_params> in trait_aliases -> ast::TraitAlias,
|
|
|
|
Impl<generic_params> in impls -> ast::Impl,
|
|
|
|
TypeAlias<generic_params> in type_aliases -> ast::TypeAlias,
|
2020-06-23 11:41:32 -05:00
|
|
|
Mod in mods -> ast::Module,
|
|
|
|
MacroCall in macro_calls -> ast::MacroCall,
|
2020-12-15 08:37:37 -06:00
|
|
|
MacroRules in macro_rules -> ast::MacroRules,
|
2023-12-21 02:18:06 -06:00
|
|
|
Macro2 in macro_defs -> ast::MacroDef,
|
2020-06-17 11:43:41 -05:00
|
|
|
}
|
|
|
|
|
2020-03-25 09:33:01 -05:00
|
|
|
macro_rules! impl_index {
|
|
|
|
( $($fld:ident: $t:ty),+ $(,)? ) => {
|
|
|
|
$(
|
|
|
|
impl Index<Idx<$t>> for ItemTree {
|
|
|
|
type Output = $t;
|
|
|
|
|
|
|
|
fn index(&self, index: Idx<$t>) -> &Self::Output {
|
2020-06-23 12:42:19 -05:00
|
|
|
&self.data().$fld[index]
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)+
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-03-17 10:29:57 -05:00
|
|
|
impl_index!(fields: Field, variants: Variant, params: Param);
|
2020-03-25 09:33:01 -05:00
|
|
|
|
2020-06-24 08:36:18 -05:00
|
|
|
impl Index<RawVisibilityId> for ItemTree {
|
|
|
|
type Output = RawVisibility;
|
|
|
|
fn index(&self, index: RawVisibilityId) -> &Self::Output {
|
|
|
|
match index {
|
2024-01-11 04:36:10 -06:00
|
|
|
RawVisibilityId::PRIV_IMPLICIT => &VIS_PRIV_IMPLICIT,
|
|
|
|
RawVisibilityId::PRIV_EXPLICIT => &VIS_PRIV_EXPLICIT,
|
2020-06-24 08:36:18 -05:00
|
|
|
RawVisibilityId::PUB => &VIS_PUB,
|
|
|
|
RawVisibilityId::PUB_CRATE => &VIS_PUB_CRATE,
|
|
|
|
_ => &self.data().vis.arena[Idx::from_raw(index.0.into())],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-10 04:37:59 -06:00
|
|
|
impl<N: ItemTreeNode> Index<FileItemTreeId<N>> for ItemTree {
|
2020-06-16 12:20:29 -05:00
|
|
|
type Output = N;
|
|
|
|
fn index(&self, id: FileItemTreeId<N>) -> &N {
|
2023-11-16 11:39:36 -06:00
|
|
|
N::lookup(self, id.index())
|
2020-06-16 12:20:29 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-10 04:37:59 -06:00
|
|
|
impl ItemTreeNode for Variant {
|
|
|
|
type Source = ast::Variant;
|
|
|
|
|
|
|
|
fn ast_id(&self) -> FileAstId<Self::Source> {
|
|
|
|
self.ast_id
|
|
|
|
}
|
|
|
|
|
|
|
|
fn lookup(tree: &ItemTree, index: Idx<Self>) -> &Self {
|
|
|
|
&tree.data().variants[index]
|
|
|
|
}
|
|
|
|
|
|
|
|
fn attr_owner(id: FileItemTreeId<Self>) -> AttrOwner {
|
|
|
|
AttrOwner::Variant(id)
|
2024-01-15 03:24:14 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-12 16:24:26 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2023-08-02 07:19:38 -05:00
|
|
|
pub struct Use {
|
2020-06-24 08:36:18 -05:00
|
|
|
pub visibility: RawVisibilityId,
|
2020-07-30 07:12:04 -05:00
|
|
|
pub ast_id: FileAstId<ast::Use>,
|
2021-05-25 18:01:58 -05:00
|
|
|
pub use_tree: UseTree,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
|
|
pub struct UseTree {
|
|
|
|
pub index: Idx<ast::UseTree>,
|
|
|
|
kind: UseTreeKind,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
|
|
pub enum UseTreeKind {
|
2021-05-27 06:55:31 -05:00
|
|
|
/// ```
|
2021-05-25 18:01:58 -05:00
|
|
|
/// use path::to::Item;
|
|
|
|
/// use path::to::Item as Renamed;
|
|
|
|
/// use path::to::Trait as _;
|
|
|
|
/// ```
|
2021-05-25 18:26:16 -05:00
|
|
|
Single { path: Interned<ModPath>, alias: Option<ImportAlias> },
|
2021-05-25 18:01:58 -05:00
|
|
|
|
2021-05-27 06:55:31 -05:00
|
|
|
/// ```
|
2021-05-25 18:01:58 -05:00
|
|
|
/// use *; // (invalid, but can occur in nested tree)
|
|
|
|
/// use path::*;
|
|
|
|
/// ```
|
2021-05-25 18:26:16 -05:00
|
|
|
Glob { path: Option<Interned<ModPath>> },
|
2021-05-25 18:01:58 -05:00
|
|
|
|
2021-05-27 06:55:31 -05:00
|
|
|
/// ```
|
2021-05-25 18:01:58 -05:00
|
|
|
/// use prefix::{self, Item, ...};
|
|
|
|
/// ```
|
2021-05-25 18:26:16 -05:00
|
|
|
Prefixed { prefix: Option<Interned<ModPath>>, list: Box<[UseTree]> },
|
2020-06-22 08:07:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
|
|
pub struct ExternCrate {
|
2020-09-17 08:28:23 -05:00
|
|
|
pub name: Name,
|
2020-06-22 08:07:06 -05:00
|
|
|
pub alias: Option<ImportAlias>,
|
2020-06-24 08:36:18 -05:00
|
|
|
pub visibility: RawVisibilityId,
|
2020-07-30 05:26:57 -05:00
|
|
|
pub ast_id: FileAstId<ast::ExternCrate>,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2021-05-21 11:27:25 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
|
|
pub struct ExternBlock {
|
|
|
|
pub abi: Option<Interned<str>>,
|
|
|
|
pub ast_id: FileAstId<ast::ExternBlock>,
|
|
|
|
pub children: Box<[ModItem]>,
|
|
|
|
}
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2020-03-25 09:33:01 -05:00
|
|
|
pub struct Function {
|
|
|
|
pub name: Name,
|
2020-06-24 08:36:18 -05:00
|
|
|
pub visibility: RawVisibilityId,
|
2021-09-21 08:36:52 -05:00
|
|
|
pub explicit_generic_params: Interned<GenericParams>,
|
2021-04-03 13:58:42 -05:00
|
|
|
pub abi: Option<Interned<str>>,
|
2021-10-04 22:10:25 -05:00
|
|
|
pub params: IdxRange<Param>,
|
2021-04-01 12:46:43 -05:00
|
|
|
pub ret_type: Interned<TypeRef>,
|
2020-07-30 07:51:08 -05:00
|
|
|
pub ast_id: FileAstId<ast::Fn>,
|
2021-04-03 13:58:42 -05:00
|
|
|
pub(crate) flags: FnFlags,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2023-09-28 06:16:11 -05:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
pub struct Param {
|
|
|
|
/// This is [`None`] for varargs
|
|
|
|
pub type_ref: Option<Interned<TypeRef>>,
|
|
|
|
pub ast_id: ParamAstId,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
pub enum ParamAstId {
|
|
|
|
Param(FileAstId<ast::Param>),
|
|
|
|
SelfParam(FileAstId<ast::SelfParam>),
|
2021-03-17 10:29:57 -05:00
|
|
|
}
|
|
|
|
|
2022-04-07 09:13:37 -05:00
|
|
|
bitflags::bitflags! {
|
2023-04-17 10:42:59 -05:00
|
|
|
#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)]
|
2022-04-07 09:13:37 -05:00
|
|
|
pub(crate) struct FnFlags: u8 {
|
|
|
|
const HAS_SELF_PARAM = 1 << 0;
|
|
|
|
const HAS_BODY = 1 << 1;
|
2022-04-07 11:33:03 -05:00
|
|
|
const HAS_DEFAULT_KW = 1 << 2;
|
|
|
|
const HAS_CONST_KW = 1 << 3;
|
|
|
|
const HAS_ASYNC_KW = 1 << 4;
|
|
|
|
const HAS_UNSAFE_KW = 1 << 5;
|
2022-04-07 09:13:37 -05:00
|
|
|
const IS_VARARGS = 1 << 6;
|
|
|
|
}
|
2021-03-14 05:00:11 -05:00
|
|
|
}
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2020-03-25 09:33:01 -05:00
|
|
|
pub struct Struct {
|
|
|
|
pub name: Name,
|
2020-06-24 08:36:18 -05:00
|
|
|
pub visibility: RawVisibilityId,
|
2021-04-04 20:50:10 -05:00
|
|
|
pub generic_params: Interned<GenericParams>,
|
2020-03-25 09:33:01 -05:00
|
|
|
pub fields: Fields,
|
2020-07-30 10:50:40 -05:00
|
|
|
pub ast_id: FileAstId<ast::Struct>,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2020-03-25 09:33:01 -05:00
|
|
|
pub struct Union {
|
|
|
|
pub name: Name,
|
2020-06-24 08:36:18 -05:00
|
|
|
pub visibility: RawVisibilityId,
|
2021-04-04 20:50:10 -05:00
|
|
|
pub generic_params: Interned<GenericParams>,
|
2020-03-25 09:33:01 -05:00
|
|
|
pub fields: Fields,
|
2020-07-30 10:36:46 -05:00
|
|
|
pub ast_id: FileAstId<ast::Union>,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2020-03-25 09:33:01 -05:00
|
|
|
pub struct Enum {
|
|
|
|
pub name: Name,
|
2020-06-24 08:36:18 -05:00
|
|
|
pub visibility: RawVisibilityId,
|
2021-04-04 20:50:10 -05:00
|
|
|
pub generic_params: Interned<GenericParams>,
|
2024-01-15 03:24:14 -06:00
|
|
|
pub variants: Range<FileItemTreeId<Variant>>,
|
2020-07-30 10:52:53 -05:00
|
|
|
pub ast_id: FileAstId<ast::Enum>,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2020-03-25 09:33:01 -05:00
|
|
|
pub struct Const {
|
2021-12-08 08:44:52 -06:00
|
|
|
/// `None` for `const _: () = ();`
|
2020-03-25 09:33:01 -05:00
|
|
|
pub name: Option<Name>,
|
2020-06-24 08:36:18 -05:00
|
|
|
pub visibility: RawVisibilityId,
|
2021-04-01 12:46:43 -05:00
|
|
|
pub type_ref: Interned<TypeRef>,
|
2020-07-30 11:02:20 -05:00
|
|
|
pub ast_id: FileAstId<ast::Const>,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2020-03-25 09:33:01 -05:00
|
|
|
pub struct Static {
|
|
|
|
pub name: Name,
|
2020-06-24 08:36:18 -05:00
|
|
|
pub visibility: RawVisibilityId,
|
2020-06-22 09:41:10 -05:00
|
|
|
pub mutable: bool,
|
2021-04-01 12:46:43 -05:00
|
|
|
pub type_ref: Interned<TypeRef>,
|
2020-07-30 11:02:20 -05:00
|
|
|
pub ast_id: FileAstId<ast::Static>,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2020-03-25 09:33:01 -05:00
|
|
|
pub struct Trait {
|
|
|
|
pub name: Name,
|
2020-06-24 08:36:18 -05:00
|
|
|
pub visibility: RawVisibilityId,
|
2021-04-04 20:50:10 -05:00
|
|
|
pub generic_params: Interned<GenericParams>,
|
2021-03-15 11:05:03 -05:00
|
|
|
pub is_auto: bool,
|
|
|
|
pub is_unsafe: bool,
|
2023-03-03 09:24:07 -06:00
|
|
|
pub items: Box<[AssocItem]>,
|
2020-07-30 11:17:28 -05:00
|
|
|
pub ast_id: FileAstId<ast::Trait>,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2023-03-03 09:24:07 -06:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
|
|
pub struct TraitAlias {
|
|
|
|
pub name: Name,
|
|
|
|
pub visibility: RawVisibilityId,
|
|
|
|
pub generic_params: Interned<GenericParams>,
|
|
|
|
pub ast_id: FileAstId<ast::TraitAlias>,
|
|
|
|
}
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2020-03-25 09:33:01 -05:00
|
|
|
pub struct Impl {
|
2021-04-04 20:50:10 -05:00
|
|
|
pub generic_params: Interned<GenericParams>,
|
2021-04-01 12:46:43 -05:00
|
|
|
pub target_trait: Option<Interned<TraitRef>>,
|
|
|
|
pub self_ty: Interned<TypeRef>,
|
2020-03-25 09:33:01 -05:00
|
|
|
pub is_negative: bool,
|
2023-11-14 13:02:23 -06:00
|
|
|
pub is_unsafe: bool,
|
2020-06-24 09:07:02 -05:00
|
|
|
pub items: Box<[AssocItem]>,
|
2020-07-30 11:28:28 -05:00
|
|
|
pub ast_id: FileAstId<ast::Impl>,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
pub struct TypeAlias {
|
|
|
|
pub name: Name,
|
2020-06-24 08:36:18 -05:00
|
|
|
pub visibility: RawVisibilityId,
|
2020-06-22 09:41:10 -05:00
|
|
|
/// Bounds on the type alias itself. Only valid in trait declarations, eg. `type Assoc: Copy;`.
|
2021-05-24 08:13:23 -05:00
|
|
|
pub bounds: Box<[Interned<TypeBound>]>,
|
2021-04-04 20:50:10 -05:00
|
|
|
pub generic_params: Interned<GenericParams>,
|
2021-04-01 12:46:43 -05:00
|
|
|
pub type_ref: Option<Interned<TypeRef>>,
|
2020-07-30 08:25:46 -05:00
|
|
|
pub ast_id: FileAstId<ast::TypeAlias>,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2020-03-25 09:33:01 -05:00
|
|
|
pub struct Mod {
|
|
|
|
pub name: Name,
|
2020-06-24 08:36:18 -05:00
|
|
|
pub visibility: RawVisibilityId,
|
2020-06-15 12:16:02 -05:00
|
|
|
pub kind: ModKind,
|
|
|
|
pub ast_id: FileAstId<ast::Module>,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2020-06-12 16:24:26 -05:00
|
|
|
pub enum ModKind {
|
2020-06-15 12:16:02 -05:00
|
|
|
/// `mod m { ... }`
|
2020-06-24 09:07:02 -05:00
|
|
|
Inline { items: Box<[ModItem]> },
|
2020-06-15 12:16:02 -05:00
|
|
|
/// `mod m;`
|
2022-03-11 09:49:41 -06:00
|
|
|
Outline,
|
2020-06-12 16:24:26 -05:00
|
|
|
}
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2020-03-25 09:33:01 -05:00
|
|
|
pub struct MacroCall {
|
2020-06-15 12:16:02 -05:00
|
|
|
/// Path to the called macro.
|
2021-04-01 13:35:21 -05:00
|
|
|
pub path: Interned<ModPath>,
|
2020-12-15 08:37:37 -06:00
|
|
|
pub ast_id: FileAstId<ast::MacroCall>,
|
2021-09-05 14:30:06 -05:00
|
|
|
pub expand_to: ExpandTo,
|
2023-12-21 02:18:06 -06:00
|
|
|
// FIXME: We need to move this out. It invalidates the item tree when typing inside the macro call.
|
2023-12-20 05:53:46 -06:00
|
|
|
pub call_site: Span,
|
2020-12-15 08:37:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
|
|
|
pub struct MacroRules {
|
2020-12-15 11:43:19 -06:00
|
|
|
/// The name of the declared macro.
|
2020-12-15 08:37:37 -06:00
|
|
|
pub name: Name,
|
|
|
|
pub ast_id: FileAstId<ast::MacroRules>,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2020-12-15 11:43:19 -06:00
|
|
|
/// "Macros 2.0" macro definition.
|
|
|
|
#[derive(Debug, Clone, Eq, PartialEq)]
|
2023-12-21 02:18:06 -06:00
|
|
|
pub struct Macro2 {
|
2020-12-15 11:43:19 -06:00
|
|
|
pub name: Name,
|
|
|
|
pub visibility: RawVisibilityId,
|
|
|
|
pub ast_id: FileAstId<ast::MacroDef>,
|
|
|
|
}
|
|
|
|
|
2023-08-02 07:19:38 -05:00
|
|
|
impl Use {
|
2021-05-25 18:01:58 -05:00
|
|
|
/// Maps a `UseTree` contained in this import back to its AST node.
|
|
|
|
pub fn use_tree_to_ast(
|
|
|
|
&self,
|
|
|
|
db: &dyn DefDatabase,
|
|
|
|
file_id: HirFileId,
|
|
|
|
index: Idx<ast::UseTree>,
|
|
|
|
) -> ast::UseTree {
|
|
|
|
// Re-lower the AST item and get the source map.
|
|
|
|
// Note: The AST unwraps are fine, since if they fail we should have never obtained `index`.
|
|
|
|
let ast = InFile::new(file_id, self.ast_id).to_node(db.upcast());
|
|
|
|
let ast_use_tree = ast.use_tree().expect("missing `use_tree`");
|
2023-11-25 08:37:40 -06:00
|
|
|
let span_map = db.span_map(file_id);
|
|
|
|
let (_, source_map) = lower::lower_use_tree(db, span_map.as_ref(), ast_use_tree)
|
2023-11-24 09:38:48 -06:00
|
|
|
.expect("failed to lower use tree");
|
2021-05-25 18:01:58 -05:00
|
|
|
source_map[index].clone()
|
|
|
|
}
|
2023-08-18 04:46:35 -05:00
|
|
|
/// Maps a `UseTree` contained in this import back to its AST node.
|
|
|
|
pub fn use_tree_source_map(
|
|
|
|
&self,
|
|
|
|
db: &dyn DefDatabase,
|
|
|
|
file_id: HirFileId,
|
|
|
|
) -> Arena<ast::UseTree> {
|
|
|
|
// Re-lower the AST item and get the source map.
|
|
|
|
// Note: The AST unwraps are fine, since if they fail we should have never obtained `index`.
|
|
|
|
let ast = InFile::new(file_id, self.ast_id).to_node(db.upcast());
|
|
|
|
let ast_use_tree = ast.use_tree().expect("missing `use_tree`");
|
2023-11-25 08:37:40 -06:00
|
|
|
let span_map = db.span_map(file_id);
|
|
|
|
lower::lower_use_tree(db, span_map.as_ref(), ast_use_tree)
|
2023-11-24 09:38:48 -06:00
|
|
|
.expect("failed to lower use tree")
|
|
|
|
.1
|
2023-08-18 04:46:35 -05:00
|
|
|
}
|
2021-05-25 18:01:58 -05:00
|
|
|
}
|
|
|
|
|
2021-06-28 13:11:58 -05:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
|
|
pub enum ImportKind {
|
|
|
|
/// The `ModPath` is imported normally.
|
|
|
|
Plain,
|
|
|
|
/// This is a glob-import of all names in the `ModPath`.
|
|
|
|
Glob,
|
|
|
|
/// This is a `some::path::self` import, which imports `some::path` only in type namespace.
|
|
|
|
TypeOnly,
|
|
|
|
}
|
|
|
|
|
2021-05-25 18:01:58 -05:00
|
|
|
impl UseTree {
|
|
|
|
/// Expands the `UseTree` into individually imported `ModPath`s.
|
|
|
|
pub fn expand(
|
|
|
|
&self,
|
2021-06-28 13:11:58 -05:00
|
|
|
mut cb: impl FnMut(Idx<ast::UseTree>, ModPath, ImportKind, Option<ImportAlias>),
|
2021-05-25 18:01:58 -05:00
|
|
|
) {
|
|
|
|
self.expand_impl(None, &mut cb)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn expand_impl(
|
|
|
|
&self,
|
|
|
|
prefix: Option<ModPath>,
|
2023-08-09 13:06:08 -05:00
|
|
|
cb: &mut impl FnMut(Idx<ast::UseTree>, ModPath, ImportKind, Option<ImportAlias>),
|
2021-05-25 18:01:58 -05:00
|
|
|
) {
|
2021-06-28 13:11:58 -05:00
|
|
|
fn concat_mod_paths(
|
|
|
|
prefix: Option<ModPath>,
|
|
|
|
path: &ModPath,
|
|
|
|
) -> Option<(ModPath, ImportKind)> {
|
2021-05-25 18:01:58 -05:00
|
|
|
match (prefix, &path.kind) {
|
2021-06-28 13:11:58 -05:00
|
|
|
(None, _) => Some((path.clone(), ImportKind::Plain)),
|
2021-05-25 18:01:58 -05:00
|
|
|
(Some(mut prefix), PathKind::Plain) => {
|
|
|
|
for segment in path.segments() {
|
|
|
|
prefix.push_segment(segment.clone());
|
|
|
|
}
|
2021-06-28 13:11:58 -05:00
|
|
|
Some((prefix, ImportKind::Plain))
|
2021-05-25 18:01:58 -05:00
|
|
|
}
|
2022-01-11 08:30:39 -06:00
|
|
|
(Some(mut prefix), PathKind::Super(n))
|
|
|
|
if *n > 0 && prefix.segments().is_empty() =>
|
|
|
|
{
|
|
|
|
// `super::super` + `super::rest`
|
|
|
|
match &mut prefix.kind {
|
|
|
|
PathKind::Super(m) => {
|
|
|
|
cov_mark::hit!(concat_super_mod_paths);
|
|
|
|
*m += *n;
|
|
|
|
for segment in path.segments() {
|
|
|
|
prefix.push_segment(segment.clone());
|
|
|
|
}
|
|
|
|
Some((prefix, ImportKind::Plain))
|
|
|
|
}
|
|
|
|
_ => None,
|
2021-05-25 18:01:58 -05:00
|
|
|
}
|
|
|
|
}
|
2022-01-11 08:30:39 -06:00
|
|
|
(Some(prefix), PathKind::Super(0)) if path.segments().is_empty() => {
|
|
|
|
// `some::path::self` == `some::path`
|
|
|
|
Some((prefix, ImportKind::TypeOnly))
|
|
|
|
}
|
2021-05-25 18:01:58 -05:00
|
|
|
(Some(_), _) => None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
match &self.kind {
|
|
|
|
UseTreeKind::Single { path, alias } => {
|
2021-06-28 13:11:58 -05:00
|
|
|
if let Some((path, kind)) = concat_mod_paths(prefix, path) {
|
|
|
|
cb(self.index, path, kind, alias.clone());
|
2021-05-25 18:01:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
UseTreeKind::Glob { path: Some(path) } => {
|
2021-06-28 13:11:58 -05:00
|
|
|
if let Some((path, _)) = concat_mod_paths(prefix, path) {
|
|
|
|
cb(self.index, path, ImportKind::Glob, None);
|
2021-05-25 18:01:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
UseTreeKind::Glob { path: None } => {
|
|
|
|
if let Some(prefix) = prefix {
|
2021-06-28 13:11:58 -05:00
|
|
|
cb(self.index, prefix, ImportKind::Glob, None);
|
2021-05-25 18:01:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
UseTreeKind::Prefixed { prefix: additional_prefix, list } => {
|
|
|
|
let prefix = match additional_prefix {
|
|
|
|
Some(path) => match concat_mod_paths(prefix, path) {
|
2021-06-28 13:11:58 -05:00
|
|
|
Some((path, ImportKind::Plain)) => Some(path),
|
|
|
|
_ => return,
|
2021-05-25 18:01:58 -05:00
|
|
|
},
|
|
|
|
None => prefix,
|
|
|
|
};
|
2021-05-25 18:26:16 -05:00
|
|
|
for tree in &**list {
|
2021-05-25 18:01:58 -05:00
|
|
|
tree.expand_impl(prefix.clone(), cb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-11 12:46:56 -05:00
|
|
|
macro_rules! impl_froms {
|
|
|
|
($e:ident { $($v:ident ($t:ty)),* $(,)? }) => {
|
|
|
|
$(
|
|
|
|
impl From<$t> for $e {
|
|
|
|
fn from(it: $t) -> $e {
|
|
|
|
$e::$v(it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)*
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-17 11:43:41 -05:00
|
|
|
impl ModItem {
|
|
|
|
pub fn as_assoc_item(&self) -> Option<AssocItem> {
|
|
|
|
match self {
|
2023-08-02 07:19:38 -05:00
|
|
|
ModItem::Use(_)
|
2020-06-22 08:07:06 -05:00
|
|
|
| ModItem::ExternCrate(_)
|
2021-05-21 11:27:25 -05:00
|
|
|
| ModItem::ExternBlock(_)
|
2020-06-17 11:43:41 -05:00
|
|
|
| ModItem::Struct(_)
|
|
|
|
| ModItem::Union(_)
|
|
|
|
| ModItem::Enum(_)
|
|
|
|
| ModItem::Static(_)
|
|
|
|
| ModItem::Trait(_)
|
2023-03-03 09:24:07 -06:00
|
|
|
| ModItem::TraitAlias(_)
|
2020-06-17 11:43:41 -05:00
|
|
|
| ModItem::Impl(_)
|
2020-12-15 08:37:37 -06:00
|
|
|
| ModItem::Mod(_)
|
2020-12-15 11:43:19 -06:00
|
|
|
| ModItem::MacroRules(_)
|
2023-12-21 02:18:06 -06:00
|
|
|
| ModItem::Macro2(_) => None,
|
2020-06-17 11:43:41 -05:00
|
|
|
ModItem::MacroCall(call) => Some(AssocItem::MacroCall(*call)),
|
|
|
|
ModItem::Const(konst) => Some(AssocItem::Const(*konst)),
|
|
|
|
ModItem::TypeAlias(alias) => Some(AssocItem::TypeAlias(*alias)),
|
|
|
|
ModItem::Function(func) => Some(AssocItem::Function(*func)),
|
|
|
|
}
|
|
|
|
}
|
2020-06-22 08:07:06 -05:00
|
|
|
|
2020-10-20 10:49:21 -05:00
|
|
|
pub fn ast_id(&self, tree: &ItemTree) -> FileAstId<ast::Item> {
|
|
|
|
match self {
|
2023-11-16 11:39:36 -06:00
|
|
|
ModItem::Use(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::ExternCrate(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::ExternBlock(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::Function(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::Struct(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::Union(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::Enum(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::Const(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::Static(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::Trait(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::TraitAlias(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::Impl(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::TypeAlias(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::Mod(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::MacroCall(it) => tree[it.index()].ast_id().upcast(),
|
|
|
|
ModItem::MacroRules(it) => tree[it.index()].ast_id().upcast(),
|
2023-12-21 02:18:06 -06:00
|
|
|
ModItem::Macro2(it) => tree[it.index()].ast_id().upcast(),
|
2020-10-20 10:49:21 -05:00
|
|
|
}
|
|
|
|
}
|
2020-06-17 11:43:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
2020-03-25 09:33:01 -05:00
|
|
|
pub enum AssocItem {
|
2020-06-16 12:20:29 -05:00
|
|
|
Function(FileItemTreeId<Function>),
|
|
|
|
TypeAlias(FileItemTreeId<TypeAlias>),
|
|
|
|
Const(FileItemTreeId<Const>),
|
|
|
|
MacroCall(FileItemTreeId<MacroCall>),
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
2020-06-11 12:46:56 -05:00
|
|
|
impl_froms!(AssocItem {
|
2020-06-16 12:20:29 -05:00
|
|
|
Function(FileItemTreeId<Function>),
|
|
|
|
TypeAlias(FileItemTreeId<TypeAlias>),
|
|
|
|
Const(FileItemTreeId<Const>),
|
|
|
|
MacroCall(FileItemTreeId<MacroCall>),
|
2020-06-11 12:46:56 -05:00
|
|
|
});
|
|
|
|
|
2020-06-22 08:07:06 -05:00
|
|
|
impl From<AssocItem> for ModItem {
|
|
|
|
fn from(item: AssocItem) -> Self {
|
|
|
|
match item {
|
|
|
|
AssocItem::Function(it) => it.into(),
|
|
|
|
AssocItem::TypeAlias(it) => it.into(),
|
|
|
|
AssocItem::Const(it) => it.into(),
|
|
|
|
AssocItem::MacroCall(it) => it.into(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-06 05:30:16 -06:00
|
|
|
impl AssocItem {
|
|
|
|
pub fn ast_id(self, tree: &ItemTree) -> FileAstId<ast::AssocItem> {
|
|
|
|
match self {
|
|
|
|
AssocItem::Function(id) => tree[id].ast_id.upcast(),
|
|
|
|
AssocItem::TypeAlias(id) => tree[id].ast_id.upcast(),
|
|
|
|
AssocItem::Const(id) => tree[id].ast_id.upcast(),
|
|
|
|
AssocItem::MacroCall(id) => tree[id].ast_id.upcast(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-02-10 04:37:59 -06:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
2020-03-25 09:33:01 -05:00
|
|
|
pub struct Variant {
|
|
|
|
pub name: Name,
|
|
|
|
pub fields: Fields,
|
2022-09-04 12:28:04 -05:00
|
|
|
pub ast_id: FileAstId<ast::Variant>,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
pub enum Fields {
|
2021-10-04 22:10:25 -05:00
|
|
|
Record(IdxRange<Field>),
|
|
|
|
Tuple(IdxRange<Field>),
|
2020-03-25 09:33:01 -05:00
|
|
|
Unit,
|
|
|
|
}
|
|
|
|
|
2022-09-04 12:28:04 -05:00
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
pub enum FieldAstId {
|
|
|
|
Record(FileAstId<ast::RecordField>),
|
|
|
|
Tuple(FileAstId<ast::TupleField>),
|
|
|
|
}
|
|
|
|
|
2020-03-25 09:33:01 -05:00
|
|
|
/// A single field of an enum variant or struct
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
|
|
pub struct Field {
|
|
|
|
pub name: Name,
|
2021-04-01 12:46:43 -05:00
|
|
|
pub type_ref: Interned<TypeRef>,
|
2020-06-24 08:36:18 -05:00
|
|
|
pub visibility: RawVisibilityId,
|
2022-09-04 12:28:04 -05:00
|
|
|
pub ast_id: FieldAstId,
|
2020-03-25 09:33:01 -05:00
|
|
|
}
|