Skip to content

Commit 9159ebb

Browse files
committed
fix(cargo-lints): Don't rewrite dash to underscore in lint name
1 parent 6fc9e4b commit 9159ebb

File tree

6 files changed

+33
-62
lines changed

6 files changed

+33
-62
lines changed

src/cargo/core/workspace.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,7 +1161,6 @@ impl<'gctx> Workspace<'gctx> {
11611161
.cloned()
11621162
.unwrap_or_default()
11631163
.into_iter()
1164-
.map(|(k, v)| (k.replace('-', "_"), v))
11651164
.collect();
11661165

11671166
for (path, maybe_pkg) in &self.packages.packages {
@@ -1214,10 +1213,6 @@ impl<'gctx> Workspace<'gctx> {
12141213
.get("cargo")
12151214
.cloned()
12161215
.unwrap_or(manifest::TomlToolLints::default());
1217-
let normalized_lints = cargo_lints
1218-
.into_iter()
1219-
.map(|(name, lint)| (name.replace('-', "_"), lint))
1220-
.collect();
12211216

12221217
// We should only be using workspace lints if the `[lints]` table is
12231218
// present in the manifest, and `workspace` is set to `true`
@@ -1242,7 +1237,7 @@ impl<'gctx> Workspace<'gctx> {
12421237
analyze_cargo_lints_table(
12431238
pkg,
12441239
&path,
1245-
&normalized_lints,
1240+
&cargo_lints,
12461241
ws_cargo_lints,
12471242
ws_contents,
12481243
ws_document,
@@ -1252,23 +1247,23 @@ impl<'gctx> Workspace<'gctx> {
12521247
check_im_a_teapot(
12531248
pkg,
12541249
&path,
1255-
&normalized_lints,
1250+
&cargo_lints,
12561251
ws_cargo_lints,
12571252
&mut error_count,
12581253
self.gctx,
12591254
)?;
12601255
check_implicit_features(
12611256
pkg,
12621257
&path,
1263-
&normalized_lints,
1258+
&cargo_lints,
12641259
ws_cargo_lints,
12651260
&mut error_count,
12661261
self.gctx,
12671262
)?;
12681263
unused_dependencies(
12691264
pkg,
12701265
&path,
1271-
&normalized_lints,
1266+
&cargo_lints,
12721267
ws_cargo_lints,
12731268
&mut error_count,
12741269
self.gctx,

src/cargo/util/lints.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -117,31 +117,21 @@ fn verify_feature_enabled(
117117
gctx: &GlobalContext,
118118
) -> CargoResult<()> {
119119
if !manifest.unstable_features().is_enabled(feature_gate) {
120-
let dash_name = lint_name.replace("_", "-");
121120
let dash_feature_name = feature_gate.name().replace("_", "-");
122-
let title = format!("use of unstable lint `{}`", dash_name);
121+
let title = format!("use of unstable lint `{}`", lint_name);
123122
let label = format!(
124123
"this is behind `{}`, which is not enabled",
125124
dash_feature_name
126125
);
127-
let second_title = format!("`cargo::{}` was inherited", dash_name);
126+
let second_title = format!("`cargo::{}` was inherited", lint_name);
128127
let help = format!(
129128
"consider adding `cargo-features = [\"{}\"]` to the top of the manifest",
130129
dash_feature_name
131130
);
132131
let message = match reason {
133132
LintLevelReason::Package => {
134-
let span = get_span(
135-
manifest.document(),
136-
&["lints", "cargo", dash_name.as_str()],
137-
false,
138-
)
139-
.or(get_span(
140-
manifest.document(),
141-
&["lints", "cargo", lint_name],
142-
false,
143-
))
144-
.unwrap();
133+
let span =
134+
get_span(manifest.document(), &["lints", "cargo", lint_name], false).unwrap();
145135

146136
Level::Error
147137
.title(&title)
@@ -155,15 +145,10 @@ fn verify_feature_enabled(
155145
}
156146
LintLevelReason::Workspace => {
157147
let lint_span = get_span(
158-
ws_document,
159-
&["workspace", "lints", "cargo", dash_name.as_str()],
160-
false,
161-
)
162-
.or(get_span(
163148
ws_document,
164149
&["workspace", "lints", "cargo", lint_name],
165150
false,
166-
))
151+
)
167152
.unwrap();
168153
let inherit_span_key =
169154
get_span(manifest.document(), &["lints", "workspace"], false).unwrap();

tests/testsuite/lints/implicit_features/edition_2021_warn/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ baz = { version = "0.1.0", optional = true }
2727
target-dep = { version = "0.1.0", optional = true }
2828
2929
[lints.cargo]
30-
implicit-features = "warn"
30+
implicit_features = "warn"
3131
"#,
3232
)
3333
.file("src/lib.rs", "")

tests/testsuite/lints/implicit_features/edition_2024/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ baz = { version = "0.1.0", optional = true }
2525
baz = ["dep:baz"]
2626
2727
[lints.cargo]
28-
unused-optional-dependency = "allow"
28+
unused_optional_dependency = "allow"
2929
"#,
3030
)
3131
.file("src/lib.rs", "")

tests/testsuite/lints/unused_optional_dependencies/edition_2021/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ edition = "2021"
1919
bar = { version = "0.1.0", optional = true }
2020
2121
[lints.cargo]
22-
implicit-features = "allow"
22+
implicit_features = "allow"
2323
"#,
2424
)
2525
.file("src/lib.rs", "")

tests/testsuite/lints_table.rs

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -762,7 +762,6 @@ edition = "2015"
762762
authors = []
763763
764764
[lints.cargo]
765-
im-a-teapot = "warn"
766765
"#,
767766
)
768767
.file("src/lib.rs", "")
@@ -799,7 +798,6 @@ authors = []
799798
im-a-teapot = true
800799
801800
[lints.cargo]
802-
im-a-teapot = "warn"
803801
"#,
804802
)
805803
.file("src/lib.rs", "")
@@ -835,7 +833,7 @@ authors = []
835833
im-a-teapot = true
836834
837835
[lints.cargo]
838-
im-a-teapot = "warn"
836+
im_a_teapot = "warn"
839837
"#,
840838
)
841839
.file("src/lib.rs", "")
@@ -860,7 +858,7 @@ warning: `im_a_teapot` is specified
860858
}
861859

862860
#[cargo_test]
863-
fn cargo_lints_underscore_supported() {
861+
fn cargo_lints_dashes_dont_get_rewritten() {
864862
let foo = project()
865863
.file(
866864
"Cargo.toml",
@@ -875,7 +873,7 @@ authors = []
875873
im-a-teapot = true
876874
877875
[lints.cargo]
878-
im_a_teapot = "warn"
876+
im-a-teapot = "warn"
879877
"#,
880878
)
881879
.file("src/lib.rs", "")
@@ -885,13 +883,6 @@ im_a_teapot = "warn"
885883
.masquerade_as_nightly_cargo(&["cargo-lints", "test-dummy-unstable"])
886884
.with_stderr(
887885
"\
888-
warning: `im_a_teapot` is specified
889-
--> Cargo.toml:9:1
890-
|
891-
9 | im-a-teapot = true
892-
| ------------------
893-
|
894-
= note: `cargo::im_a_teapot` is set to `warn` in `[lints]`
895886
[CHECKING] foo v0.0.1 ([CWD])
896887
[FINISHED] [..]
897888
",
@@ -915,8 +906,8 @@ authors = []
915906
im-a-teapot = true
916907
917908
[lints.cargo]
918-
im-a-teapot = { level = "warn", priority = 10 }
919-
test-dummy-unstable = { level = "forbid", priority = -1 }
909+
im_a_teapot = { level = "warn", priority = 10 }
910+
test_dummy_unstable = { level = "forbid", priority = -1 }
920911
"#,
921912
)
922913
.file("src/lib.rs", "")
@@ -948,8 +939,8 @@ fn workspace_cargo_lints() {
948939
cargo-features = ["test-dummy-unstable"]
949940
950941
[workspace.lints.cargo]
951-
im-a-teapot = { level = "warn", priority = 10 }
952-
test-dummy-unstable = { level = "forbid", priority = -1 }
942+
im_a_teapot = { level = "warn", priority = 10 }
943+
test_dummy_unstable = { level = "forbid", priority = -1 }
953944
954945
[package]
955946
name = "foo"
@@ -992,7 +983,7 @@ fn dont_always_inherit_workspace_lints() {
992983
members = ["foo"]
993984
994985
[workspace.lints.cargo]
995-
im-a-teapot = "warn"
986+
im_a_teapot = "warn"
996987
"#,
997988
)
998989
.file(
@@ -1038,7 +1029,7 @@ edition = "2021"
10381029
baz = { version = "0.1.0", optional = true }
10391030
10401031
[lints.cargo]
1041-
implicit-features = "warn"
1032+
implicit_features = "warn"
10421033
"#,
10431034
)
10441035
.file("src/lib.rs", "")
@@ -1056,7 +1047,7 @@ edition = "2021"
10561047
bar = "0.1.0"
10571048
10581049
[lints.cargo]
1059-
implicit-features = "warn"
1050+
implicit_features = "warn"
10601051
"#,
10611052
)
10621053
.file("src/lib.rs", "")
@@ -1091,7 +1082,7 @@ edition = "2015"
10911082
authors = []
10921083
10931084
[lints.cargo]
1094-
im-a-teapot = "warn"
1085+
im_a_teapot = "warn"
10951086
"#,
10961087
)
10971088
.file("src/lib.rs", "")
@@ -1102,10 +1093,10 @@ im-a-teapot = "warn"
11021093
.with_status(101)
11031094
.with_stderr(
11041095
"\
1105-
error: use of unstable lint `im-a-teapot`
1096+
error: use of unstable lint `im_a_teapot`
11061097
--> Cargo.toml:9:1
11071098
|
1108-
9 | im-a-teapot = \"warn\"
1099+
9 | im_a_teapot = \"warn\"
11091100
| ^^^^^^^^^^^ this is behind `test-dummy-unstable`, which is not enabled
11101101
|
11111102
= help: consider adding `cargo-features = [\"test-dummy-unstable\"]` to the top of the manifest
@@ -1125,8 +1116,8 @@ fn check_feature_gated_workspace() {
11251116
members = ["foo"]
11261117
11271118
[workspace.lints.cargo]
1128-
im-a-teapot = { level = "warn", priority = 10 }
1129-
test-dummy-unstable = { level = "forbid", priority = -1 }
1119+
im_a_teapot = { level = "warn", priority = 10 }
1120+
test_dummy_unstable = { level = "forbid", priority = -1 }
11301121
"#,
11311122
)
11321123
.file(
@@ -1150,26 +1141,26 @@ workspace = true
11501141
.with_status(101)
11511142
.with_stderr(
11521143
"\
1153-
error: use of unstable lint `im-a-teapot`
1144+
error: use of unstable lint `im_a_teapot`
11541145
--> Cargo.toml:6:1
11551146
|
1156-
6 | im-a-teapot = { level = \"warn\", priority = 10 }
1147+
6 | im_a_teapot = { level = \"warn\", priority = 10 }
11571148
| ^^^^^^^^^^^ this is behind `test-dummy-unstable`, which is not enabled
11581149
|
1159-
note: `cargo::im-a-teapot` was inherited
1150+
note: `cargo::im_a_teapot` was inherited
11601151
--> foo/Cargo.toml:9:1
11611152
|
11621153
9 | workspace = true
11631154
| ----------------
11641155
|
11651156
= help: consider adding `cargo-features = [\"test-dummy-unstable\"]` to the top of the manifest
1166-
error: use of unstable lint `test-dummy-unstable`
1157+
error: use of unstable lint `test_dummy_unstable`
11671158
--> Cargo.toml:7:1
11681159
|
1169-
7 | test-dummy-unstable = { level = \"forbid\", priority = -1 }
1160+
7 | test_dummy_unstable = { level = \"forbid\", priority = -1 }
11701161
| ^^^^^^^^^^^^^^^^^^^ this is behind `test-dummy-unstable`, which is not enabled
11711162
|
1172-
note: `cargo::test-dummy-unstable` was inherited
1163+
note: `cargo::test_dummy_unstable` was inherited
11731164
--> foo/Cargo.toml:9:1
11741165
|
11751166
9 | workspace = true

0 commit comments

Comments
 (0)