-
Notifications
You must be signed in to change notification settings - Fork 957
Description
Take any piece of Rust code, split by non-obnoxious tokens on each line, for each line add a space after the token, a newline, and a comment.
non-obnoxious token would mean tokens that make sense to be commented, e.g. all tokens other than commas, double colons ::
in paths or dots in field access or method calls .
, or <
and >
in generic argument syntax etc.
for example this code:
pub trait Clean<Inner, Outer>: Dirty + 'static {
const ASSOC: usize = 0;
}
would become
pub
// comment
trait
// comment
Clean<
// comment
Inner,
// comment
Outer>:
// comment
Dirty +
// comment
'static {
// comment
const
// comment
ASSOC:
// comment
usize =
// comment
0;
// comment
}
(note the whitespace before newlines)
the reason we do this is to see which tokens leave leftover whitespace after them when passed through rustfmt. these are all locations a programmer would possibly want to comment on, for example, one could need to add a comment between pub and trait to denote why Clean
needs to be a trait and not a standalone constant (first error), or simply comment on the type of a constant (8th error) etc.
in contemporary rustfmt this cannot be formatted due to left behind trailing whitespace
errors:
eurydice@fedora:~/coreign/thread_local_rng$ cargo fmt
error[internal]: left behind trailing whitespace
--> /home/eurydice/coreign/thread_local_rng/src/lib.rs:22:22:4
|
22 | pub
| ^
|
error[internal]: left behind trailing whitespace
--> /home/eurydice/coreign/thread_local_rng/src/lib.rs:24:24:6
|
24 | trait
| ^
|
...
warning: rustfmt has failed to format. See previous 11 errors.