From 26e8558d8a7bb72f621696e36a02ea575574a69b Mon Sep 17 00:00:00 2001 From: Oliver Schneider Date: Tue, 24 Jan 2017 11:31:42 +0100 Subject: [PATCH] remove rustc-serialize dependency and factor `util::cargo` out into a crate --- Cargo.toml | 5 +- clippy_lints/Cargo.toml | 1 - clippy_lints/src/lib.rs | 2 - clippy_lints/src/utils/cargo.rs | 77 -------------------------- clippy_lints/src/utils/mod.rs | 1 - src/main.rs | 6 +- tests/compile-fail/serde.rs | 21 +++++-- tests/used_underscore_binding_macro.rs | 4 +- tests/versioncheck.rs | 7 +-- 9 files changed, 25 insertions(+), 99 deletions(-) delete mode 100644 clippy_lints/src/utils/cargo.rs diff --git a/Cargo.toml b/Cargo.toml index 98f71d01e..a21a4a658 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,14 +32,15 @@ test = false # begin automatic update clippy_lints = { version = "0.0.111", path = "clippy_lints" } # end automatic update +cargo_metadata = "0.1" [dev-dependencies] compiletest_rs = "0.2.5" lazy_static = "0.1.15" regex = "0.2" -rustc-serialize = "0.3" +serde_derive = "0.9.0-rc3" clippy-mini-macro-test = { version = "0.1", path = "mini-macro" } -serde = "0.7" +serde = "0.9.0-rc3" [features] debugging = [] diff --git a/clippy_lints/Cargo.toml b/clippy_lints/Cargo.toml index 9a5ea23e6..fb147b2a1 100644 --- a/clippy_lints/Cargo.toml +++ b/clippy_lints/Cargo.toml @@ -22,7 +22,6 @@ semver = "0.2.1" toml = "0.2" unicode-normalization = "0.1" quine-mc_cluskey = "0.2.2" -rustc-serialize = "0.3" [features] debugging = [] diff --git a/clippy_lints/src/lib.rs b/clippy_lints/src/lib.rs index 0d797c567..2b778e12c 100644 --- a/clippy_lints/src/lib.rs +++ b/clippy_lints/src/lib.rs @@ -38,8 +38,6 @@ extern crate regex_syntax; // for finding minimal boolean expressions extern crate quine_mc_cluskey; -extern crate rustc_serialize; - extern crate rustc_errors; extern crate rustc_plugin; extern crate rustc_const_eval; diff --git a/clippy_lints/src/utils/cargo.rs b/clippy_lints/src/utils/cargo.rs deleted file mode 100644 index b9ce8626e..000000000 --- a/clippy_lints/src/utils/cargo.rs +++ /dev/null @@ -1,77 +0,0 @@ -use std::collections::HashMap; -use std::process::Command; -use std::str::{from_utf8, Utf8Error}; -use std::io; -use rustc_serialize::json; - -#[derive(RustcDecodable, Debug)] -pub struct Metadata { - pub packages: Vec, - resolve: Option<()>, - pub version: usize, -} - -#[derive(RustcDecodable, Debug)] -pub struct Package { - pub name: String, - pub version: String, - id: String, - source: Option, - pub dependencies: Vec, - pub targets: Vec, - features: HashMap>, - pub manifest_path: String, -} - -#[derive(RustcDecodable, Debug)] -pub struct Dependency { - pub name: String, - source: Option, - pub req: String, - kind: Option, - optional: bool, - uses_default_features: bool, - features: Vec, - target: Option, -} - -#[derive(RustcDecodable, Debug)] -pub struct Target { - pub name: String, - pub kind: Vec, - src_path: String, -} - -#[derive(Debug)] -pub enum Error { - Io(io::Error), - Utf8(Utf8Error), - Json(json::DecoderError), -} - -impl From for Error { - fn from(err: io::Error) -> Self { - Error::Io(err) - } -} -impl From for Error { - fn from(err: Utf8Error) -> Self { - Error::Utf8(err) - } -} -impl From for Error { - fn from(err: json::DecoderError) -> Self { - Error::Json(err) - } -} - -pub fn metadata(manifest_path_arg: Option<&str>) -> Result { - let mut cmd = Command::new("cargo"); - cmd.arg("metadata").arg("--no-deps"); - if let Some(mani) = manifest_path_arg { - cmd.arg(mani); - } - let output = cmd.output()?; - let stdout = from_utf8(&output.stdout)?; - Ok(json::decode(stdout)?) -} diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index d453a9095..ef9c6b9c3 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -21,7 +21,6 @@ use syntax::errors::DiagnosticBuilder; use syntax::ptr::P; use syntax::symbol::keywords; -pub mod cargo; pub mod comparisons; pub mod conf; pub mod constants; diff --git a/src/main.rs b/src/main.rs index 036adae83..1be98cbeb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,7 +21,7 @@ use std::process::{self, Command}; use syntax::ast; use std::io::{self, Write}; -use clippy_lints::utils::cargo; +extern crate cargo_metadata; struct ClippyCompilerCalls { default: RustcDefaultCalls, @@ -179,15 +179,13 @@ pub fn main() { let manifest_path_arg = std::env::args().skip(2).find(|val| val.starts_with("--manifest-path=")); - let mut metadata = if let Ok(metadata) = cargo::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)) { + let mut metadata = if let Ok(metadata) = cargo_metadata::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)) { metadata } else { let _ = io::stderr().write_fmt(format_args!("error: Could not obtain cargo metadata.")); process::exit(101); }; - assert_eq!(metadata.version, 1); - let manifest_path = manifest_path_arg.map(|arg| PathBuf::from(Path::new(&arg["--manifest-path=".len()..]))); let current_dir = std::env::current_dir(); diff --git a/tests/compile-fail/serde.rs b/tests/compile-fail/serde.rs index d5099edbc..a0671f071 100644 --- a/tests/compile-fail/serde.rs +++ b/tests/compile-fail/serde.rs @@ -9,14 +9,19 @@ struct A; impl serde::de::Visitor for A { type Value = (); - fn visit_str(&mut self, _v: &str) -> Result - where E: serde::Error, + + fn expecting(&self, _: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + unimplemented!() + } + + fn visit_str(self, _v: &str) -> Result + where E: serde::de::Error, { unimplemented!() } - fn visit_string(&mut self, _v: String) -> Result - where E: serde::Error, + fn visit_string(self, _v: String) -> Result + where E: serde::de::Error, { unimplemented!() } @@ -27,9 +32,13 @@ struct B; impl serde::de::Visitor for B { type Value = (); - fn visit_string(&mut self, _v: String) -> Result + fn expecting(&self, _: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + unimplemented!() + } + + fn visit_string(self, _v: String) -> Result //~^ ERROR you should not implement `visit_string` without also implementing `visit_str` - where E: serde::Error, + where E: serde::de::Error, { unimplemented!() } diff --git a/tests/used_underscore_binding_macro.rs b/tests/used_underscore_binding_macro.rs index 9cd44d440..c7da8e4f9 100644 --- a/tests/used_underscore_binding_macro.rs +++ b/tests/used_underscore_binding_macro.rs @@ -1,11 +1,11 @@ #![feature(plugin)] #![plugin(clippy)] -extern crate rustc_serialize; +#[macro_use] extern crate serde_derive; /// Test that we do not lint for unused underscores in a `MacroAttribute` expansion #[deny(used_underscore_binding)] -#[derive(RustcEncodable)] +#[derive(Deserialize)] struct MacroAttributesTest { _foo: u32, } diff --git a/tests/versioncheck.rs b/tests/versioncheck.rs index e216c8015..beea9ab7e 100644 --- a/tests/versioncheck.rs +++ b/tests/versioncheck.rs @@ -1,11 +1,10 @@ -extern crate clippy_lints; -use clippy_lints::utils::cargo; +extern crate cargo_metadata; #[test] fn check_that_clippy_lints_has_the_same_version_as_clippy() { - let clippy_meta = cargo::metadata(None).expect("could not obtain cargo metadata"); + let clippy_meta = cargo_metadata::metadata(None).expect("could not obtain cargo metadata"); std::env::set_current_dir(std::env::current_dir().unwrap().join("clippy_lints")).unwrap(); - let clippy_lints_meta = cargo::metadata(None).expect("could not obtain cargo metadata"); + let clippy_lints_meta = cargo_metadata::metadata(None).expect("could not obtain cargo metadata"); assert_eq!(clippy_lints_meta.packages[0].version, clippy_meta.packages[0].version); for package in &clippy_meta.packages[0].dependencies { if package.name == "clippy_lints" {