Skip to content

Commit 8dead3d

Browse files
committed
Handle mod declaration with a partial cfg
1 parent 4ed212b commit 8dead3d

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/modules.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,9 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
267267
}
268268

269269
// Look for nested path, like `#[cfg_attr(feature = "foo", path = "bar.rs")]`.
270-
match self.find_mods_ouside_of_ast(attrs, sub_mod) {
271-
Some(mods) => {
272-
if !mods.is_empty() {
273-
return Ok(SubModKind::MultiExternal(mods));
274-
}
275-
}
276-
_ => (),
277-
}
270+
let mut mods_outside_ast = self
271+
.find_mods_ouside_of_ast(attrs, sub_mod)
272+
.unwrap_or(vec![]);
278273

279274
let relative = match self.directory.ownership {
280275
DirectoryOwnership::Owned { relative } => relative,
@@ -292,7 +287,15 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
292287
path,
293288
directory_ownership,
294289
..
295-
}) => Ok(SubModKind::External(path, directory_ownership)),
290+
}) => Ok(if mods_outside_ast.is_empty() {
291+
SubModKind::External(path, directory_ownership)
292+
} else {
293+
mods_outside_ast.push((path, directory_ownership, sub_mod.clone()));
294+
SubModKind::MultiExternal(mods_outside_ast)
295+
}),
296+
Err(_) if !mods_outside_ast.is_empty() => {
297+
Ok(SubModKind::MultiExternal(mods_outside_ast))
298+
}
296299
Err(_) => Err(format!(
297300
"Failed to find module {} in {:?} {:?}",
298301
mod_name, self.directory.path, relative,
@@ -375,7 +378,8 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
375378
);
376379
parser.cfg_mods = false;
377380
let lo = parser.span;
378-
let mod_attrs = match parse_inner_attributes(&mut parser) {
381+
// FIXME(topecongiro) Format inner attributes (#3606).
382+
let _mod_attrs = match parse_inner_attributes(&mut parser) {
379383
Ok(attrs) => attrs,
380384
Err(mut e) => {
381385
e.cancel();

0 commit comments

Comments
 (0)