|
10 | 10 | use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
|
11 | 11 | use crate::rustc::{declare_tool_lint, lint_array};
|
12 | 12 | use crate::syntax::ast::*;
|
| 13 | +use crate::syntax::source_map::DUMMY_SP; |
13 | 14 | use crate::utils::span_lint;
|
14 | 15 |
|
15 | 16 | use cargo_metadata;
|
16 |
| -use lazy_static::lazy_static; |
17 | 17 | use semver;
|
18 | 18 |
|
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`. |
20 | 20 | ///
|
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), |
22 | 22 | /// it is highly unlikely that you work with any possible version of your dependency,
|
23 | 23 | /// and wildcard dependencies would cause unnecessary breakage in the ecosystem.
|
24 | 24 | ///
|
@@ -53,19 +53,17 @@ impl EarlyLintPass for Pass {
|
53 | 53 | return;
|
54 | 54 | };
|
55 | 55 |
|
56 |
| - lazy_static! { |
57 |
| - // VersionReq::any() does not work |
58 |
| - static ref WILDCARD_VERSION_REQ: semver::VersionReq = semver::VersionReq::parse("*").unwrap(); |
59 |
| - } |
60 |
| - |
61 | 56 | 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 | + } |
69 | 67 | }
|
70 | 68 | }
|
71 | 69 | }
|
|
0 commit comments