]> git.lizzy.rs Git - rust.git/commitdiff
Some fixes for wildcard_dependencies
authorHidehito Yabuuchi <hdht.ybuc@gmail.com>
Wed, 24 Oct 2018 11:18:19 +0000 (20:18 +0900)
committerHidehito Yabuuchi <hdht.ybuc@gmail.com>
Wed, 24 Oct 2018 11:19:13 +0000 (20:19 +0900)
clippy_lints/src/wildcard_dependencies.rs

index e02501005e2ba05388e888b903db5675f84746ed..00533efb8e5e56fa009f8d0143c8022d131db307 100644 (file)
 use crate::rustc::lint::{EarlyContext, EarlyLintPass, LintArray, LintPass};
 use crate::rustc::{declare_tool_lint, lint_array};
 use crate::syntax::ast::*;
+use crate::syntax::source_map::DUMMY_SP;
 use crate::utils::span_lint;
 
 use cargo_metadata;
-use lazy_static::lazy_static;
 use semver;
 
-/// **What it does:** Checks to see if wildcard dependencies are being used.
+/// **What it does:** Checks for wildcard dependencies in the `Cargo.toml`.
 ///
-/// **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),
+/// **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),
 /// it is highly unlikely that you work with any possible version of your dependency,
 /// and wildcard dependencies would cause unnecessary breakage in the ecosystem.
 ///
@@ -53,19 +53,17 @@ fn check_crate(&mut self, cx: &EarlyContext<'_>, krate: &Crate) {
             return;
         };
 
-        lazy_static! {
-            // VersionReq::any() does not work
-            static ref WILDCARD_VERSION_REQ: semver::VersionReq = semver::VersionReq::parse("*").unwrap();
-        }
-
         for dep in &metadata.packages[0].dependencies {
-            if dep.req == *WILDCARD_VERSION_REQ {
-                span_lint(
-                    cx,
-                    WILDCARD_DEPENDENCIES,
-                    krate.span,
-                    &format!("wildcard dependency for `{}`", dep.name),
-                );
+            // VersionReq::any() does not work
+            if let Ok(wildcard_ver) = semver::VersionReq::parse("*") {
+                if dep.req == wildcard_ver {
+                    span_lint(
+                        cx,
+                        WILDCARD_DEPENDENCIES,
+                        DUMMY_SP,
+                        &format!("wildcard dependency for `{}`", dep.name),
+                    );
+                }
             }
         }
     }