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

cargo fix --edition does not make the code compilable in rust 2018 if uniform_paths are enabled #5905

Closed
orium opened this issue Aug 18, 2018 · 3 comments

Comments

@orium
Copy link
Member

orium commented Aug 18, 2018

Hi,

while testing cargo fix I believe I have found a bug: When using uniform_paths cargo fix --edition does not migrate paths in use, and those will fail to build on rust 2018.

To reproduce create the following project:

Cargo.toml:

[package]
name = "foobar"
version = "0.0.0"
authors = ["Foo <example@example.com>"]

[dependencies]
criterion = "0.2"

src/lib.rs:

#![allow(unused)]
#![feature(rust_2018_preview, uniform_paths)]
extern crate criterion;
use criterion::Criterion;

If you now run cargo +nightly fix --edition nothing will change, but the code is not compilable in rust 2018. Change Cargo.toml to enable edition 2018 (by adding cargo-features = ["edition"] and package.edition = "2018") and run cargo +nightly build:

$ cargo +nightly build
[...]
error: `criterion` import is ambiguous
 --> src/lib.rs:4:5
  |
3 | extern crate criterion;
  | ----------------------- can refer to `self::criterion`
4 | use criterion::Criterion;
  |     ^^^^^^^^^ can refer to external crate `::criterion`
  |
  = help: write `::criterion` or `self::criterion` explicitly instead
  = note: relative `use` paths enabled by `#![feature(uniform_paths)]`
[...]

As this diagnostic suggests, cargo +nightly fix --edition should have changed line 4 to use ::criterion::Criterion.

@alexcrichton
Copy link
Member

Thanks for the report! Currently not all suggestions in the compiler are marked as "machine applicable" which means that cargo fix will actually apply the fix. In that sense this is mostly an issue for upstream rust-lang/rust and related to rust-lang/rust#50723

@orium
Copy link
Member Author

orium commented Aug 29, 2018

rustc doesn't even emit a warning. Opened issue rust-lang/rust#53797.

@alexcrichton
Copy link
Member

Thanks! In that case I'll close this in favor of that

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

No branches or pull requests

2 participants