rust-lang / rustfmt

Format Rust code
https://rust-lang.github.io/rustfmt/
Apache License 2.0
6.07k stars 893 forks source link

rustfmt removes double colons in macro #5526

Open Dinonard opened 2 years ago

Dinonard commented 2 years ago

Hello,

rustfmt will remove :: from a macro.

To illustrate:

construct_runtime!(
    pub struct Runtime
    where
        Block = Block,
        NodeBlock = generic::Block<Header, sp_runtime::OpaqueExtrinsic>,
        UncheckedExtrinsic = UncheckedExtrinsic,
    {
        Council: pallet_collective::<Instance1>,
        TechnicalCommittee: pallet_collective::<Instance2>,
    }
);

After running cargo fmt:

construct_runtime!(
    pub struct Runtime
    where
        Block = Block,
        NodeBlock = generic::Block<Header, sp_runtime::OpaqueExtrinsic>,
        UncheckedExtrinsic = UncheckedExtrinsic,
    {
        Council: pallet_collective<Instance1>,   <<== '::' is gone
        TechnicalCommittee: pallet_collective<Instance2>,
    }
);

The compilation will fail afterwards. We're using Rust nightly-2022-07-24.

ytmimi commented 2 years ago

Thanks for the report! Confirming I can reproduce this with rustfmt 1.5.1-nightly (2f3ddd9f 2022-06-27)

ytmimi commented 2 years ago

A smaller reproducible example. No macro needed.

Input

struct Runtime {
    Council: pallet_collective::<Instance1>     
}

Output

struct Runtime {
    Council: pallet_collective<Instance1>,
}
ytmimi commented 2 years ago

hmm okay on second thought I think we actually want to remove the :: if we're not in a macro context, but inside the macro we don't want to remove tokens, so I guess this is actually only an issue in the macro case. Related issues: #3139

shawntabrizi commented 6 months ago

Ran into this issue today too.