Skip to content
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

imports_granularity=Item removes #[cfg()] attribute from imports #5030

Closed
Tracked by #4991
narpfel opened this issue Oct 16, 2021 · 2 comments
Closed
Tracked by #4991

imports_granularity=Item removes #[cfg()] attribute from imports #5030

narpfel opened this issue Oct 16, 2021 · 2 comments
Labels
bug Panic, non-idempotency, invalid code, etc. help wanted only-with-option requires a non-default option value to reproduce

Comments

@narpfel
Copy link
Contributor

narpfel commented Oct 16, 2021

If I format this file

#[cfg(feature = "foo")]
use std::collections::{
    HashMap,
    HashSet,
};

fn main() {
    println!("Hello, world!");
}

with rustfmt --config imports_granularity=Item, rustfmt removes the cfg attribute:

$ rustfmt --config imports_granularity=Item main.rs

Output:

use std::collections::HashMap;
use std::collections::HashSet;

fn main() {
    println!("Hello, world!");
}

This only happens if there is more than one import in the use statement, i. e. formatting

#[cfg(feature = "foo")]
use std::collections::{
    HashMap,
};

correctly retains the attribute.

rustfmt was installed via rustup, current nightly:

$ rustfmt --version
rustfmt 1.4.37-nightly (c102653 2021-10-15)
@calebcartwright calebcartwright added bug Panic, non-idempotency, invalid code, etc. help wanted only-with-option requires a non-default option value to reproduce labels Oct 16, 2021
@calebcartwright
Copy link
Member

Thanks for the report!

@calebcartwright
Copy link
Member

Cross linking #4991

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Panic, non-idempotency, invalid code, etc. help wanted only-with-option requires a non-default option value to reproduce
Projects
None yet
2 participants