Help test out the 2018 module system changes!

> rustup show
Default host: x86_64-pc-windows-msvc

...

active toolchain
----------------

nightly-x86_64-pc-windows-msvc (default)
rustc 1.29.0-nightly (6a1c0637c 2018-07-23)

Feedback

  1. Having rustfix merged into cargo was a great idea. As someone who does a lot of Python at home and work, and often educates people on how/why to migrate to Python 3, having an automated, officially supported tool at everyone's finger tips is going to pay dividends here. :+1:

  2. I found it a little confusing that after adding #![feature(rust_2018_preview)] to main.rs and no other changes, I was doomed to hit this error:

error: the working directory of this project is detected as dirty, and `cargo fix` can potentially perform destructive changes; if you'd like to suppress this error pass
 `--allow-dirty`, or commit the changes to these files:

  * src/main.rs

Is there any way to special case the #![feature(rust_2018_preview)] diff since literally everyone will hit it? Or when this is stable, will that flag not be needed so that this transition would be smoother for everyone?

  1. Git-ignored files shouldn't be worried about as dirty, but I already saw an issue for that somewhere.

  2. cargo fix should automatically fix extern crate's. I was getting warnings, but they all seemed like they should be fixed mechanically.

cargo-features = ["edition"]

...
[package]
edition = '2018'

Running

> cargo +nightly fix --prepare-for 2018 --all-targets --all-features --allow-dirty
    Checking rust-belt v1.2.0 (file:///C:/Users/User/PycharmProjects/rust-belt)
warning: unused extern crate
 --> src\main.rs:6:1
  |
6 | extern crate ai_behavior;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it
  |
note: lint level defined here
 --> src\main.rs:4:9
  |
4 | #![warn(rust_2018_idioms)]
  |         ^^^^^^^^^^^^^^^^
  = note: #[warn(unused_extern_crates)] implied by #[warn(rust_2018_idioms)]

warning: `extern crate` is not idiomatic in the new edition
 --> src\main.rs:7:1
  |
7 | extern crate music;
  | ^^^^^^^^^^^^^^^^^^^ help: convert it to a `use`

warning: unused extern crate
 --> src\main.rs:8:1
  |
8 | extern crate opengl_graphics;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it

warning: unused extern crate
 --> src\main.rs:9:1
  |
9 | extern crate piston_window;
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove it

warning: `extern crate` is not idiomatic in the new edition
  --> src\main.rs:10:1
   |
10 | extern crate rand;
   | ^^^^^^^^^^^^^^^^^^ help: convert it to a `use`

warning: unused extern crate
  --> src\main.rs:11:1
   |
11 | extern crate sprite;
   | ^^^^^^^^^^^^^^^^^^^^ help: remove it

...

    Finished dev [unoptimized + debuginfo] target(s) in 2.65s
  1. Some of the extern crate lints were invalid. For example it told me:
warning: `extern crate` is not idiomatic in the new edition
 --> src\main.rs:7:1
  |
7 | extern crate music;
  | ^^^^^^^^^^^^^^^^^^^ help: convert it to a `use`

But when I changed it to a use, I got another warning:

warning: unused import: `music`
 --> src\main.rs:6:5
  |
6 | use music;
  |     ^^^^^
  |
  = note: #[warn(unused_imports)] on by default

Other times the lint told me to remove the extern crate correctly.

Overall, the experience was positive, but I wonder if it would be possible to provide an option to condense the 3 steps (#![feature(rust_2018_preview)], #![warn(rust_2018_idioms)], and Cargo.toml) changes into a single step.

Something like: cargo fix --migrate-to 2018 that would condense all of these steps into a single go.

In the end, I had rust-belt fully migrated to Rust 2018 in about 30 minutes using cargo fix on Windows (probably less tested, which is why I chose to do it on Windows). Diff can be viewed on GitHub.

1 Like