Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Add --prepare-for flag #98

Merged
merged 6 commits into from
May 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions cargo-fix/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ pub fn run() -> Result<(), Error> {
Arg::with_name("broken-code")
.long("broken-code")
.help("Fix code even if it already has compiler errors"),
)
.arg(
Arg::with_name("edition")
.long("prepare-for")
.help("Fix warnings in preparation of an edition upgrade")
.takes_value(true)
.possible_values(&["2018"]),
),
)
.get_matches();
Expand Down Expand Up @@ -77,6 +84,15 @@ pub fn run() -> Result<(), Error> {
cmd.env("RUSTC_ORIGINAL", rustc);
}

// Trigger edition-upgrade mode. Currently only supports the 2018 edition.
info!("edition upgrade? {:?}", matches.value_of("edition"));
if let Some("2018") = matches.value_of("edition") {
info!("edition upgrade!");
let mut rustc_flags = env::var_os("RUSTFLAGS").unwrap_or_else(|| "".into());
rustc_flags.push("-W rust-2018-breakage");
cmd.env("RUSTFLAGS", &rustc_flags);
}

// An now execute all of Cargo! This'll fix everything along the way.
//
// TODO: we probably want to do something fancy here like collect results
Expand Down
46 changes: 46 additions & 0 deletions cargo-fix/tests/all/edition_upgrade.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//! Test that we can use cargo-fix to upgrade our code to work with the 2018
//! edition.
//!
//! We'll trigger the `absolute_path_starting_with_module` lint which should
//! transform a `use ::foo;` where `foo` is local to `use crate::foo;`.

use super::project;

#[test]
fn prepare_for_2018() {
let p = project()
.file(
"src/lib.rs",
r#"
#![allow(unused)]
#![feature(rust_2018_preview)]

mod foo {
pub const FOO: &str = "fooo";
}

mod bar {
use ::foo::FOO;
}

fn main() {
let x = ::foo::FOO;
}
"#,
)
.build();

let stderr = "\
[CHECKING] foo v0.1.0 (CWD)
[FIXING] src/lib.rs (2 fixes)
[FINISHED] dev [unoptimized + debuginfo]
";
p.expect_cmd("cargo-fix fix --prepare-for 2018")
.stdout("")
.stderr(stderr)
.run();

println!("{}", p.read("src/lib.rs"));
assert!(p.read("src/lib.rs").contains("use crate::foo::FOO;"));
assert!(p.read("src/lib.rs").contains("let x = crate::foo::FOO;"));
}
1 change: 1 addition & 0 deletions cargo-fix/tests/all/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ fn diff(expected: &str, actual: &str) {
mod broken_build;
mod broken_lints;
mod dependencies;
mod edition_upgrade;
mod smoke;
mod subtargets;
mod warnings;