Skip to content

Commit 62e1906

Browse files
committed
Collapse visit_mod methods
1 parent c0adce9 commit 62e1906

File tree

1 file changed

+9
-44
lines changed

1 file changed

+9
-44
lines changed

src/modules.rs

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
142142

143143
// Skip visiting sub modules when the input is from stdin.
144144
if self.recursive {
145-
self.visit_mod_from_ast(&krate.items)?;
145+
self.visit_mod(&krate.items)?;
146146
}
147147

148148
let snippet_provider = self.parse_sess.snippet_provider(krate.spans.inner_span);
@@ -163,53 +163,22 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
163163
fn visit_cfg_if(&mut self, item: &ast::Item) -> Result<(), ModuleResolutionError> {
164164
let mut visitor = visitor::CfgIfVisitor::new(self.parse_sess);
165165
visitor.visit_item(item);
166-
self.visit_mod_outside_ast(&visitor.items)?;
166+
self.visit_mod(&visitor.items)?;
167167
Ok(())
168168
}
169169

170-
/// Visit modules defined inside macro calls.
171-
fn visit_mod_outside_ast(
170+
fn visit_mod(
172171
&mut self,
173172
items: &[rustc_ast::ptr::P<ast::Item>],
174173
) -> Result<(), ModuleResolutionError> {
175174
for item in items {
176175
if is_cfg_if(item) {
177176
self.visit_cfg_if(item)?;
178-
continue;
179-
}
180-
181-
if let ast::ItemKind::Mod(_, ref sub_mod_kind) = item.kind {
182-
let span = item.span;
177+
} else if let ast::ItemKind::Mod(_, sub_mod_kind) = &item.kind {
183178
self.visit_sub_mod(
184179
&item,
185180
Module::new(
186-
span,
187-
Some(Cow::Borrowed(sub_mod_kind)),
188-
Cow::Owned(ThinVec::new()),
189-
&[],
190-
),
191-
)?;
192-
}
193-
}
194-
Ok(())
195-
}
196-
197-
/// Visit modules from AST.
198-
fn visit_mod_from_ast(
199-
&mut self,
200-
items: &[rustc_ast::ptr::P<ast::Item>],
201-
) -> Result<(), ModuleResolutionError> {
202-
for item in items {
203-
if is_cfg_if(item) {
204-
self.visit_cfg_if(item)?;
205-
}
206-
207-
if let ast::ItemKind::Mod(_, ref sub_mod_kind) = item.kind {
208-
let span = item.span;
209-
self.visit_sub_mod(
210-
item,
211-
Module::new(
212-
span,
181+
item.span,
213182
Some(Cow::Borrowed(sub_mod_kind)),
214183
Cow::Owned(ThinVec::new()),
215184
&[],
@@ -315,14 +284,10 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
315284
if let Some(directory) = directory {
316285
self.directory = directory;
317286
}
318-
match (sub_mod.ast_mod_kind, sub_mod.items) {
319-
(Some(Cow::Borrowed(ast::ModKind::Loaded(items, _, _))), _) => {
320-
self.visit_mod_from_ast(items)
321-
}
322-
(Some(Cow::Owned(ast::ModKind::Loaded(items, _, _))), _) | (_, Cow::Owned(items)) => {
323-
self.visit_mod_outside_ast(&items)
324-
}
325-
(_, _) => Ok(()),
287+
if let Some(ast::ModKind::Loaded(items, _, _)) = sub_mod.ast_mod_kind.as_deref() {
288+
self.visit_mod(&items)
289+
} else {
290+
self.visit_mod(&sub_mod.items)
326291
}
327292
}
328293

0 commit comments

Comments
 (0)