Update dependencies

This commit is contained in:
Oliver Schneider 2018-03-13 15:02:40 +01:00
parent 5296c52307
commit 21f387d278
No known key found for this signature in database
GPG key ID: A69F8D225B3AD7D9
8 changed files with 122 additions and 77 deletions

1
.gitignore vendored
View file

@ -16,6 +16,7 @@ out
Cargo.lock Cargo.lock
/target /target
/clippy_lints/target /clippy_lints/target
/clippy_workspace_tests/target
# Generated by dogfood # Generated by dogfood
/target_recur/ /target_recur/

View file

@ -39,8 +39,9 @@ path = "src/driver.rs"
# begin automatic update # begin automatic update
clippy_lints = { version = "0.0.187", path = "clippy_lints" } clippy_lints = { version = "0.0.187", path = "clippy_lints" }
# end automatic update # end automatic update
cargo_metadata = "0.2" cargo_metadata = "0.5"
regex = "0.2" regex = "0.2"
semver = "0.9"
[dev-dependencies] [dev-dependencies]
compiletest_rs = "0.3.7" compiletest_rs = "0.3.7"

View file

@ -16,18 +16,18 @@ license = "MPL-2.0"
keywords = ["clippy", "lint", "plugin"] keywords = ["clippy", "lint", "plugin"]
[dependencies] [dependencies]
itertools = "0.6.0" itertools = "0.7"
lazy_static = "1.0" lazy_static = "1.0"
matches = "0.1.2" matches = "0.1.2"
quine-mc_cluskey = "0.2.2" quine-mc_cluskey = "0.2.2"
regex-syntax = "0.4.0" regex-syntax = "0.5.0"
semver = "0.6.0" semver = "0.9.0"
serde = "1.0" serde = "1.0"
serde_derive = "1.0" serde_derive = "1.0"
toml = "0.4" toml = "0.4"
unicode-normalization = "0.1" unicode-normalization = "0.1"
pulldown-cmark = "0.0.15" pulldown-cmark = "0.1"
url = "1.5.0" url = "1.7.0"
if_chain = "0.1" if_chain = "0.1"
[features] [features]

View file

@ -6,7 +6,6 @@ use rustc::middle::const_val::ConstVal;
use rustc_const_eval::ConstContext; use rustc_const_eval::ConstContext;
use rustc::ty::subst::Substs; use rustc::ty::subst::Substs;
use std::collections::HashSet; use std::collections::HashSet;
use std::error::Error;
use syntax::ast::{LitKind, NodeId, StrStyle}; use syntax::ast::{LitKind, NodeId, StrStyle};
use syntax::codemap::{BytePos, Span}; use syntax::codemap::{BytePos, Span};
use syntax::symbol::InternedString; use syntax::symbol::InternedString;
@ -134,16 +133,12 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
} }
} }
#[allow(cast_possible_truncation)] fn str_span(base: Span, c: regex_syntax::ast::Span, offset: usize) -> Span {
fn str_span(base: Span, s: &str, c: usize) -> Span { let offset = offset as u32;
let mut si = s.char_indices().skip(c); let end = base.lo() + BytePos(c.end.offset as u32 + offset);
let start = base.lo() + BytePos(c.start.offset as u32 + offset);
match (si.next(), si.next()) { assert!(start <= end);
(Some((l, _)), Some((h, _))) => { Span::new(start, end, base.ctxt())
Span::new(base.lo() + BytePos(l as u32), base.lo() + BytePos(h as u32), base.ctxt())
},
_ => base,
}
} }
fn const_str<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) -> Option<InternedString> { fn const_str<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) -> Option<InternedString> {
@ -159,24 +154,30 @@ fn const_str<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, e: &'tcx Expr) -> Option<Inte
} }
} }
fn is_trivial_regex(s: &regex_syntax::Expr) -> Option<&'static str> { fn is_trivial_regex(s: &regex_syntax::hir::Hir) -> Option<&'static str> {
use regex_syntax::Expr; use regex_syntax::hir::HirKind::*;
use regex_syntax::hir::Anchor::*;
match *s { let is_literal = |e: &[regex_syntax::hir::Hir]| e.iter().all(|e| match *e.kind() {
Expr::Empty | Expr::StartText | Expr::EndText => Some("the regex is unlikely to be useful as it is"), Literal(_) => true,
Expr::Literal { .. } => Some("consider using `str::contains`"), _ => false,
Expr::Concat(ref exprs) => match exprs.len() { });
2 => match (&exprs[0], &exprs[1]) {
(&Expr::StartText, &Expr::EndText) => Some("consider using `str::is_empty`"), match *s.kind() {
(&Expr::StartText, &Expr::Literal { .. }) => Some("consider using `str::starts_with`"), Empty |
(&Expr::Literal { .. }, &Expr::EndText) => Some("consider using `str::ends_with`"), Anchor(_) => Some("the regex is unlikely to be useful as it is"),
_ => None, Literal(_) => Some("consider using `str::contains`"),
}, Alternation(ref exprs) => if exprs.iter().all(|e| e.kind().is_empty()) {
3 => if let (&Expr::StartText, &Expr::Literal { .. }, &Expr::EndText) = (&exprs[0], &exprs[1], &exprs[2]) { Some("the regex is unlikely to be useful as it is")
Some("consider using `==` on `str`s") } else {
} else { None
None },
}, Concat(ref exprs) => match (exprs[0].kind(), exprs[exprs.len() - 1].kind()) {
(&Anchor(StartText), &Anchor(EndText)) if exprs[1..(exprs.len() - 1)].is_empty() => Some("consider using `str::is_empty`"),
(&Anchor(StartText), &Anchor(EndText)) if is_literal(&exprs[1..(exprs.len() - 1)]) => Some("consider using `==` on `str`s"),
(&Anchor(StartText), &Literal(_)) if is_literal(&exprs[1..]) => Some("consider using `str::starts_with`"),
(&Literal(_), &Anchor(EndText)) if is_literal(&exprs[1..(exprs.len() - 1)]) => Some("consider using `str::ends_with`"),
_ if is_literal(exprs) => Some("consider using `str::contains`"),
_ => None, _ => None,
}, },
_ => None, _ => None,
@ -196,41 +197,73 @@ fn check_set<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, utf8: bool)
} }
fn check_regex<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, utf8: bool) { fn check_regex<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, utf8: bool) {
let builder = regex_syntax::ExprBuilder::new().unicode(utf8); let mut parser = regex_syntax::ParserBuilder::new().unicode(utf8).build();
if let ExprLit(ref lit) = expr.node { if let ExprLit(ref lit) = expr.node {
if let LitKind::Str(ref r, style) = lit.node { if let LitKind::Str(ref r, style) = lit.node {
let r = &r.as_str(); let r = &r.as_str();
let offset = if let StrStyle::Raw(n) = style { 1 + n } else { 0 }; let offset = if let StrStyle::Raw(n) = style { 2 + n } else { 1 };
match builder.parse(r) { match parser.parse(r) {
Ok(r) => if let Some(repl) = is_trivial_regex(&r) { Ok(r) => if let Some(repl) = is_trivial_regex(&r) {
span_help_and_lint( span_help_and_lint(
cx, cx,
TRIVIAL_REGEX, TRIVIAL_REGEX,
expr.span, expr.span,
"trivial regex", "trivial regex",
&format!("consider using {}", repl), repl,
);
},
Err(regex_syntax::Error::Parse(e)) => {
span_lint(
cx,
INVALID_REGEX,
str_span(expr.span, *e.span(), offset),
&format!("regex syntax error: {}", e.kind()),
);
},
Err(regex_syntax::Error::Translate(e)) => {
span_lint(
cx,
INVALID_REGEX,
str_span(expr.span, *e.span(), offset),
&format!("regex syntax error: {}", e.kind()),
); );
}, },
Err(e) => { Err(e) => {
span_lint( span_lint(
cx, cx,
INVALID_REGEX, INVALID_REGEX,
str_span(expr.span, r, e.position() + offset), expr.span,
&format!("regex syntax error: {}", e.description()), &format!("regex syntax error: {}", e),
); );
}, },
} }
} }
} else if let Some(r) = const_str(cx, expr) { } else if let Some(r) = const_str(cx, expr) {
match builder.parse(&r) { match parser.parse(&r) {
Ok(r) => if let Some(repl) = is_trivial_regex(&r) { Ok(r) => if let Some(repl) = is_trivial_regex(&r) {
span_help_and_lint( span_help_and_lint(
cx, cx,
TRIVIAL_REGEX, TRIVIAL_REGEX,
expr.span, expr.span,
"trivial regex", "trivial regex",
&format!("consider using {}", repl), repl,
);
},
Err(regex_syntax::Error::Parse(e)) => {
span_lint(
cx,
INVALID_REGEX,
expr.span,
&format!("regex syntax error on position {}: {}", e.span().start.offset, e.kind()),
);
},
Err(regex_syntax::Error::Translate(e)) => {
span_lint(
cx,
INVALID_REGEX,
expr.span,
&format!("regex syntax error on position {}: {}", e.span().start.offset, e.kind()),
); );
}, },
Err(e) => { Err(e) => {
@ -238,7 +271,7 @@ fn check_regex<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, expr: &'tcx Expr, utf8: boo
cx, cx,
INVALID_REGEX, INVALID_REGEX,
expr.span, expr.span,
&format!("regex syntax error on position {}: {}", e.position(), e.description()), &format!("regex syntax error: {}", e),
); );
}, },
} }

View file

@ -9,7 +9,7 @@ use std::io::{self, Write};
extern crate cargo_metadata; extern crate cargo_metadata;
use std::path::Path; use std::path::{Path, PathBuf};
const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code. const CARGO_CLIPPY_HELP: &str = r#"Checks a package to catch common mistakes and improve your Rust code.
@ -61,17 +61,19 @@ pub fn main() {
let manifest_path_arg = std::env::args() let manifest_path_arg = std::env::args()
.skip(2) .skip(2)
.find(|val| val.starts_with("--manifest-path=")); .find(|val| val.starts_with("--manifest-path="))
.map(|val| val["--manifest-path=".len()..].to_owned());
let mut metadata = if let Ok(metadata) = cargo_metadata::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 metadata
} else { } else {
println!("{:?}", cargo_metadata::metadata(manifest_path_arg.as_ref().map(AsRef::as_ref)));
let _ = io::stderr().write_fmt(format_args!("error: Could not obtain cargo metadata.\n")); let _ = io::stderr().write_fmt(format_args!("error: Could not obtain cargo metadata.\n"));
process::exit(101); process::exit(101);
}; };
let manifest_path = manifest_path_arg.map(|arg| { let manifest_path = manifest_path_arg.map(|arg| {
Path::new(&arg["--manifest-path=".len()..]) PathBuf::from(arg)
.canonicalize() .canonicalize()
.expect("manifest path could not be canonicalized") .expect("manifest path could not be canonicalized")
}); });

View file

@ -68,7 +68,7 @@ fn run_mode(dir: &'static str, mode: &'static str) {
fn prepare_env() { fn prepare_env() {
set_var("CLIPPY_DISABLE_DOCS_LINKS", "true"); set_var("CLIPPY_DISABLE_DOCS_LINKS", "true");
set_var("CLIPPY_TESTS", "true"); set_var("CLIPPY_TESTS", "true");
set_var("RUST_BACKTRACE", "0"); //set_var("RUST_BACKTRACE", "0");
} }
#[test] #[test]

View file

@ -1,60 +1,67 @@
error: regex syntax error: empty alternate error: trivial regex
--> $DIR/regex.rs:16:45 --> $DIR/regex.rs:16:45
| |
16 | let pipe_in_wrong_position = Regex::new("|"); 16 | let pipe_in_wrong_position = Regex::new("|");
| ^^^ | ^^^
| |
= note: `-D invalid-regex` implied by `-D warnings` = note: `-D trivial-regex` implied by `-D warnings`
= help: the regex is unlikely to be useful as it is
error: regex syntax error: empty alternate error: trivial regex
--> $DIR/regex.rs:17:60 --> $DIR/regex.rs:17:60
| |
17 | let pipe_in_wrong_position_builder = RegexBuilder::new("|"); 17 | let pipe_in_wrong_position_builder = RegexBuilder::new("|");
| ^^^ | ^^^
|
= help: the regex is unlikely to be useful as it is
error: regex syntax error: invalid character class range error: regex syntax error: invalid character class range, the start must be <= the end
--> $DIR/regex.rs:18:40 --> $DIR/regex.rs:18:42
| |
18 | let wrong_char_ranice = Regex::new("[z-a]"); 18 | let wrong_char_ranice = Regex::new("[z-a]");
| ^^^^^^^ | ^^^
|
= note: `-D invalid-regex` implied by `-D warnings`
error: regex syntax error: invalid character class range error: regex syntax error: invalid character class range, the start must be <= the end
--> $DIR/regex.rs:19:35 --> $DIR/regex.rs:19:37
| |
19 | let some_unicode = Regex::new("[é-è]"); 19 | let some_unicode = Regex::new("[é-è]");
| ^^^^^^^ | ^^^
error: regex syntax error on position 0: unclosed parenthesis error: regex syntax error on position 0: unclosed group
--> $DIR/regex.rs:21:33 --> $DIR/regex.rs:21:33
| |
21 | let some_regex = Regex::new(OPENING_PAREN); 21 | let some_regex = Regex::new(OPENING_PAREN);
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: regex syntax error: empty alternate error: trivial regex
--> $DIR/regex.rs:23:53 --> $DIR/regex.rs:23:53
| |
23 | let binary_pipe_in_wrong_position = BRegex::new("|"); 23 | let binary_pipe_in_wrong_position = BRegex::new("|");
| ^^^ | ^^^
|
= help: the regex is unlikely to be useful as it is
error: regex syntax error on position 0: unclosed parenthesis error: regex syntax error on position 0: unclosed group
--> $DIR/regex.rs:24:41 --> $DIR/regex.rs:24:41
| |
24 | let some_binary_regex = BRegex::new(OPENING_PAREN); 24 | let some_binary_regex = BRegex::new(OPENING_PAREN);
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: regex syntax error on position 0: unclosed parenthesis error: regex syntax error on position 0: unclosed group
--> $DIR/regex.rs:25:56 --> $DIR/regex.rs:25:56
| |
25 | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN); 25 | let some_binary_regex_builder = BRegexBuilder::new(OPENING_PAREN);
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: regex syntax error on position 0: unclosed parenthesis error: regex syntax error on position 0: unclosed group
--> $DIR/regex.rs:40:9 --> $DIR/regex.rs:40:9
| |
40 | OPENING_PAREN, 40 | OPENING_PAREN,
| ^^^^^^^^^^^^^ | ^^^^^^^^^^^^^
error: regex syntax error on position 0: unclosed parenthesis error: regex syntax error on position 0: unclosed group
--> $DIR/regex.rs:44:9 --> $DIR/regex.rs:44:9
| |
44 | OPENING_PAREN, 44 | OPENING_PAREN,
@ -64,13 +71,13 @@ error: regex syntax error: unrecognized escape sequence
--> $DIR/regex.rs:48:45 --> $DIR/regex.rs:48:45
| |
48 | let raw_string_error = Regex::new(r"[...//...]"); 48 | let raw_string_error = Regex::new(r"[...//...]");
| ^ | ^^
error: regex syntax error: unrecognized escape sequence error: regex syntax error: unrecognized escape sequence
--> $DIR/regex.rs:49:46 --> $DIR/regex.rs:49:46
| |
49 | let raw_string_error = Regex::new(r#"[...//...]"#); 49 | let raw_string_error = Regex::new(r#"[...//...]"#);
| ^ | ^^
error: trivial regex error: trivial regex
--> $DIR/regex.rs:53:33 --> $DIR/regex.rs:53:33
@ -78,8 +85,7 @@ error: trivial regex
53 | let trivial_eq = Regex::new("^foobar$"); 53 | let trivial_eq = Regex::new("^foobar$");
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= note: `-D trivial-regex` implied by `-D warnings` = help: consider using `==` on `str`s
= help: consider using consider using `==` on `str`s
error: trivial regex error: trivial regex
--> $DIR/regex.rs:55:48 --> $DIR/regex.rs:55:48
@ -87,7 +93,7 @@ error: trivial regex
55 | let trivial_eq_builder = RegexBuilder::new("^foobar$"); 55 | let trivial_eq_builder = RegexBuilder::new("^foobar$");
| ^^^^^^^^^^ | ^^^^^^^^^^
| |
= help: consider using consider using `==` on `str`s = help: consider using `==` on `str`s
error: trivial regex error: trivial regex
--> $DIR/regex.rs:57:42 --> $DIR/regex.rs:57:42
@ -95,7 +101,7 @@ error: trivial regex
57 | let trivial_starts_with = Regex::new("^foobar"); 57 | let trivial_starts_with = Regex::new("^foobar");
| ^^^^^^^^^ | ^^^^^^^^^
| |
= help: consider using consider using `str::starts_with` = help: consider using `str::starts_with`
error: trivial regex error: trivial regex
--> $DIR/regex.rs:59:40 --> $DIR/regex.rs:59:40
@ -103,7 +109,7 @@ error: trivial regex
59 | let trivial_ends_with = Regex::new("foobar$"); 59 | let trivial_ends_with = Regex::new("foobar$");
| ^^^^^^^^^ | ^^^^^^^^^
| |
= help: consider using consider using `str::ends_with` = help: consider using `str::ends_with`
error: trivial regex error: trivial regex
--> $DIR/regex.rs:61:39 --> $DIR/regex.rs:61:39
@ -111,7 +117,7 @@ error: trivial regex
61 | let trivial_contains = Regex::new("foobar"); 61 | let trivial_contains = Regex::new("foobar");
| ^^^^^^^^ | ^^^^^^^^
| |
= help: consider using consider using `str::contains` = help: consider using `str::contains`
error: trivial regex error: trivial regex
--> $DIR/regex.rs:63:39 --> $DIR/regex.rs:63:39
@ -119,7 +125,7 @@ error: trivial regex
63 | let trivial_contains = Regex::new(NOT_A_REAL_REGEX); 63 | let trivial_contains = Regex::new(NOT_A_REAL_REGEX);
| ^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^
| |
= help: consider using consider using `str::contains` = help: consider using `str::contains`
error: trivial regex error: trivial regex
--> $DIR/regex.rs:65:40 --> $DIR/regex.rs:65:40
@ -127,7 +133,7 @@ error: trivial regex
65 | let trivial_backslash = Regex::new("a/.b"); 65 | let trivial_backslash = Regex::new("a/.b");
| ^^^^^^^ | ^^^^^^^
| |
= help: consider using consider using `str::contains` = help: consider using `str::contains`
error: trivial regex error: trivial regex
--> $DIR/regex.rs:68:36 --> $DIR/regex.rs:68:36
@ -135,7 +141,7 @@ error: trivial regex
68 | let trivial_empty = Regex::new(""); 68 | let trivial_empty = Regex::new("");
| ^^ | ^^
| |
= help: consider using the regex is unlikely to be useful as it is = help: the regex is unlikely to be useful as it is
error: trivial regex error: trivial regex
--> $DIR/regex.rs:70:36 --> $DIR/regex.rs:70:36
@ -143,7 +149,7 @@ error: trivial regex
70 | let trivial_empty = Regex::new("^"); 70 | let trivial_empty = Regex::new("^");
| ^^^ | ^^^
| |
= help: consider using the regex is unlikely to be useful as it is = help: the regex is unlikely to be useful as it is
error: trivial regex error: trivial regex
--> $DIR/regex.rs:72:36 --> $DIR/regex.rs:72:36
@ -151,7 +157,7 @@ error: trivial regex
72 | let trivial_empty = Regex::new("^$"); 72 | let trivial_empty = Regex::new("^$");
| ^^^^ | ^^^^
| |
= help: consider using consider using `str::is_empty` = help: consider using `str::is_empty`
error: trivial regex error: trivial regex
--> $DIR/regex.rs:74:44 --> $DIR/regex.rs:74:44
@ -159,7 +165,7 @@ error: trivial regex
74 | let binary_trivial_empty = BRegex::new("^$"); 74 | let binary_trivial_empty = BRegex::new("^$");
| ^^^^ | ^^^^
| |
= help: consider using consider using `str::is_empty` = help: consider using `str::is_empty`
error: aborting due to 23 previous errors error: aborting due to 23 previous errors

View file

@ -1,4 +1,6 @@
extern crate cargo_metadata; extern crate cargo_metadata;
extern crate semver;
use semver::VersionReq;
#[test] #[test]
fn check_that_clippy_lints_has_the_same_version_as_clippy() { fn check_that_clippy_lints_has_the_same_version_as_clippy() {
@ -8,7 +10,7 @@ fn check_that_clippy_lints_has_the_same_version_as_clippy() {
assert_eq!(clippy_lints_meta.packages[0].version, clippy_meta.packages[0].version); assert_eq!(clippy_lints_meta.packages[0].version, clippy_meta.packages[0].version);
for package in &clippy_meta.packages[0].dependencies { for package in &clippy_meta.packages[0].dependencies {
if package.name == "clippy_lints" { if package.name == "clippy_lints" {
assert_eq!(clippy_lints_meta.packages[0].version, package.req[1..]); assert_eq!(VersionReq::parse(&clippy_lints_meta.packages[0].version).unwrap(), package.req);
return; return;
} }
} }