diff --git a/clippy_lints/src/array_indexing.rs b/clippy_lints/src/array_indexing.rs index 4563a58f7abd..1b21cf8c5ff4 100644 --- a/clippy_lints/src/array_indexing.rs +++ b/clippy_lints/src/array_indexing.rs @@ -3,6 +3,7 @@ use rustc::ty; use rustc::hir; use syntax::ast::RangeLimits; use utils::{self, higher}; +use utils::higher::Range; use consts::{constant, Constant}; /// **What it does:** Checks for out of bounds array indexing with a constant @@ -73,10 +74,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIndexing { // Index is a constant range if let Some(range) = higher::range(index) { - let start = range.start.map(|start| constant(cx, start).map(|(c, _)| c)); - let end = range.end.map(|end| constant(cx, end).map(|(c, _)| c)); - - if let Some((start, end)) = to_const_range(&start, &end, range.limits, size) { + if let Some((start, end)) = to_const_range(cx, range, size) { if start > size || end > size { utils::span_lint(cx, OUT_OF_BOUNDS_INDEXING, e.span, "range is out of bounds"); } @@ -102,20 +100,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIndexing { /// Returns an option containing a tuple with the start and end (exclusive) of /// the range. -fn to_const_range( - start: &Option>, - end: &Option>, - limits: RangeLimits, - array_size: u128, -) -> Option<(u128, u128)> { - let start = match *start { +fn to_const_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, range: Range, array_size: u128) -> Option<(u128, u128)> { + let s = range.start.map(|expr| constant(cx, expr).map(|(c, _)| c)); + let start = match s { Some(Some(Constant::Int(x))) => x, Some(_) => return None, None => 0, }; - let end = match *end { - Some(Some(Constant::Int(x))) => if limits == RangeLimits::Closed { + let e = range.end.map(|expr| constant(cx, expr).map(|(c, _)| c)); + let end = match e { + Some(Some(Constant::Int(x))) => if range.limits == RangeLimits::Closed { x + 1 } else { x diff --git a/clippy_lints/src/methods.rs b/clippy_lints/src/methods.rs index 50de299ca7d1..423be2106d16 100644 --- a/clippy_lints/src/methods.rs +++ b/clippy_lints/src/methods.rs @@ -680,9 +680,7 @@ impl LintPass for Pass { } impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass { - #[allow(unused_attributes)] - // ^ required because `cyclomatic_complexity` attribute shows up as unused - #[cyclomatic_complexity = "30"] + #[allow(cyclomatic_complexity)] fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) { if in_macro(expr.span) { return; @@ -889,6 +887,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, name: } /// Check for `*or(foo())`. + #[allow(too_many_arguments)] fn check_general_case( cx: &LateContext, name: &str, diff --git a/clippy_lints/src/utils/hir_utils.rs b/clippy_lints/src/utils/hir_utils.rs index e790184a7aba..1f96ec2b237c 100644 --- a/clippy_lints/src/utils/hir_utils.rs +++ b/clippy_lints/src/utils/hir_utils.rs @@ -316,6 +316,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> { b.rules.hash(&mut self.s); } + #[allow(many_single_char_names)] pub fn hash_expr(&mut self, e: &Expr) { if let Some(e) = constant_simple(self.cx, e) { return e.hash(&mut self.s); diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index e3a7fc851b15..f71de382cade 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -1103,7 +1103,7 @@ pub fn without_block_comments(lines: Vec<&str>) -> Vec<&str> { let mut nest_level = 0; - for line in lines.into_iter() { + for line in lines { if line.contains("/*") { nest_level += 1; continue; diff --git a/src/main.rs b/src/main.rs index 5bdbaf1bc80e..aac5e97f3114 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,10 +77,30 @@ where if cfg!(windows) { path.set_extension("exe"); } + + let target_dir = std::env::var_os("CLIPPY_DOGFOOD") + .map(|_| { + std::env::var_os("CARGO_MANIFEST_DIR").map_or_else( + || { + let mut fallback = std::ffi::OsString::new(); + fallback.push("clippy_dogfood"); + fallback + }, + |d| { + std::path::PathBuf::from(d) + .join("target") + .join("dogfood") + .into_os_string() + }, + ) + }) + .map(|p| ("CARGO_TARGET_DIR", p)); + let exit_status = std::process::Command::new("cargo") .args(&args) .env("RUSTC_WRAPPER", path) .env("CLIPPY_ARGS", clippy_args) + .envs(target_dir) .spawn() .expect("could not run cargo") .wait() diff --git a/tests/dogfood.rs b/tests/dogfood.rs index ed6451a3eb68..a2d4da9a1ca4 100644 --- a/tests/dogfood.rs +++ b/tests/dogfood.rs @@ -15,6 +15,7 @@ fn dogfood() { .arg("cargo-clippy") .arg("--manifest-path") .arg(root_dir.join("Cargo.toml")) + .env("CLIPPY_DOGFOOD", "true") .output() .unwrap(); println!("status: {}", output.status);