Skip to content

Commit c5559c1

Browse files
authored
Merge pull request #2605 from mikerite/dogfood_target_dir
Make dogfood test output to seperate directory
2 parents 83e2109 + add4434 commit c5559c1

File tree

6 files changed

+33
-17
lines changed

6 files changed

+33
-17
lines changed

clippy_lints/src/array_indexing.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc::ty;
33
use rustc::hir;
44
use syntax::ast::RangeLimits;
55
use utils::{self, higher};
6+
use utils::higher::Range;
67
use consts::{constant, Constant};
78

89
/// **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 {
7374

7475
// Index is a constant range
7576
if let Some(range) = higher::range(index) {
76-
let start = range.start.map(|start| constant(cx, start).map(|(c, _)| c));
77-
let end = range.end.map(|end| constant(cx, end).map(|(c, _)| c));
78-
79-
if let Some((start, end)) = to_const_range(&start, &end, range.limits, size) {
77+
if let Some((start, end)) = to_const_range(cx, range, size) {
8078
if start > size || end > size {
8179
utils::span_lint(cx, OUT_OF_BOUNDS_INDEXING, e.span, "range is out of bounds");
8280
}
@@ -102,20 +100,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ArrayIndexing {
102100

103101
/// Returns an option containing a tuple with the start and end (exclusive) of
104102
/// the range.
105-
fn to_const_range(
106-
start: &Option<Option<Constant>>,
107-
end: &Option<Option<Constant>>,
108-
limits: RangeLimits,
109-
array_size: u128,
110-
) -> Option<(u128, u128)> {
111-
let start = match *start {
103+
fn to_const_range<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, range: Range, array_size: u128) -> Option<(u128, u128)> {
104+
let s = range.start.map(|expr| constant(cx, expr).map(|(c, _)| c));
105+
let start = match s {
112106
Some(Some(Constant::Int(x))) => x,
113107
Some(_) => return None,
114108
None => 0,
115109
};
116110

117-
let end = match *end {
118-
Some(Some(Constant::Int(x))) => if limits == RangeLimits::Closed {
111+
let e = range.end.map(|expr| constant(cx, expr).map(|(c, _)| c));
112+
let end = match e {
113+
Some(Some(Constant::Int(x))) => if range.limits == RangeLimits::Closed {
119114
x + 1
120115
} else {
121116
x

clippy_lints/src/methods.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -680,9 +680,7 @@ impl LintPass for Pass {
680680
}
681681

682682
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
683-
#[allow(unused_attributes)]
684-
// ^ required because `cyclomatic_complexity` attribute shows up as unused
685-
#[cyclomatic_complexity = "30"]
683+
#[allow(cyclomatic_complexity)]
686684
fn check_expr(&mut self, cx: &LateContext<'a, 'tcx>, expr: &'tcx hir::Expr) {
687685
if in_macro(expr.span) {
688686
return;
@@ -889,6 +887,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, method_span: Span, name:
889887
}
890888

891889
/// Check for `*or(foo())`.
890+
#[allow(too_many_arguments)]
892891
fn check_general_case(
893892
cx: &LateContext,
894893
name: &str,

clippy_lints/src/utils/hir_utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ impl<'a, 'tcx: 'a> SpanlessHash<'a, 'tcx> {
316316
b.rules.hash(&mut self.s);
317317
}
318318

319+
#[allow(many_single_char_names)]
319320
pub fn hash_expr(&mut self, e: &Expr) {
320321
if let Some(e) = constant_simple(self.cx, e) {
321322
return e.hash(&mut self.s);

clippy_lints/src/utils/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ pub fn without_block_comments(lines: Vec<&str>) -> Vec<&str> {
11031103

11041104
let mut nest_level = 0;
11051105

1106-
for line in lines.into_iter() {
1106+
for line in lines {
11071107
if line.contains("/*") {
11081108
nest_level += 1;
11091109
continue;

src/main.rs

+20
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,30 @@ where
7777
if cfg!(windows) {
7878
path.set_extension("exe");
7979
}
80+
81+
let target_dir = std::env::var_os("CLIPPY_DOGFOOD")
82+
.map(|_| {
83+
std::env::var_os("CARGO_MANIFEST_DIR").map_or_else(
84+
|| {
85+
let mut fallback = std::ffi::OsString::new();
86+
fallback.push("clippy_dogfood");
87+
fallback
88+
},
89+
|d| {
90+
std::path::PathBuf::from(d)
91+
.join("target")
92+
.join("dogfood")
93+
.into_os_string()
94+
},
95+
)
96+
})
97+
.map(|p| ("CARGO_TARGET_DIR", p));
98+
8099
let exit_status = std::process::Command::new("cargo")
81100
.args(&args)
82101
.env("RUSTC_WRAPPER", path)
83102
.env("CLIPPY_ARGS", clippy_args)
103+
.envs(target_dir)
84104
.spawn()
85105
.expect("could not run cargo")
86106
.wait()

tests/dogfood.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ fn dogfood() {
1515
.arg("cargo-clippy")
1616
.arg("--manifest-path")
1717
.arg(root_dir.join("Cargo.toml"))
18+
.env("CLIPPY_DOGFOOD", "true")
1819
.output()
1920
.unwrap();
2021
println!("status: {}", output.status);

0 commit comments

Comments
 (0)