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

Commit 5649ad4

Browse files
authored
Merge pull request #98 from rust-lang-nursery/prepare-for-flag
Add `--prepare-for` flag
2 parents b5e4e61 + a956e9e commit 5649ad4

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

cargo-fix/src/cli.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ pub fn run() -> Result<(), Error> {
3333
Arg::with_name("broken-code")
3434
.long("broken-code")
3535
.help("Fix code even if it already has compiler errors"),
36+
)
37+
.arg(
38+
Arg::with_name("edition")
39+
.long("prepare-for")
40+
.help("Fix warnings in preparation of an edition upgrade")
41+
.takes_value(true)
42+
.possible_values(&["2018"]),
3643
),
3744
)
3845
.get_matches();
@@ -77,6 +84,15 @@ pub fn run() -> Result<(), Error> {
7784
cmd.env("RUSTC_ORIGINAL", rustc);
7885
}
7986

87+
// Trigger edition-upgrade mode. Currently only supports the 2018 edition.
88+
info!("edition upgrade? {:?}", matches.value_of("edition"));
89+
if let Some("2018") = matches.value_of("edition") {
90+
info!("edition upgrade!");
91+
let mut rustc_flags = env::var_os("RUSTFLAGS").unwrap_or_else(|| "".into());
92+
rustc_flags.push("-W rust-2018-breakage");
93+
cmd.env("RUSTFLAGS", &rustc_flags);
94+
}
95+
8096
// An now execute all of Cargo! This'll fix everything along the way.
8197
//
8298
// TODO: we probably want to do something fancy here like collect results
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//! Test that we can use cargo-fix to upgrade our code to work with the 2018
2+
//! edition.
3+
//!
4+
//! We'll trigger the `absolute_path_starting_with_module` lint which should
5+
//! transform a `use ::foo;` where `foo` is local to `use crate::foo;`.
6+
7+
use super::project;
8+
9+
#[test]
10+
fn prepare_for_2018() {
11+
let p = project()
12+
.file(
13+
"src/lib.rs",
14+
r#"
15+
#![allow(unused)]
16+
#![feature(rust_2018_preview)]
17+
18+
mod foo {
19+
pub const FOO: &str = "fooo";
20+
}
21+
22+
mod bar {
23+
use ::foo::FOO;
24+
}
25+
26+
fn main() {
27+
let x = ::foo::FOO;
28+
}
29+
"#,
30+
)
31+
.build();
32+
33+
let stderr = "\
34+
[CHECKING] foo v0.1.0 (CWD)
35+
[FIXING] src/lib.rs (2 fixes)
36+
[FINISHED] dev [unoptimized + debuginfo]
37+
";
38+
p.expect_cmd("cargo-fix fix --prepare-for 2018")
39+
.stdout("")
40+
.stderr(stderr)
41+
.run();
42+
43+
println!("{}", p.read("src/lib.rs"));
44+
assert!(p.read("src/lib.rs").contains("use crate::foo::FOO;"));
45+
assert!(p.read("src/lib.rs").contains("let x = crate::foo::FOO;"));
46+
}

cargo-fix/tests/all/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,7 @@ fn diff(expected: &str, actual: &str) {
318318
mod broken_build;
319319
mod broken_lints;
320320
mod dependencies;
321+
mod edition_upgrade;
321322
mod smoke;
322323
mod subtargets;
323324
mod warnings;

0 commit comments

Comments
 (0)