Skip to content

cargo fmt does not do anything in tokio repo #4078

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Diggsey opened this issue Mar 10, 2020 · 5 comments
Open

cargo fmt does not do anything in tokio repo #4078

Diggsey opened this issue Mar 10, 2020 · 5 comments
Labels
a-macros a-mods Module resolution.

Comments

@Diggsey
Copy link

Diggsey commented Mar 10, 2020

I found this problem locally and wondered how tokio was checking formatting in CI.

As you can see they are calling rustfmt directly:
https://github.com/tokio-rs/tokio/blob/master/ci/azure-rustfmt.yml#L17

This comment links to a cargo issue:
rust-lang/cargo#7732

However, this cargo issue is closed and it's not clear how it's related.

@calebcartwright
Copy link
Member

I can't really speak to the tokio nor cargo aspects, so you'd have to check in those respective repos for more details.

cargo fmt is a wrapper around the rustfmt binary to make it easier to run rustfmt across entire projects/workspaces. cargo fmt leverages the cargo_metadata crate which at a high level executes the cargo metadata --format-version 1 ... commands and deserializes the results. cargo fmt then uses the contents of that cargo metadata to structure and issue the corresponding rustfmt commands.

If, for whatever reason, the cargo metadata cannot be determined within the tokio workspace then that would be problematic for cargo fmt.

You could try running cargo fmt with the --verbose flag to get additional output, including the rustfmt commands it would issue. However, I don't get the sense the tokio challenges are related to rustfmt, though please let us know if there does turn out to be an issue on the rustfmt side.

@lnicola

This comment has been minimized.

@calebcartwright
Copy link
Member

calebcartwright commented Apr 6, 2020

It looks like cargo fmt only finds files called lib.rs, main.rs and build.rs. Seen on both nightly and stable.

That is by design. cargo fmt will pass the main entry point file for each target for each package within the workspace. rustfmt then formats those recursively following the tree of imported mods, including those defined in separate files.

@topecongiro
Copy link
Contributor

Outside of the linked issue, tokio uses macros to define modules, which rustfmt cannot recognize (https://github.com/tokio-rs/tokio/blob/67c4cc03919a58076c139f0930f28c3c41dad1e5/tokio/src/lib.rs#L326-L348).

I don't think that just adding support for modules defined inside macro calls fixes the issue in tokio crate, though we should add it anyway.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 26, 2022

Somewhat related to #4034 since it's another case where we don't perform module resolution because of macros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-macros a-mods Module resolution.
Projects
None yet
Development

No branches or pull requests

5 participants