Rustfmt question

I have some code with extra spaces added inside [ ] intentionally. If I run cargo fmt, it will remove the extra space. Is there a way to tell rustfmt (or cargo fmt) to skip that?

example:

    state[idx    ] ^= 10;
    state[idx + 1] ^= 11;
    state[idx + 2] ^= 12;

By default, rustfmt removes the extra space in the first line above. Can I ask rustfmt not to do that?

Thanks.

I think there's a #[rustfmt::skip] thing or something like that.

1 Like

Personally, to satisfy some kind of OCD about regularity and consistency and to avoid that ugly hole, I would write it as:

    state[idx + 0] ^= 10;
    state[idx + 1] ^= 11;
    state[idx + 2] ^= 12;

But then one has to add #[warn(clippy::identity_op)] to keep clippy shut up about warning: the operation is ineffective. Consider reducing it to 'idx'

But then I don't like to have all that hash, square bracket ugliness cluttering up the code either. Or put it in a clippy.toml file.

Meh, so often I'm lazy enough to just let cargo fmt do what it likes out of the box and move on.

Exactly. I started with idx + 0 and then went through the clippy thing. I didn't know about the clippy.toml config though.

I'm also not sure about adding #[rustfm::skip] like alice mentioned.

I need to think about which route to go, or maybe just table this issue for now.

Hmm... to "table an issue" means "put it on the table for discussion now".

I'd be inclined to shelve it :slight_smile:

Haha, I never thought of that :wink: . Now I just looked it up, and found something interesting:

from wikipedia%20of%20a%20proposal.):

In parliamentary procedure, the verb to table has the opposite meaning in different countries:

In the United States, to "table" usually means to postpone or suspend consideration of a pending motion.
In the rest of the English-speaking world, to "table" means to begin consideration (or reconsideration) of a proposal.
2 Likes

Yeah, as George Burnard Shaw said:

England and America are two countries separated by the same language!

3 Likes