A module loaded with #[path] is incorrectly reported as circular when the loaded module contains an inner attribute and declares a nested module using the name/mod.rs layout.
I tried this code:
Cargo.toml
main.rs
name/
mod.rs
name/
mod.rs
# Cargo.toml
[package]
name = "circular_modules"
version = "0.0.0"
[[bin]]
name = "main"
path = "main.rs"
// main.rs
#[path = "name/mod.rs"]
mod name;
fn main() {}
// name/mod.rs
#![allow(unused)]
mod name;
I expected to see this happen: the crate compiles successfully. The modules are distinct: main.rs loads name/mod.rs, which then loads name/name/mod.rs.
Instead, this happened:
error: circular modules: name/name/mod.rs -> name/name/mod.rs
--> name/mod.rs:3:1
|
3 | mod name;
| ^^^^^^^^^
The issue appears to depend on this particular combination.
Removing the inner attribute makes it compile:
Removing the parent's #[path] attribute also makes it compile:
// main.rs
mod name;
fn main() {}
Keeping the parent's #[path] and the inner attribute, but changing the child module layout from:
to:
also makes it compile.
So the false circular-module diagnostic appears when:
- the parent module is loaded through
#[path];
- that loaded module contains an inner attribute;
- its child is resolved using the
name/mod.rs layout.
Meta
The bug occurs on both stable 1.98.0 and current nightly.
rustc +stable --version --verbose:
rustc 1.98.0 (88d9e12ae 2026-08-18)
binary: rustc
commit-hash: 88d9e12ae178fab0fb5cc050a94da85685d449ea
commit-date: 2026-08-18
host: x86_64-unknown-linux-gnu
release: 1.98.0
LLVM version: 22.1.8
rustc +nightly --version --verbose:
rustc 1.100.0-nightly (908501772 2026-08-30)
binary: rustc
commit-hash: 90850177249efe0321573c569aec5d12b257f8d6
commit-date: 2026-08-30
host: x86_64-unknown-linux-gnu
release: 1.100.0-nightly
LLVM version: 23.1.0
A module loaded with
#[path]is incorrectly reported as circular when the loaded module contains an inner attribute and declares a nested module using thename/mod.rslayout.I tried this code:
// name/name/mod.rsI expected to see this happen: the crate compiles successfully. The modules are distinct:
main.rsloadsname/mod.rs, which then loadsname/name/mod.rs.Instead, this happened:
The issue appears to depend on this particular combination.
Removing the inner attribute makes it compile:
Removing the parent's
#[path]attribute also makes it compile:Keeping the parent's
#[path]and the inner attribute, but changing the child module layout from:to:
also makes it compile.
So the false circular-module diagnostic appears when:
#[path];name/mod.rslayout.Meta
The bug occurs on both stable 1.98.0 and current nightly.
rustc +stable --version --verbose:rustc +nightly --version --verbose: