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

WIP: Edition mode #95

Closed
wants to merge 6 commits into from
Closed
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ log = "0.4.1"
duct = "0.8.2"
env_logger = "0.5.0-rc.1"
log = "0.4.1"
pretty_assertions = "0.4.1"
tempdir = "0.3.5"
proptest = "0.7.0"
difference = "2.0.0"

[workspace]
members = [
Expand Down
48 changes: 48 additions & 0 deletions cargo-fix/tests/all/edition.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use super::project;

#[test]
#[ignore = "Requires custom rustc build"]
fn fix_edition_lints() {
let p = project()
.file(
"Cargo.toml",
r#"
cargo-features = ["edition"]

[package]
name = "foo"
version = "0.1.0"

rust = "2018"

[workspace]
"#,
)
.file(
"src/lib.rs",
r#"
#![allow(unused)]
#[warn(rust_2018_migration)]

mod private_mod {
pub const FOO: &str = "BAR";
}

fn main() {}

"#,
)
.build();

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

assert!(p.read("src/lib.rs").contains(r#"crate const FOO: &str = "BAR";"#));
}
1 change: 1 addition & 0 deletions cargo-fix/tests/all/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,3 +321,4 @@ mod dependencies;
mod smoke;
mod subtargets;
mod warnings;
mod edition;
File renamed without changes.
8 changes: 8 additions & 0 deletions tests/edition/pub_crate.fixed.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![allow(unused)]
#[warn(rust_2018_migration)]

mod private_mod {
crate const FOO: &str = "BAR";
}

fn main() {}
108 changes: 108 additions & 0 deletions tests/edition/pub_crate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"message": "unreachable `pub` item",
"code": {
"code": "unreachable_pub",
"explanation": null
},
"level": "warning",
"spans": [
{
"file_name": "./tests/edition/pub_crate.rs",
"byte_start": 70,
"byte_end": 98,
"line_start": 5,
"line_end": 5,
"column_start": 5,
"column_end": 33,
"is_primary": true,
"text": [
{
"text": " pub const FOO: &str = \"BAR\";",
"highlight_start": 5,
"highlight_end": 33
}
],
"label": null,
"suggested_replacement": null,
"expansion": null
}
],
"children": [
{
"message": "lint level defined here",
"code": null,
"level": "note",
"spans": [
{
"file_name": "./tests/edition/pub_crate.rs",
"byte_start": 25,
"byte_end": 44,
"line_start": 2,
"line_end": 2,
"column_start": 8,
"column_end": 27,
"is_primary": true,
"text": [
{
"text": "#[warn(rust_2018_migration)]",
"highlight_start": 8,
"highlight_end": 27
}
],
"label": null,
"suggested_replacement": null,
"expansion": null
}
],
"children": [],
"rendered": null
},
{
"message": "#[warn(unreachable_pub)] implied by #[warn(rust_2018_migration)]",
"code": null,
"level": "note",
"spans": [],
"children": [],
"rendered": null
},
{
"message": "or consider exporting it for use by other crates",
"code": null,
"level": "help",
"spans": [],
"children": [],
"rendered": null
},
{
"message": "consider restricting its visibility",
"code": null,
"level": "help",
"spans": [
{
"file_name": "./tests/edition/pub_crate.rs",
"byte_start": 70,
"byte_end": 73,
"line_start": 5,
"line_end": 5,
"column_start": 5,
"column_end": 8,
"is_primary": true,
"text": [
{
"text": " pub const FOO: &str = \"BAR\";",
"highlight_start": 5,
"highlight_end": 8
}
],
"label": null,
"suggested_replacement": "crate",
"suggestion_applicability": "MachineApplicable",
"expansion": null
}
],
"children": [],
"rendered": null
}
],
"rendered": "warning: unreachable `pub` item\n --> ./tests/edition/pub_crate.rs:5:5\n |\n5 | pub const FOO: &str = \"BAR\";\n | ---^^^^^^^^^^^^^^^^^^^^^^^^^\n | |\n | help: consider restricting its visibility: `crate`\n |\nnote: lint level defined here\n --> ./tests/edition/pub_crate.rs:2:8\n |\n2 | #[warn(rust_2018_migration)]\n | ^^^^^^^^^^^^^^^^^^^\n = note: #[warn(unreachable_pub)] implied by #[warn(rust_2018_migration)]\n = help: or consider exporting it for use by other crates\n\n"
}
8 changes: 8 additions & 0 deletions tests/edition/pub_crate.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![allow(unused)]
#[warn(rust_2018_migration)]

mod private_mod {
pub const FOO: &str = "BAR";
}

fn main() {}
158 changes: 0 additions & 158 deletions tests/everything.rs

This file was deleted.

2 changes: 2 additions & 0 deletions tests/everything/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.recorded.json
*.recorded.rs
6 changes: 3 additions & 3 deletions tests/fixtures/E0178.json → tests/everything/E0178.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"level": "error",
"spans": [
{
"file_name": "./tests/fixtures/E0178.rs",
"file_name": "./tests/everything/E0178.rs",
"byte_start": 60,
"byte_end": 74,
"line_start": 6,
Expand All @@ -34,7 +34,7 @@
"level": "help",
"spans": [
{
"file_name": "./tests/fixtures/E0178.rs",
"file_name": "./tests/everything/E0178.rs",
"byte_start": 60,
"byte_end": 74,
"line_start": 6,
Expand All @@ -58,7 +58,7 @@
"rendered": null
}
],
"rendered": "error[E0178]: expected a path on the left-hand side of `+`, not `&'a Foo`\n --> ./tests/fixtures/E0178.rs:6:8\n |\n6 | w: &'a Foo + Send,\n | ^^^^^^^^^^^^^^ help: try adding parentheses: `&'a (Foo + Send)`\n\nIf you want more information on this error, try using \"rustc --explain E0178\"\n"
"rendered": "error[E0178]: expected a path on the left-hand side of `+`, not `&'a Foo`\n --> ./tests/everything/E0178.rs:6:8\n |\n6 | w: &'a Foo + Send,\n | ^^^^^^^^^^^^^^ help: try adding parentheses: `&'a (Foo + Send)`\n\nIf you want more information on this error, try using \"rustc --explain E0178\"\n"
}
{
"message": "aborting due to previous error",
Expand Down
File renamed without changes.
Loading