Skip to content

Make dogfood test output to seperate directory #2605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from Apr 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions clippy_lints/src/array_indexing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
Expand All @@ -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<Option<Constant>>,
end: &Option<Option<Constant>>,
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
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions clippy_lints/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions tests/dogfood.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down