Skip to content

Commit f86f6a8

Browse files
committed
Change terminology, do not name use items and use trees as imports
1 parent 12cb6e7 commit f86f6a8

File tree

7 files changed

+37
-39
lines changed

7 files changed

+37
-39
lines changed

crates/hir-def/src/db.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ use crate::{
2323
visibility::{self, Visibility},
2424
AttrDefId, BlockId, BlockLoc, ConstBlockId, ConstBlockLoc, ConstId, ConstLoc, DefWithBodyId,
2525
EnumId, EnumLoc, ExternBlockId, ExternBlockLoc, ExternCrateId, ExternCrateLoc, FunctionId,
26-
FunctionLoc, GenericDefId, ImplId, ImplLoc, ImportId, ImportLoc, InTypeConstId, InTypeConstLoc,
27-
LocalEnumVariantId, LocalFieldId, Macro2Id, Macro2Loc, MacroRulesId, MacroRulesLoc,
28-
ProcMacroId, ProcMacroLoc, StaticId, StaticLoc, StructId, StructLoc, TraitAliasId,
29-
TraitAliasLoc, TraitId, TraitLoc, TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, VariantId,
26+
FunctionLoc, GenericDefId, ImplId, ImplLoc, InTypeConstId, InTypeConstLoc, LocalEnumVariantId,
27+
LocalFieldId, Macro2Id, Macro2Loc, MacroRulesId, MacroRulesLoc, ProcMacroId, ProcMacroLoc,
28+
StaticId, StaticLoc, StructId, StructLoc, TraitAliasId, TraitAliasLoc, TraitId, TraitLoc,
29+
TypeAliasId, TypeAliasLoc, UnionId, UnionLoc, UseId, UseLoc, VariantId,
3030
};
3131

3232
#[salsa::query_group(InternDatabaseStorage)]
3333
pub trait InternDatabase: SourceDatabase {
3434
// region: items
3535
#[salsa::interned]
36-
fn intern_import(&self, loc: ImportLoc) -> ImportId;
36+
fn intern_use(&self, loc: UseLoc) -> UseId;
3737
#[salsa::interned]
3838
fn intern_extern_crate(&self, loc: ExternCrateLoc) -> ExternCrateId;
3939
#[salsa::interned]

crates/hir-def/src/item_tree.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ impl ItemTree {
188188
fn shrink_to_fit(&mut self) {
189189
if let Some(data) = &mut self.data {
190190
let ItemTreeData {
191-
imports,
191+
uses,
192192
extern_crates,
193193
extern_blocks,
194194
functions,
@@ -211,7 +211,7 @@ impl ItemTree {
211211
vis,
212212
} = &mut **data;
213213

214-
imports.shrink_to_fit();
214+
uses.shrink_to_fit();
215215
extern_crates.shrink_to_fit();
216216
extern_blocks.shrink_to_fit();
217217
functions.shrink_to_fit();
@@ -262,7 +262,7 @@ static VIS_PUB_CRATE: RawVisibility = RawVisibility::Module(ModPath::from_kind(P
262262

263263
#[derive(Default, Debug, Eq, PartialEq)]
264264
struct ItemTreeData {
265-
imports: Arena<Import>,
265+
uses: Arena<Use>,
266266
extern_crates: Arena<ExternCrate>,
267267
extern_blocks: Arena<ExternBlock>,
268268
functions: Arena<Function>,
@@ -486,7 +486,7 @@ macro_rules! mod_items {
486486
}
487487

488488
mod_items! {
489-
Import in imports -> ast::Use,
489+
Use in uses -> ast::Use,
490490
ExternCrate in extern_crates -> ast::ExternCrate,
491491
ExternBlock in extern_blocks -> ast::ExternBlock,
492492
Function in functions -> ast::Fn,
@@ -541,7 +541,7 @@ impl<N: ItemTreeNode> Index<FileItemTreeId<N>> for ItemTree {
541541
}
542542

543543
#[derive(Debug, Clone, Eq, PartialEq)]
544-
pub struct Import {
544+
pub struct Use {
545545
pub visibility: RawVisibilityId,
546546
pub ast_id: FileAstId<ast::Use>,
547547
pub use_tree: UseTree,
@@ -744,7 +744,7 @@ pub struct MacroDef {
744744
pub ast_id: FileAstId<ast::MacroDef>,
745745
}
746746

747-
impl Import {
747+
impl Use {
748748
/// Maps a `UseTree` contained in this import back to its AST node.
749749
pub fn use_tree_to_ast(
750750
&self,
@@ -870,7 +870,7 @@ macro_rules! impl_froms {
870870
impl ModItem {
871871
pub fn as_assoc_item(&self) -> Option<AssocItem> {
872872
match self {
873-
ModItem::Import(_)
873+
ModItem::Use(_)
874874
| ModItem::ExternCrate(_)
875875
| ModItem::ExternBlock(_)
876876
| ModItem::Struct(_)
@@ -892,7 +892,7 @@ impl ModItem {
892892

893893
pub fn ast_id(&self, tree: &ItemTree) -> FileAstId<ast::Item> {
894894
match self {
895-
ModItem::Import(it) => tree[it.index].ast_id().upcast(),
895+
ModItem::Use(it) => tree[it.index].ast_id().upcast(),
896896
ModItem::ExternCrate(it) => tree[it.index].ast_id().upcast(),
897897
ModItem::ExternBlock(it) => tree[it.index].ast_id().upcast(),
898898
ModItem::Function(it) => tree[it.index].ast_id().upcast(),

crates/hir-def/src/item_tree/lower.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -502,13 +502,13 @@ impl<'a> Ctx<'a> {
502502
Some(id(self.data().impls.alloc(res)))
503503
}
504504

505-
fn lower_use(&mut self, use_item: &ast::Use) -> Option<FileItemTreeId<Import>> {
505+
fn lower_use(&mut self, use_item: &ast::Use) -> Option<FileItemTreeId<Use>> {
506506
let visibility = self.lower_visibility(use_item);
507507
let ast_id = self.source_ast_id_map.ast_id(use_item);
508508
let (use_tree, _) = lower_use_tree(self.db, self.hygiene(), use_item.use_tree()?)?;
509509

510-
let res = Import { visibility, ast_id, use_tree };
511-
Some(id(self.data().imports.alloc(res)))
510+
let res = Use { visibility, ast_id, use_tree };
511+
Some(id(self.data().uses.alloc(res)))
512512
}
513513

514514
fn lower_extern_crate(

crates/hir-def/src/item_tree/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,8 @@ impl Printer<'_> {
198198
self.print_attrs_of(item);
199199

200200
match item {
201-
ModItem::Import(it) => {
202-
let Import { visibility, use_tree, ast_id: _ } = &self.tree[it];
201+
ModItem::Use(it) => {
202+
let Use { visibility, use_tree, ast_id: _ } = &self.tree[it];
203203
self.print_visibility(*visibility);
204204
w!(self, "use ");
205205
self.print_use_tree(use_tree);

crates/hir-def/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ use crate::{
8888
builtin_type::BuiltinType,
8989
data::adt::VariantData,
9090
item_tree::{
91-
Const, Enum, ExternCrate, Function, Impl, Import, ItemTreeId, ItemTreeNode, MacroDef,
92-
MacroRules, Static, Struct, Trait, TraitAlias, TypeAlias, Union,
91+
Const, Enum, ExternCrate, Function, Impl, ItemTreeId, ItemTreeNode, MacroDef, MacroRules,
92+
Static, Struct, Trait, TraitAlias, TypeAlias, Union, Use,
9393
},
9494
};
9595

@@ -324,9 +324,9 @@ type ImplLoc = ItemLoc<Impl>;
324324
impl_intern!(ImplId, ImplLoc, intern_impl, lookup_intern_impl);
325325

326326
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
327-
pub struct ImportId(salsa::InternId);
328-
type ImportLoc = ItemLoc<Import>;
329-
impl_intern!(ImportId, ImportLoc, intern_import, lookup_intern_import);
327+
pub struct UseId(salsa::InternId);
328+
type UseLoc = ItemLoc<Use>;
329+
impl_intern!(UseId, UseLoc, intern_use, lookup_intern_use);
330330

331331
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Ord, PartialOrd)]
332332
pub struct ExternCrateId(salsa::InternId);

crates/hir-def/src/nameres/collector.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ use crate::{
5252
tt,
5353
visibility::{RawVisibility, Visibility},
5454
AdtId, AstId, AstIdWithPath, ConstLoc, CrateRootModuleId, EnumLoc, EnumVariantId,
55-
ExternBlockLoc, ExternCrateLoc, FunctionId, FunctionLoc, ImplLoc, ImportLoc, Intern,
56-
ItemContainerId, LocalModuleId, Macro2Id, Macro2Loc, MacroExpander, MacroId, MacroRulesId,
57-
MacroRulesLoc, ModuleDefId, ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc, StructLoc,
58-
TraitAliasLoc, TraitLoc, TypeAliasLoc, UnionLoc, UnresolvedMacro,
55+
ExternBlockLoc, ExternCrateLoc, FunctionId, FunctionLoc, ImplLoc, Intern, ItemContainerId,
56+
LocalModuleId, Macro2Id, Macro2Loc, MacroExpander, MacroId, MacroRulesId, MacroRulesLoc,
57+
ModuleDefId, ModuleId, ProcMacroId, ProcMacroLoc, StaticLoc, StructLoc, TraitAliasLoc,
58+
TraitLoc, TypeAliasLoc, UnionLoc, UnresolvedMacro, UseLoc,
5959
};
6060

6161
static GLOB_RECURSION_LIMIT: Limit = Limit::new(100);
@@ -146,7 +146,7 @@ impl PartialResolvedImport {
146146

147147
#[derive(Clone, Debug, Eq, PartialEq)]
148148
enum ImportSource {
149-
Import { id: ItemTreeId<item_tree::Import>, use_tree: Idx<ast::UseTree> },
149+
Use { id: ItemTreeId<item_tree::Use>, use_tree: Idx<ast::UseTree> },
150150
ExternCrate(ItemTreeId<item_tree::ExternCrate>),
151151
}
152152

@@ -166,7 +166,7 @@ impl Import {
166166
db: &dyn DefDatabase,
167167
krate: CrateId,
168168
tree: &ItemTree,
169-
id: ItemTreeId<item_tree::Import>,
169+
id: ItemTreeId<item_tree::Use>,
170170
mut cb: impl FnMut(Self),
171171
) {
172172
let it = &tree[id.value];
@@ -181,7 +181,7 @@ impl Import {
181181
kind,
182182
is_prelude,
183183
is_macro_use: false,
184-
source: ImportSource::Import { id, use_tree: idx },
184+
source: ImportSource::Use { id, use_tree: idx },
185185
});
186186
});
187187
}
@@ -1474,7 +1474,7 @@ impl DefCollector<'_> {
14741474
}
14751475

14761476
for directive in &self.unresolved_imports {
1477-
if let ImportSource::Import { id: import, use_tree } = directive.import.source {
1477+
if let ImportSource::Use { id: import, use_tree } = directive.import.source {
14781478
if matches!(
14791479
(directive.import.path.segments().first(), &directive.import.path.kind),
14801480
(Some(krate), PathKind::Plain | PathKind::Abs) if diagnosed_extern_crates.contains(krate)
@@ -1576,12 +1576,10 @@ impl ModCollector<'_, '_> {
15761576

15771577
match item {
15781578
ModItem::Mod(m) => self.collect_module(m, &attrs),
1579-
ModItem::Import(import_id) => {
1580-
let _import_id = ImportLoc {
1581-
container: module,
1582-
id: ItemTreeId::new(self.tree_id, import_id),
1583-
}
1584-
.intern(db);
1579+
ModItem::Use(import_id) => {
1580+
let _import_id =
1581+
UseLoc { container: module, id: ItemTreeId::new(self.tree_id, import_id) }
1582+
.intern(db);
15851583
Import::from_use(
15861584
db,
15871585
krate,

crates/hir-def/src/nameres/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub enum DefDiagnosticKind {
1919

2020
UnresolvedExternCrate { ast: AstId<ast::ExternCrate> },
2121

22-
UnresolvedImport { id: ItemTreeId<item_tree::Import>, index: Idx<ast::UseTree> },
22+
UnresolvedImport { id: ItemTreeId<item_tree::Use>, index: Idx<ast::UseTree> },
2323

2424
UnconfiguredCode { ast: ErasedAstId, cfg: CfgExpr, opts: CfgOptions },
2525

@@ -70,7 +70,7 @@ impl DefDiagnostic {
7070

7171
pub(super) fn unresolved_import(
7272
container: LocalModuleId,
73-
id: ItemTreeId<item_tree::Import>,
73+
id: ItemTreeId<item_tree::Use>,
7474
index: Idx<ast::UseTree>,
7575
) -> Self {
7676
Self { in_module: container, kind: DefDiagnosticKind::UnresolvedImport { id, index } }

0 commit comments

Comments
 (0)