Skip to content

Commit 663f2cf

Browse files
committed
Some fixes for wildcard_dependencies
1 parent d334fab commit 663f2cf

File tree

1 file changed

+13
-15
lines changed

1 file changed

+13
-15
lines changed

clippy_lints/src/wildcard_dependencies.rs

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
1111
use crate::rustc::{declare_tool_lint, lint_array};
1212
use crate::syntax::ast::*;
13+
use crate::syntax::source_map::DUMMY_SP;
1314
use crate::utils::span_lint;
1415

1516
use cargo_metadata;
16-
use lazy_static::lazy_static;
1717
use semver;
1818

19-
/// **What it does:** Checks to see if wildcard dependencies are being used.
19+
/// **What it does:** Checks for wildcard dependencies in the `Cargo.toml`.
2020
///
21-
/// **Why is this bad?** [As the edition guide sais](https://rust-lang-nursery.github.io/edition-guide/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.html),
21+
/// **Why is this bad?** [As the edition guide says](https://rust-lang-nursery.github.io/edition-guide/rust-2018/cargo-and-crates-io/crates-io-disallows-wildcard-dependencies.html),
2222
/// it is highly unlikely that you work with any possible version of your dependency,
2323
/// and wildcard dependencies would cause unnecessary breakage in the ecosystem.
2424
///
@@ -53,19 +53,17 @@ impl EarlyLintPass for Pass {
5353
return;
5454
};
5555

56-
lazy_static! {
57-
// VersionReq::any() does not work
58-
static ref WILDCARD_VERSION_REQ: semver::VersionReq = semver::VersionReq::parse("*").unwrap();
59-
}
60-
6156
for dep in &metadata.packages[0].dependencies {
62-
if dep.req == *WILDCARD_VERSION_REQ {
63-
span_lint(
64-
cx,
65-
WILDCARD_DEPENDENCIES,
66-
krate.span,
67-
&format!("wildcard dependency for `{}`", dep.name),
68-
);
57+
// VersionReq::any() does not work
58+
if let Ok(wildcard_ver) = semver::VersionReq::parse("*") {
59+
if dep.req == wildcard_ver {
60+
span_lint(
61+
cx,
62+
WILDCARD_DEPENDENCIES,
63+
DUMMY_SP,
64+
&format!("wildcard dependency for `{}`", dep.name),
65+
);
66+
}
6967
}
7068
}
7169
}

0 commit comments

Comments
 (0)