Skip to content

Commit bb2d497

Browse files
committed
Auto merge of #12146 - kristof-mattei:multiple-crate-versions-with-dashes, r=Manishearth
Fix [`multiple_crate_versions`] to correctly normalize package names to avoid missing the local one Fixes #12145 changelog: [`multiple_crate_versions`]: correctly normalize package name
2 parents 2067fe4 + e8ec998 commit bb2d497

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

clippy_lints/src/cargo/multiple_crate_versions.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ pub(super) fn check(cx: &LateContext<'_>, metadata: &Metadata) {
1616

1717
if let Some(resolve) = &metadata.resolve
1818
&& let Some(local_id) = packages.iter().find_map(|p| {
19-
if p.name == local_name.as_str() {
19+
// p.name contains the original crate names with dashes intact
20+
// local_name contains the crate name as a namespace, with the dashes converted to underscores
21+
// the code below temporarily rectifies this discrepancy
22+
if p.name
23+
.as_bytes()
24+
.iter()
25+
.map(|b| if b == &b'-' { &b'_' } else { b })
26+
.eq(local_name.as_str().as_bytes())
27+
{
2028
Some(&p.id)
2129
} else {
2230
None
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
error: multiple versions for dependency `winapi`: 0.2.8, 0.3.9
2+
|
3+
= note: `-D clippy::multiple-crate-versions` implied by `-D warnings`
4+
= help: to override `-D warnings` add `#[allow(clippy::multiple_crate_versions)]`
5+
6+
error: could not compile `multiple-crate-versions` (bin "multiple-crate-versions") due to 1 previous error
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Should not lint for dev or build dependencies. See issue 5041.
2+
3+
[package]
4+
# purposefully separated by - instead of _
5+
name = "multiple-crate-versions"
6+
version = "0.1.0"
7+
publish = false
8+
9+
[workspace]
10+
11+
# One of the versions of winapi is only a dev dependency: allowed
12+
[dependencies]
13+
winapi = "0.2"
14+
ansi_term = "=0.11.0"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#![warn(clippy::multiple_crate_versions)]
2+
3+
fn main() {}

0 commit comments

Comments
 (0)