Skip to content

rustfmt fails to resolve mod foo; decorated by an attribute macro #6959

Description

@zhoukezi

Summary

#[my_macro] mod foo; (an "outlined" module supplied to an attribute/derive proc
macro) was recently stabilized on nightly by rust-lang/rust#157857.
In this form the module body can be provided by the macro, so there is intentionally
no foo.rs / foo/mod.rs on disk.

rustfmt, however, seems unconditionally try to resolve every mod foo; to a file
on disk and aborts the entire run when the file is missing, regardless of whether
the module is decorated by an attribute macro.

Expected behavior

rustfmt formats the file (or at least leaves the #[my_macro] mod foo; item
untouched and continues) without requiring a foo.rs file to exist on disk,
since the attribute macro provides the module body.

Actual behavior

rustfmt aborts with a module resolution error and exits non-zero:

Error writing files: failed to resolve mod `foo`: /tmp/foo.rs does not exist

Configuration

Nothing special. Nightly rustfmt.

Reproduction Steps

> cat test.rs
#[my_macro]
mod foo;
> rustfmt +nightly --edition 2024 test.rs
Error writing files: failed to resolve mod `foo`: /tmp/foo.rs does not exist

Nightly rust currently accepts this code (after replacing the placeholder with a real proc-macro that supports this syntax).

Meta

rustfmt --version:

rustfmt 1.9.0-nightly (d0babd8b6b 2026-07-15)

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: this is a bug; use also I-* labels for specific bug kinds, e.g. I-non-idempotency or I-ICEneeds-triageThis issue or PR needs triaging to determine its status. Remove label once sufficiently triaged.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions