Merge pull request #2605 from mikerite/dogfood_target_dir

Make dogfood test output to seperate directory
This commit is contained in:
Oliver Schneider 2018-04-02 12:10:43 +02:00 committed by GitHub
commit c5559c1648
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 17 deletions

View file

@ -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<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

View file

@ -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,

View file

@ -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);

View file

@ -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;

View file

@ -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()

View file

@ -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);