Closed
Description
Problem
cargo fmt
no longer processes modules that are referenced in an inline mod.
Steps
crate tree:
.
├── Cargo.toml
└── src
├── bar
│ └── baz.rs
├── foo
│ └── qux.rs
├── foo.rs
└── main.rs
src/main.rs:
fn main() {
println!("Hello, world!");
}
mod foo;
mod bar {
mod baz;
}
src/foo.rs: mod qux;
src/foo/qux.rs: empty
src/bar/baz.rs: empty
Stable is fine:
> cargo +stable fmt -- -v
Formatting /home/jan/x/src/bar/baz.rs
Formatting /home/jan/x/src/foo/qux.rs
Formatting /home/jan/x/src/foo.rs
Formatting /home/jan/x/src/main.rs
Nightly is broken:
> cargo +nightly fmt -- -v
Formatting /home/jan/x/src/foo/qux.rs
Formatting /home/jan/x/src/foo.rs
Formatting /home/jan/x/src/main.rs
Notes
Output of cargo version
:
- Nightly is broken:
cargo 1.54.0-nightly (44456677b 2021-06-12)
- Stable is fine:
cargo 1.52.0 (69767412a 2021-04-21)
Rust via rustup 1.24.3, Arch Linux.
Activity
heftig commentedon Jun 17, 2021
Beta (
cargo 1.53.0-beta (4369396ce 2021-04-27)
) is affected as well.calebcartwright commentedon Jun 17, 2021
We haven't really had any changes on our end, much less anything that touched the mod resolver. Could you please run
cargo fmt --version
just to rule out the possibility of an older install being usedheftig commentedon Jun 17, 2021
calebcartwright commentedon Jun 17, 2021
Thanks! Have a theory, will test it out later today
ehuss commentedon Jun 17, 2021
Bisecting was a bit tricky since it was just a "rustfmt update", but 612e8d5 looks suspicious. Let us know if you need any help.
calebcartwright commentedon Jun 17, 2021
thanks @ehuss
in the ast prior to any kind of expansion, the bar mod item here would have a loaded/inline::yes kind wouldn't it?
if so it's probably an issue here. i'm stuck at work for several more hours but if anyone wants to take a pass at it in the interim i'd probably start looking here on that first arm
rustfmt/src/modules.rs
Lines 320 to 325 in 6495024
ehuss commentedon Jun 17, 2021
Yea, from my understanding of rust-lang/rust@4a88165, it is loaded/inline::Yes. So maybe something like this could work:
However, from what I can tell, rustfmt does not format post-expansion loaded modules. I'm not too familiar with rustfmt, but is it known or intended that does not work? For example:
Here,
foo.rs
will never get formatted because it is only loaded after expansion. That's maybe unrelated to the issue here, just curious.calebcartwright commentedon Jun 18, 2021
You are correct and yes it's known/expected. There's a few exceptions, such as
cfg_if
, where we have special case handling to use the tokens and attempt to parse out mod items, but otherwise such post-expansion mods and their associated files don't get formatted.Probably a couple options for extending support for those types of cases, but I'd expect it to be a sizeable undertaking that'd be a relatively low priority compared to some other items on our backlog.
Rollup merge of rust-lang#86424 - calebcartwright:rustfmt-mod-resolut…
calebcartwright commentedon Jun 23, 2021
The fix has been applied in the rustc repo and should be in the latest nightly so going to close
pnkfelix commentedon Jun 24, 2021
If this affects beta or stable versions (i.e. not just nightly) then should it remain open (at least until there's a decision about whether to backport the thing to beta/stable)? That is the policy we use for
rustc
, but I don't know if the rustfmt team uses a different policy.or maybe the point is that the real bug needs to be tracked on the rustc repo, not the rustfmt repo... hmm.
calebcartwright commentedon Jun 24, 2021
We've always closed our issues as they are fixed in source, and don't base our issue status on release/channel propagation upstream. In my opinion backport nominations/status are far better handled in rustc and I don't want to attempt to try to duplicate/mirror that here.
Although I'd personally encourage proceeding with the backport, that's a separate concern from the bug being fixed, and whether or not backporting happens is obviously a decision outside our control.
No, development and maintenance of rustfmt happens here and our issues need to continue to be managed here as well. I'm not sure if it makes sense to have a separate tracking-like issue in rustc for the backporting piece, but I don't want to bifurcate our issue tracker across two repos.
3 remaining items