Skip to content

Absolute use path is erroneously stripped #3918

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
DomWilliams0 opened this issue Nov 10, 2019 · 2 comments
Closed

Absolute use path is erroneously stripped #3918

DomWilliams0 opened this issue Nov 10, 2019 · 2 comments

Comments

@DomWilliams0
Copy link

DomWilliams0 commented Nov 10, 2019

Rustfmt is removing the :: prefix of absolute imports, which breaks when that import must differentiate between the crate of that name and a clashing module. An example:

$ cat src/lib.rs
// an empty module that shares the name of another crate, no problem
mod std {}

// i can access the original crate through ::std
use ::std::string;

$ cargo build
...
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s // <----- successful build

$ rustfmt --version
rustfmt 1.4.9-nightly (33e3667 2019-10-07)

$ rustfmt src/lib.rs

$ cat src/lib.rs
// an empty module that shares the name of another crate, no problem
mod std {}

// i can access the original crate through ::std
use std::string;      // <------------ note the removed :: prefix

$ cargo build
   Compiling fmt v0.1.0 (/tmp/fmt)
error[E0432]: unresolved import `std::string`
 --> src/lib.rs:5:5
  |
5 | use std::string;
  |     ^^^^^^^^^^^ no `string` in `std`

error[E0659]: `std` is ambiguous (name vs any other name during import resolution)
 --> src/lib.rs:5:5
  |
5 | use std::string;
  |     ^^^ ambiguous name
  |
  = note: `std` could refer to a built-in crate
  = help: use `::std` to refer to this crate unambiguously
note: `std` could also refer to the module defined here
 --> src/lib.rs:2:1
  |
2 | mod std {}
  | ^^^^^^^^^^
  = help: use `crate::std` to refer to this module unambiguously

error: aborting due to 2 previous errors
@calebcartwright
Copy link
Member

Sounds like a potential dupe of #3501.

Have you tried including edition either via --edition 2018 arg or in your rustfmt config file? rustfmt 2.0 will switch the default edition to 2018 but it currently defaults to 2015

@topecongiro
Copy link
Contributor

Closing as a dup of #3501.

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