Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ use crate::errors::{
};
use crate::fluent_generated;
use crate::mbe::diagnostics::annotate_err_with_kind;
use crate::module::{mod_dir_path, parse_external_mod, DirOwnership, ParsedExternalMod};
use crate::module::{
mod_dir_path, mod_file_path_from_attr, parse_external_mod, DirOwnership, ParsedExternalMod,
};
use crate::placeholders::{placeholder, PlaceholderExpander};

macro_rules! ast_fragments {
Expand Down Expand Up @@ -1202,8 +1204,14 @@ impl InvocationCollectorNode for P<ast::Item> {
ecx.current_expansion.dir_ownership,
*inline,
);
// If the module was parsed from an external file, recover its path.
// This lets `parse_external_mod` catch cycles if it's self-referential.
let file_path = match inline {
Inline::Yes => None,
Inline::No => mod_file_path_from_attr(ecx.sess, &attrs, &dir_path),
};
node.attrs = attrs;
(None, dir_path, dir_ownership)
(file_path, dir_path, dir_ownership)
}
ModKind::Unloaded => {
// We have an outline `mod foo;` so we need to parse the file.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ fn mod_file_path<'a>(

/// Derive a submodule path from the first found `#[path = "path_string"]`.
/// The provided `dir_path` is joined with the `path_string`.
fn mod_file_path_from_attr(
pub(crate) fn mod_file_path_from_attr(
sess: &Session,
attrs: &[Attribute],
dir_path: &Path,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@ error-pattern: circular modules
// Regression test for #97589: a doc-comment on a circular module bypassed cycle detection

#![crate_type = "lib"]

pub mod recursive;
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: circular modules: $DIR/recursive.rs -> $DIR/recursive.rs
--> $DIR/recursive.rs:6:1
|
LL | mod recursive;
| ^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//@ ignore-test: this is an auxiliary file for circular-module-with-doc-comment-issue-97589.rs

//! this comment caused the circular dependency checker to break

#[path = "recursive.rs"]
mod recursive;
Loading