Skip to content

imports_granularity = "Module" breaks code which imports the same identifier twice with two different names #5224

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

Closed
glittershark opened this issue Feb 7, 2022 · 2 comments

Comments

@glittershark
Copy link

glittershark commented Feb 7, 2022

rustfmt.toml:

edition = "2018" # not sure if this is necessary for repro
imports_granularity = "Module"

main.rs (pre formatting):

use std::collections::HashMap;
use std::collections::HashMap as HM;

fn f(_: &HM<i32, i32>) {}
fn main() {
  let x = HashMap::new();
  f(&x);
}

main.rs (post formatting):

use std::collections::HashMap;

fn f(_: &HM<i32, i32>) {}
fn main() {
    let x = HashMap::new();
    f(&x);
}

removing the HashMap as HM alias causes the code to no longer compile.

@ytmimi
Copy link
Contributor

ytmimi commented Feb 8, 2022

Thanks for reaching out.

By the way, what version of rustfmt are you using? I believe this has been fixed in master by #5209.

Using rustfmt 1.4.38-nightly (8b0b213c 2022-01-29) I get the following when reformatting your snippet using your specified configuration options:

use std::collections::{HashMap, HashMap as HM};

fn f(_: &HM<i32, i32>) {}
fn main() {
    let x = HashMap::new();
    f(&x);
}

@ytmimi ytmimi added the fixed label Feb 8, 2022
@calebcartwright
Copy link
Member

Thanks for sharing but closing as a duplicate. It hasn't been released yet but the fix will hit nightly the next time we run a sync

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants