Skip to content

Commit 7aac7f8

Browse files
committed
fix(implicit_features): Work with any dep table
1 parent 301010a commit 7aac7f8

File tree

3 files changed

+45
-16
lines changed

3 files changed

+45
-16
lines changed

src/cargo/util/lints.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,18 @@ pub fn check_implicit_features(
192192
if lint_level == LintLevel::Forbid || lint_level == LintLevel::Deny {
193193
*error_count += 1;
194194
}
195+
let mut toml_path = vec![dep.kind().kind_table(), dep_name_in_toml.as_str()];
196+
let platform = dep.platform().map(|p| p.to_string());
197+
if let Some(platform) = platform.as_ref() {
198+
toml_path.insert(0, platform);
199+
toml_path.insert(0, "target");
200+
}
195201
let level = lint_level.to_diagnostic_level();
196202
let manifest_path = rel_cwd_manifest_path(path, gctx);
197203
let message = level.title(IMPLICIT_FEATURES.desc).snippet(
198204
Snippet::source(manifest.contents())
199205
.origin(&manifest_path)
200-
.annotation(
201-
level.span(
202-
get_span(
203-
manifest.document(),
204-
&["dependencies", &dep_name_in_toml],
205-
false,
206-
)
207-
.unwrap(),
208-
),
209-
)
206+
.annotation(level.span(get_span(manifest.document(), &toml_path, false).unwrap()))
210207
.fold(true),
211208
);
212209
let renderer = Renderer::styled().term_width(

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ use cargo_test_support::{file, project};
66
#[cargo_test]
77
fn case() {
88
Package::new("bar", "0.1.0").publish();
9+
Package::new("baz", "0.1.0").publish();
10+
Package::new("target-dep", "0.1.0").publish();
911
let p = project()
1012
.file(
1113
"Cargo.toml",
@@ -18,6 +20,12 @@ edition = "2021"
1820
[dependencies]
1921
bar = { version = "0.1.0", optional = true }
2022
23+
[build-dependencies]
24+
baz = { version = "0.1.0", optional = true }
25+
26+
[target.'cfg(target_os = "linux")'.dependencies]
27+
target-dep = { version = "0.1.0", optional = true }
28+
2129
[lints.cargo]
2230
implicit-features = "warn"
2331
"#,

tests/testsuite/lints/implicit_features/edition_2021_warn/stderr.term.svg

Lines changed: 30 additions & 6 deletions
Loading

0 commit comments

Comments
 (0)