Skip to content

Commit 9a7644e

Browse files
committed
rustc_expand: remember module #[path]s during expansion
this fixes cycle detection for modules that need a second invocation collection pass after parsing
1 parent f7f8bdf commit 9a7644e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

Diff for: compiler/rustc_expand/src/expand.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ use crate::errors::{
4141
};
4242
use crate::fluent_generated;
4343
use crate::mbe::diagnostics::annotate_err_with_kind;
44-
use crate::module::{mod_dir_path, parse_external_mod, DirOwnership, ParsedExternalMod};
44+
use crate::module::{
45+
mod_dir_path, mod_file_path_from_attr, parse_external_mod, DirOwnership, ParsedExternalMod,
46+
};
4547
use crate::placeholders::{placeholder, PlaceholderExpander};
4648

4749
macro_rules! ast_fragments {
@@ -1202,8 +1204,14 @@ impl InvocationCollectorNode for P<ast::Item> {
12021204
ecx.current_expansion.dir_ownership,
12031205
*inline,
12041206
);
1207+
// If the module was parsed from an external file, recover its path.
1208+
// This lets `parse_external_mod` catch cycles if it's self-referential.
1209+
let file_path = match inline {
1210+
Inline::Yes => None,
1211+
Inline::No => mod_file_path_from_attr(ecx.sess, &attrs, &dir_path),
1212+
};
12051213
node.attrs = attrs;
1206-
(None, dir_path, dir_ownership)
1214+
(file_path, dir_path, dir_ownership)
12071215
}
12081216
ModKind::Unloaded => {
12091217
// We have an outline `mod foo;` so we need to parse the file.

Diff for: compiler/rustc_expand/src/module.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ fn mod_file_path<'a>(
171171

172172
/// Derive a submodule path from the first found `#[path = "path_string"]`.
173173
/// The provided `dir_path` is joined with the `path_string`.
174-
fn mod_file_path_from_attr(
174+
pub(crate) fn mod_file_path_from_attr(
175175
sess: &Session,
176176
attrs: &[Attribute],
177177
dir_path: &Path,

0 commit comments

Comments
 (0)