Formatting the compiler tree

This also landed CI checks so all PRs from now on must be appropriately formatted before landing in-tree.

Happy to clarify if people have questions!


I just noticed that trailing whitespace has not been removed. Can someone please run the following across all the code?

find . -type f -name '*.rs' -exec sed --in-place 's/[[:space:]]\+$//' {} \;

I know that trailing whitespace is a tiny nit to pick, but it always bugs me when its there...

Note that it may be worth running it across other code as well, tweaking the command should be easy.

Running rg '\s+$' -trust -g '!src/tools/rustfmt' -g '!src/tools/rls' -g '!src/stdarch' -g '!src/tools/miri' -c locally seems to show that very few files are actually affected by this (I've ignored submodules in that command).


All of these look like they're intentional (testing for \r\n working I believe) so I think there's no actual bug here, at least not within rust-lang/rust.


Glad that the code is clean! But can you check the submodules as well?

I don't personally touch the submodules much -- it certainly looks like there's some trailing new lines in there, but you'd need to talk to the maintainers of those repositories (I don't really contribute to most of our submodules). I expect we don't have unintentional trailing lines in most, if not all, files, there too though.

If that's true, then I'm very impressed!

Why does rustfmt insists on moving the comment to its own line in code like this?

fn main() {
    if true { // explanation.

Having a short comment in the line it refers to can be very useful, so it is quite annoying not to be allowed to do this any more. And worse, rustfmt moves the comment down to after the point where it matters. I expected justification to be given here but there's nothing there, making this seem entirely arbitrary.

I'm very happy with all the auto-indent features for long lists of arguments or chains of functions calls, but it's things like this (and this and this) that make me not use rustfmt on my own projects -- and now they make me regularly fight the tool when working on rustc. :frowning:

EDIT: Filed an issue: