Skip to content

Commit 9da454b

Browse files
bors[bot]matklad
andauthored
Merge #5578
5578: Rename ModuleItem -> Item r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
2 parents 4567ae5 + ede5d17 commit 9da454b

File tree

19 files changed

+491
-495
lines changed

19 files changed

+491
-495
lines changed

crates/ra_hir_def/src/body/lower.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -627,53 +627,53 @@ impl ExprCollector<'_> {
627627
.items()
628628
.filter_map(|item| {
629629
let (def, name): (ModuleDefId, Option<ast::Name>) = match item {
630-
ast::ModuleItem::FnDef(def) => {
630+
ast::Item::FnDef(def) => {
631631
let id = self.find_inner_item(&def)?;
632632
(
633633
FunctionLoc { container: container.into(), id }.intern(self.db).into(),
634634
def.name(),
635635
)
636636
}
637-
ast::ModuleItem::TypeAliasDef(def) => {
637+
ast::Item::TypeAliasDef(def) => {
638638
let id = self.find_inner_item(&def)?;
639639
(
640640
TypeAliasLoc { container: container.into(), id }.intern(self.db).into(),
641641
def.name(),
642642
)
643643
}
644-
ast::ModuleItem::ConstDef(def) => {
644+
ast::Item::ConstDef(def) => {
645645
let id = self.find_inner_item(&def)?;
646646
(
647647
ConstLoc { container: container.into(), id }.intern(self.db).into(),
648648
def.name(),
649649
)
650650
}
651-
ast::ModuleItem::StaticDef(def) => {
651+
ast::Item::StaticDef(def) => {
652652
let id = self.find_inner_item(&def)?;
653653
(StaticLoc { container, id }.intern(self.db).into(), def.name())
654654
}
655-
ast::ModuleItem::StructDef(def) => {
655+
ast::Item::StructDef(def) => {
656656
let id = self.find_inner_item(&def)?;
657657
(StructLoc { container, id }.intern(self.db).into(), def.name())
658658
}
659-
ast::ModuleItem::EnumDef(def) => {
659+
ast::Item::EnumDef(def) => {
660660
let id = self.find_inner_item(&def)?;
661661
(EnumLoc { container, id }.intern(self.db).into(), def.name())
662662
}
663-
ast::ModuleItem::UnionDef(def) => {
663+
ast::Item::UnionDef(def) => {
664664
let id = self.find_inner_item(&def)?;
665665
(UnionLoc { container, id }.intern(self.db).into(), def.name())
666666
}
667-
ast::ModuleItem::TraitDef(def) => {
667+
ast::Item::TraitDef(def) => {
668668
let id = self.find_inner_item(&def)?;
669669
(TraitLoc { container, id }.intern(self.db).into(), def.name())
670670
}
671-
ast::ModuleItem::ExternBlock(_) => return None, // FIXME: collect from extern blocks
672-
ast::ModuleItem::ImplDef(_)
673-
| ast::ModuleItem::UseItem(_)
674-
| ast::ModuleItem::ExternCrateItem(_)
675-
| ast::ModuleItem::Module(_)
676-
| ast::ModuleItem::MacroCall(_) => return None,
671+
ast::Item::ExternBlock(_) => return None, // FIXME: collect from extern blocks
672+
ast::Item::ImplDef(_)
673+
| ast::Item::UseItem(_)
674+
| ast::Item::ExternCrateItem(_)
675+
| ast::Item::Module(_)
676+
| ast::Item::MacroCall(_) => return None,
677677
};
678678

679679
Some((def, name))

crates/ra_hir_def/src/item_tree.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl GenericParamsId {
7070
pub struct ItemTree {
7171
top_level: SmallVec<[ModItem; 1]>,
7272
attrs: FxHashMap<AttrOwner, Attrs>,
73-
inner_items: FxHashMap<FileAstId<ast::ModuleItem>, SmallVec<[ModItem; 1]>>,
73+
inner_items: FxHashMap<FileAstId<ast::Item>, SmallVec<[ModItem; 1]>>,
7474

7575
data: Option<Box<ItemTreeData>>,
7676
}
@@ -187,7 +187,7 @@ impl ItemTree {
187187
///
188188
/// Most AST items are lowered to a single `ModItem`, but some (eg. `use` items) may be lowered
189189
/// to multiple items in the `ItemTree`.
190-
pub fn inner_items(&self, ast: FileAstId<ast::ModuleItem>) -> &[ModItem] {
190+
pub fn inner_items(&self, ast: FileAstId<ast::Item>) -> &[ModItem] {
191191
&self.inner_items[&ast]
192192
}
193193

@@ -310,7 +310,7 @@ from_attrs!(ModItem(ModItem), Variant(Idx<Variant>), Field(Idx<Field>));
310310

311311
/// Trait implemented by all item nodes in the item tree.
312312
pub trait ItemTreeNode: Clone {
313-
type Source: AstNode + Into<ast::ModuleItem>;
313+
type Source: AstNode + Into<ast::Item>;
314314

315315
fn ast_id(&self) -> FileAstId<Self::Source>;
316316

crates/ra_hir_def/src/item_tree/lower.rs

Lines changed: 34 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@ impl Ctx {
7070
self.tree.data_mut()
7171
}
7272

73-
fn lower_mod_item(&mut self, item: &ast::ModuleItem, inner: bool) -> Option<ModItems> {
73+
fn lower_mod_item(&mut self, item: &ast::Item, inner: bool) -> Option<ModItems> {
7474
assert!(inner || self.inner_items.is_empty());
7575

7676
// Collect inner items for 1-to-1-lowered items.
7777
match item {
78-
ast::ModuleItem::StructDef(_)
79-
| ast::ModuleItem::UnionDef(_)
80-
| ast::ModuleItem::EnumDef(_)
81-
| ast::ModuleItem::FnDef(_)
82-
| ast::ModuleItem::TypeAliasDef(_)
83-
| ast::ModuleItem::ConstDef(_)
84-
| ast::ModuleItem::StaticDef(_)
85-
| ast::ModuleItem::MacroCall(_) => {
78+
ast::Item::StructDef(_)
79+
| ast::Item::UnionDef(_)
80+
| ast::Item::EnumDef(_)
81+
| ast::Item::FnDef(_)
82+
| ast::Item::TypeAliasDef(_)
83+
| ast::Item::ConstDef(_)
84+
| ast::Item::StaticDef(_)
85+
| ast::Item::MacroCall(_) => {
8686
// Skip this if we're already collecting inner items. We'll descend into all nodes
8787
// already.
8888
if !inner {
@@ -92,34 +92,30 @@ impl Ctx {
9292

9393
// These are handled in their respective `lower_X` method (since we can't just blindly
9494
// walk them).
95-
ast::ModuleItem::TraitDef(_)
96-
| ast::ModuleItem::ImplDef(_)
97-
| ast::ModuleItem::ExternBlock(_) => {}
95+
ast::Item::TraitDef(_) | ast::Item::ImplDef(_) | ast::Item::ExternBlock(_) => {}
9896

9997
// These don't have inner items.
100-
ast::ModuleItem::Module(_)
101-
| ast::ModuleItem::ExternCrateItem(_)
102-
| ast::ModuleItem::UseItem(_) => {}
98+
ast::Item::Module(_) | ast::Item::ExternCrateItem(_) | ast::Item::UseItem(_) => {}
10399
};
104100

105101
let attrs = Attrs::new(item, &self.hygiene);
106102
let items = match item {
107-
ast::ModuleItem::StructDef(ast) => self.lower_struct(ast).map(Into::into),
108-
ast::ModuleItem::UnionDef(ast) => self.lower_union(ast).map(Into::into),
109-
ast::ModuleItem::EnumDef(ast) => self.lower_enum(ast).map(Into::into),
110-
ast::ModuleItem::FnDef(ast) => self.lower_function(ast).map(Into::into),
111-
ast::ModuleItem::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into),
112-
ast::ModuleItem::StaticDef(ast) => self.lower_static(ast).map(Into::into),
113-
ast::ModuleItem::ConstDef(ast) => Some(self.lower_const(ast).into()),
114-
ast::ModuleItem::Module(ast) => self.lower_module(ast).map(Into::into),
115-
ast::ModuleItem::TraitDef(ast) => self.lower_trait(ast).map(Into::into),
116-
ast::ModuleItem::ImplDef(ast) => self.lower_impl(ast).map(Into::into),
117-
ast::ModuleItem::UseItem(ast) => Some(ModItems(
103+
ast::Item::StructDef(ast) => self.lower_struct(ast).map(Into::into),
104+
ast::Item::UnionDef(ast) => self.lower_union(ast).map(Into::into),
105+
ast::Item::EnumDef(ast) => self.lower_enum(ast).map(Into::into),
106+
ast::Item::FnDef(ast) => self.lower_function(ast).map(Into::into),
107+
ast::Item::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into),
108+
ast::Item::StaticDef(ast) => self.lower_static(ast).map(Into::into),
109+
ast::Item::ConstDef(ast) => Some(self.lower_const(ast).into()),
110+
ast::Item::Module(ast) => self.lower_module(ast).map(Into::into),
111+
ast::Item::TraitDef(ast) => self.lower_trait(ast).map(Into::into),
112+
ast::Item::ImplDef(ast) => self.lower_impl(ast).map(Into::into),
113+
ast::Item::UseItem(ast) => Some(ModItems(
118114
self.lower_use(ast).into_iter().map(Into::into).collect::<SmallVec<_>>(),
119115
)),
120-
ast::ModuleItem::ExternCrateItem(ast) => self.lower_extern_crate(ast).map(Into::into),
121-
ast::ModuleItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
122-
ast::ModuleItem::ExternBlock(ast) => {
116+
ast::Item::ExternCrateItem(ast) => self.lower_extern_crate(ast).map(Into::into),
117+
ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
118+
ast::Item::ExternBlock(ast) => {
123119
Some(ModItems(self.lower_extern_block(ast).into_iter().collect::<SmallVec<_>>()))
124120
}
125121
};
@@ -147,22 +143,22 @@ impl Ctx {
147143
fn collect_inner_items(&mut self, container: &SyntaxNode) {
148144
let forced_vis = self.forced_visibility.take();
149145
let mut inner_items = mem::take(&mut self.tree.inner_items);
150-
inner_items.extend(
151-
container.descendants().skip(1).filter_map(ast::ModuleItem::cast).filter_map(|item| {
146+
inner_items.extend(container.descendants().skip(1).filter_map(ast::Item::cast).filter_map(
147+
|item| {
152148
let ast_id = self.source_ast_id_map.ast_id(&item);
153149
Some((ast_id, self.lower_mod_item(&item, true)?.0))
154-
}),
155-
);
150+
},
151+
));
156152
self.tree.inner_items = inner_items;
157153
self.forced_visibility = forced_vis;
158154
}
159155

160-
fn lower_assoc_item(&mut self, item: &ast::ModuleItem) -> Option<AssocItem> {
156+
fn lower_assoc_item(&mut self, item: &ast::Item) -> Option<AssocItem> {
161157
match item {
162-
ast::ModuleItem::FnDef(ast) => self.lower_function(ast).map(Into::into),
163-
ast::ModuleItem::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into),
164-
ast::ModuleItem::ConstDef(ast) => Some(self.lower_const(ast).into()),
165-
ast::ModuleItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
158+
ast::Item::FnDef(ast) => self.lower_function(ast).map(Into::into),
159+
ast::Item::TypeAliasDef(ast) => self.lower_type_alias(ast).map(Into::into),
160+
ast::Item::ConstDef(ast) => Some(self.lower_const(ast).into()),
161+
ast::Item::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
166162
_ => None,
167163
}
168164
}

crates/ra_hir_def/src/item_tree/tests.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ fn test_inner_items(ra_fixture: &str) {
2121
let mut outer_items = FxHashSet::default();
2222
let mut worklist = tree.top_level_items().to_vec();
2323
while let Some(item) = worklist.pop() {
24-
let node: ast::ModuleItem = match item {
24+
let node: ast::Item = match item {
2525
ModItem::Import(it) => tree.source(&db, InFile::new(file_id, it)).into(),
2626
ModItem::ExternCrate(it) => tree.source(&db, InFile::new(file_id, it)).into(),
2727
ModItem::Function(it) => tree.source(&db, InFile::new(file_id, it)).into(),
@@ -53,7 +53,7 @@ fn test_inner_items(ra_fixture: &str) {
5353

5454
// Now descend the root node and check that all `ast::ModuleItem`s are either recorded above, or
5555
// registered as inner items.
56-
for item in root.descendants().skip(1).filter_map(ast::ModuleItem::cast) {
56+
for item in root.descendants().skip(1).filter_map(ast::Item::cast) {
5757
if outer_items.contains(&item) {
5858
continue;
5959
}
@@ -279,7 +279,7 @@ fn simple_inner_items() {
279279
280280
inner items:
281281
282-
for AST FileAstId::<ra_syntax::ast::generated::nodes::ModuleItem>(2):
282+
for AST FileAstId::<ra_syntax::ast::generated::nodes::Item>(2):
283283
Function { name: Name(Text("end")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(1), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(2) }
284284
285285
"#]],
@@ -412,7 +412,7 @@ fn inner_item_attrs() {
412412
413413
inner items:
414414
415-
for AST FileAstId::<ra_syntax::ast::generated::nodes::ModuleItem>(1):
415+
for AST FileAstId::<ra_syntax::ast::generated::nodes::Item>(1):
416416
#[Attrs { entries: Some([Attr { path: ModPath { kind: Plain, segments: [Name(Text("on_inner"))] }, input: None }]) }]
417417
Function { name: Name(Text("inner")), visibility: RawVisibilityId("pub(self)"), generic_params: GenericParamsId(4294967295), has_self_param: false, is_unsafe: false, params: [], is_varargs: false, ret_type: Tuple([]), ast_id: FileAstId::<ra_syntax::ast::generated::nodes::FnDef>(1) }
418418

crates/ra_hir_def/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ impl AsMacroCall for AstIdWithPath<ast::MacroCall> {
521521
}
522522
}
523523

524-
impl AsMacroCall for AstIdWithPath<ast::ModuleItem> {
524+
impl AsMacroCall for AstIdWithPath<ast::Item> {
525525
fn as_call_id(
526526
&self,
527527
db: &dyn db::DefDatabase,

crates/ra_hir_def/src/nameres/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ struct MacroDirective {
170170
#[derive(Clone, Debug, Eq, PartialEq)]
171171
struct DeriveDirective {
172172
module_id: LocalModuleId,
173-
ast_id: AstIdWithPath<ast::ModuleItem>,
173+
ast_id: AstIdWithPath<ast::Item>,
174174
}
175175

176176
struct DefData<'a> {
@@ -1100,7 +1100,7 @@ impl ModCollector<'_, '_> {
11001100
res
11011101
}
11021102

1103-
fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId<ast::ModuleItem>) {
1103+
fn collect_derives(&mut self, attrs: &Attrs, ast_id: FileAstId<ast::Item>) {
11041104
for derive_subtree in attrs.by_key("derive").tt_values() {
11051105
// for #[derive(Copy, Clone)], `derive_subtree` is the `(Copy, Clone)` subtree
11061106
for tt in &derive_subtree.token_trees {

crates/ra_hir_expand/src/ast_id_map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl AstIdMap {
7373
// change parent's id. This means that, say, adding a new function to a
7474
// trait does not change ids of top-level items, which helps caching.
7575
bfs(node, |it| {
76-
if let Some(module_item) = ast::ModuleItem::cast(it) {
76+
if let Some(module_item) = ast::Item::cast(it) {
7777
res.alloc(module_item.syntax());
7878
}
7979
});

crates/ra_hir_expand/src/builtin_derive.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ mod tests {
276276
let file_id = file_pos.file_id;
277277
let parsed = db.parse(file_id);
278278
let items: Vec<_> =
279-
parsed.syntax_node().descendants().filter_map(ast::ModuleItem::cast).collect();
279+
parsed.syntax_node().descendants().filter_map(ast::Item::cast).collect();
280280

281281
let ast_id_map = db.ast_id_map(file_id.into());
282282

crates/ra_hir_expand/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl HirFileId {
159159
}
160160

161161
/// Indicate it is macro file generated for builtin derive
162-
pub fn is_builtin_derive(&self, db: &dyn db::AstDatabase) -> Option<InFile<ast::ModuleItem>> {
162+
pub fn is_builtin_derive(&self, db: &dyn db::AstDatabase) -> Option<InFile<ast::Item>> {
163163
match self.0 {
164164
HirFileIdRepr::FileId(_) => None,
165165
HirFileIdRepr::MacroFile(macro_file) => {
@@ -174,7 +174,7 @@ impl HirFileId {
174174
MacroDefKind::BuiltInDerive(_) => loc.kind.node(db),
175175
_ => return None,
176176
};
177-
Some(item.with_value(ast::ModuleItem::cast(item.value.clone())?))
177+
Some(item.with_value(ast::Item::cast(item.value.clone())?))
178178
}
179179
}
180180
}
@@ -258,7 +258,7 @@ pub struct MacroCallLoc {
258258
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
259259
pub enum MacroCallKind {
260260
FnLike(AstId<ast::MacroCall>),
261-
Attr(AstId<ast::ModuleItem>, String),
261+
Attr(AstId<ast::Item>, String),
262262
}
263263

264264
impl MacroCallKind {

crates/ra_ide/src/completion/complete_fn_param.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(super) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
2828
}
2929
};
3030
for item in items {
31-
if let ast::ModuleItem::FnDef(func) = item {
31+
if let ast::Item::FnDef(func) = item {
3232
if Some(&func) == me.as_ref() {
3333
continue;
3434
}

0 commit comments

Comments
 (0)