1
Fork 0

remove nondeterminism by adjusting thresholds

This commit is contained in:
Oliver Schneider 2016-12-21 10:25:14 +01:00
parent 299d7be132
commit ed9d71f2c9
No known key found for this signature in database
GPG key ID: 56D6EEA0FC67AC46
30 changed files with 157 additions and 133 deletions

View file

@ -107,8 +107,7 @@ 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<ConstVal>>, end: Option<Option<ConstVal>>, limits: RangeLimits,
array_size: ConstInt)
fn to_const_range(start: Option<Option<ConstVal>>, end: Option<Option<ConstVal>>, limits: RangeLimits, array_size: ConstInt)
-> Option<(ConstInt, ConstInt)> {
let start = match start {
Some(Some(ConstVal::Integral(x))) => x,

View file

@ -36,9 +36,11 @@ declare_lint! {
/// **What it does:** Checks for `extern crate` and `use` items annotated with lint attributes
///
/// **Why is this bad?** Lint attributes have no effect on crate imports. Most likely a `!` was forgotten
/// **Why is this bad?** Lint attributes have no effect on crate imports. Most likely a `!` was
/// forgotten
///
/// **Known problems:** Technically one might allow `unused_import` on a `use` item, but it's easier to remove the unused item.
/// **Known problems:** Technically one might allow `unused_import` on a `use` item,
/// but it's easier to remove the unused item.
///
/// **Example:**
/// ```rust
@ -126,9 +128,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for AttrPass {
"useless lint attribute",
|db| {
sugg.insert(1, '!');
db.span_suggestion(attr.span,
"if you just forgot a `!`, use",
sugg);
db.span_suggestion(attr.span, "if you just forgot a `!`, use", sugg);
});
}
}

View file

@ -204,7 +204,8 @@ fn lint_match_arms(cx: &LateContext, expr: &Expr) {
if let PatKind::Wild = j.pats[0].node {
// if the last arm is _, then i could be integrated into _
// note that i.pats[0] cannot be _, because that would mean that we're hiding all the subsequent arms, and rust won't compile
// note that i.pats[0] cannot be _, because that would mean that we're
// hiding all the subsequent arms, and rust won't compile
db.span_note(i.body.span,
&format!("`{}` has the same arm body as the `_` wildcard, consider removing it`",
lhs));

View file

@ -268,7 +268,9 @@ fn check_doc(cx: &EarlyContext, valid_idents: &[String], docs: &[(String, Span)]
}
lookup_parser = parser.clone();
if let (Some((false, $c)), Some((false, $c))) = (lookup_parser.next(), lookup_parser.next()) {
let a = lookup_parser.next();
let b = lookup_parser.next();
if let (Some((false, $c)), Some((false, $c))) = (a, b) {
let mut close_count = 3;
while let Some((false, $c)) = lookup_parser.next() {
close_count += 1;

View file

@ -49,10 +49,13 @@ declare_lint! {
/// **What it does:** Checks for modules that have the same name as their parent module
///
/// **Why is this bad?** A typical beginner mistake is to have `mod foo;` and again `mod foo { .. }` in `foo.rs`.
/// The expectation is that items inside the inner `mod foo { .. }` are then available
/// **Why is this bad?** A typical beginner mistake is to have `mod foo;` and again `mod foo { ..
/// }` in `foo.rs`.
/// The expectation is that items inside the inner `mod foo { .. }` are then
/// available
/// through `foo::x`, but they are only available through `foo::foo::x`.
/// If this is done on purpose, it would be better to choose a more representative module name.
/// If this is done on purpose, it would be better to choose a more
/// representative module name.
///
/// **Known problems:** None.
///
@ -111,8 +114,7 @@ fn partial_rmatch(post: &str, name: &str) -> usize {
// FIXME: #600
#[allow(while_let_on_iterator)]
fn check_variant(cx: &EarlyContext, threshold: u64, def: &EnumDef, item_name: &str, item_name_chars: usize,
span: Span) {
fn check_variant(cx: &EarlyContext, threshold: u64, def: &EnumDef, item_name: &str, item_name_chars: usize, span: Span) {
if (def.variants.len() as u64) < threshold {
return;
}

View file

@ -61,8 +61,10 @@ impl LintPass for Pass {
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
fn check_fn(&mut self, cx: &LateContext<'a, 'tcx>, _: visit::FnKind<'tcx>, decl: &'tcx FnDecl, body: &'tcx Expr,
_: Span, id: NodeId) {
fn check_fn(
&mut self, cx: &LateContext<'a, 'tcx>, _: visit::FnKind<'tcx>, decl: &'tcx FnDecl, body: &'tcx Expr, _: Span,
id: NodeId
) {
let param_env = ty::ParameterEnvironment::for_item(cx.tcx, id);
let infcx = cx.tcx.borrowck_fake_infer_ctxt(param_env);

View file

@ -146,7 +146,8 @@ impl<'a, 'tcx> Visitor<'tcx> for DivergenceVisitor<'a, 'tcx> {
}
},
_ => {
// do not lint expressions referencing objects of type `!`, as that required a diverging expression to begin with
// do not lint expressions referencing objects of type `!`, as that required a diverging expression
// to begin with
},
}
self.maybe_walk_expr(e);

View file

@ -69,8 +69,10 @@ impl LintPass for Functions {
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Functions {
fn check_fn(&mut self, cx: &LateContext<'a, 'tcx>, kind: intravisit::FnKind<'tcx>, decl: &'tcx hir::FnDecl,
expr: &'tcx hir::Expr, span: Span, nodeid: ast::NodeId) {
fn check_fn(
&mut self, cx: &LateContext<'a, 'tcx>, kind: intravisit::FnKind<'tcx>, decl: &'tcx hir::FnDecl,
expr: &'tcx hir::Expr, span: Span, nodeid: ast::NodeId
) {
use rustc::hir::map::Node::*;
let is_impl = if let Some(NodeItem(item)) = cx.tcx.map.find(cx.tcx.map.get_parent_node(nodeid)) {
@ -124,8 +126,10 @@ impl<'a, 'tcx> Functions {
}
}
fn check_raw_ptr(&self, cx: &LateContext<'a, 'tcx>, unsafety: hir::Unsafety, decl: &'tcx hir::FnDecl,
expr: &'tcx hir::Expr, nodeid: ast::NodeId) {
fn check_raw_ptr(
&self, cx: &LateContext<'a, 'tcx>, unsafety: hir::Unsafety, decl: &'tcx hir::FnDecl, expr: &'tcx hir::Expr,
nodeid: ast::NodeId
) {
if unsafety == hir::Unsafety::Normal && cx.access_levels.is_exported(nodeid) {
let raw_ptrs = decl.inputs.iter().filter_map(|arg| raw_ptr_arg(cx, arg)).collect::<HashSet<_>>();

View file

@ -116,9 +116,7 @@ fn check_fn_inner<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl, gene
report_extra_lifetimes(cx, decl, generics);
}
fn could_use_elision<'a, 'tcx: 'a, T: Iterator<Item = &'tcx Lifetime>>(cx: &LateContext<'a, 'tcx>,
func: &'tcx FnDecl,
named_lts: &'tcx [LifetimeDef], bounds_lts: T)
fn could_use_elision<'a, 'tcx: 'a, T: Iterator<Item = &'tcx Lifetime>>(cx: &LateContext<'a, 'tcx>, func: &'tcx FnDecl, named_lts: &'tcx [LifetimeDef], bounds_lts: T)
-> bool {
// There are two scenarios where elision works:
// * no output references, all input references have different LT

View file

@ -379,9 +379,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
expr.span,
"this loop could be written as a `for` loop",
|db| {
db.span_suggestion(expr.span,
"try",
format!("for {} in {} {{ .. }}", loop_var, iterator));
db.span_suggestion(expr.span, "try", format!("for {} in {} {{ .. }}", loop_var, iterator));
});
}
}

View file

@ -335,8 +335,7 @@ fn check_match_ref_pats(cx: &LateContext, ex: &Expr, arms: &[Arm], source: Match
let ex = Sugg::hir(cx, ex, "..");
let template = match_template(expr.span, source, ex.deref());
db.span_suggestion(expr.span,
"instead of prefixing all patterns with `&`, you can \
dereference the expression",
"instead of prefixing all patterns with `&`, you can dereference the expression",
template);
});
}

View file

@ -695,9 +695,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
/// Checks for the `OR_FUN_CALL` lint.
fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir::Expr]) {
/// Check for `unwrap_or(T::new())` or `unwrap_or(T::default())`.
fn check_unwrap_or_default(cx: &LateContext, name: &str, fun: &hir::Expr, self_expr: &hir::Expr, arg: &hir::Expr,
or_has_args: bool, span: Span)
-> bool {
fn check_unwrap_or_default(
cx: &LateContext, name: &str, fun: &hir::Expr, self_expr: &hir::Expr, arg: &hir::Expr, or_has_args: bool,
span: Span
) -> bool {
if or_has_args {
return false;
}
@ -723,8 +724,7 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir:
|db| {
db.span_suggestion(span,
"try this",
format!("{}.unwrap_or_default()",
snippet(cx, self_expr.span, "_")));
format!("{}.unwrap_or_default()", snippet(cx, self_expr.span, "_")));
});
return true;
}
@ -736,8 +736,10 @@ fn lint_or_fun_call(cx: &LateContext, expr: &hir::Expr, name: &str, args: &[hir:
}
/// Check for `*or(foo())`.
fn check_general_case(cx: &LateContext, name: &str, fun: &hir::Expr, self_expr: &hir::Expr, arg: &hir::Expr,
or_has_args: bool, span: Span) {
fn check_general_case(
cx: &LateContext, name: &str, fun: &hir::Expr, self_expr: &hir::Expr, arg: &hir::Expr, or_has_args: bool,
span: Span
) {
// don't lint for constant values
// FIXME: can we `expect` here instead of match?
if let Some(qualif) = cx.tcx.const_qualif_map.borrow().get(&arg.id) {

View file

@ -14,7 +14,10 @@
// Note: More specifically this lint is largely inspired (aka copied) from *rustc*'s
// [`missing_doc`].
//
// [`missing_doc`]: https://github.com/rust-lang/rust/blob/d6d05904697d89099b55da3331155392f1db9c00/src/librustc_lint/builtin.rs#L246
// [`missing_doc`]:
// https://github.
// com/rust-lang/rust/blob/d6d05904697d89099b55da3331155392f1db9c00/src/librustc_lint/builtin.
// rs#L246
//
use rustc::hir;

View file

@ -144,9 +144,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
e.span,
"equality checks against false can be replaced by a negation",
|db| {
db.span_suggestion(e.span,
"try simplifying it as shown:",
(!hint).to_string());
db.span_suggestion(e.span, "try simplifying it as shown:", (!hint).to_string());
});
},
(Other, Bool(false)) => {
@ -156,9 +154,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoolComparison {
e.span,
"equality checks against false can be replaced by a negation",
|db| {
db.span_suggestion(e.span,
"try simplifying it as shown:",
(!hint).to_string());
db.span_suggestion(e.span, "try simplifying it as shown:", (!hint).to_string());
});
},
_ => (),

View file

@ -90,8 +90,10 @@ impl LintPass for NewWithoutDefault {
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NewWithoutDefault {
fn check_fn(&mut self, cx: &LateContext<'a, 'tcx>, kind: FnKind<'tcx>, decl: &'tcx hir::FnDecl,
_: &'tcx hir::Expr, span: Span, id: ast::NodeId) {
fn check_fn(
&mut self, cx: &LateContext<'a, 'tcx>, kind: FnKind<'tcx>, decl: &'tcx hir::FnDecl, _: &'tcx hir::Expr,
span: Span, id: ast::NodeId
) {
if in_external_macro(cx, span) {
return;
}

View file

@ -241,7 +241,8 @@ impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
if let Some(ref init) = local.init {
self.apply(|this| walk_expr(this, &**init));
}
// add the pattern after the expression because the bindings aren't available yet in the init expression
// add the pattern after the expression because the bindings aren't available yet in the init
// expression
SimilarNamesNameVisitor(self).visit_pat(&*local.pat);
}
fn visit_block(&mut self, blk: &'tcx Block) {
@ -249,7 +250,8 @@ impl<'a, 'tcx> Visitor<'tcx> for SimilarNamesLocalVisitor<'a, 'tcx> {
}
fn visit_arm(&mut self, arm: &'tcx Arm) {
self.apply(|this| {
// just go through the first pattern, as either all patterns bind the same bindings or rustc would have errored much earlier
// just go through the first pattern, as either all patterns
// bind the same bindings or rustc would have errored much earlier
SimilarNamesNameVisitor(this).visit_pat(&arm.pats[0]);
this.apply(|this| walk_expr(this, &arm.body));
});

View file

@ -44,12 +44,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional {
], {
if let BinOp_::BiLt = op.node {
if let BinOp_::BiAdd = op2.node {
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, "You are trying to use classic C overflow conditions that will fail in Rust.");
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
"You are trying to use classic C overflow conditions that will fail in Rust.");
}
}
if let BinOp_::BiGt = op.node {
if let BinOp_::BiSub = op2.node {
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, "You are trying to use classic C underflow conditions that will fail in Rust.");
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
"You are trying to use classic C underflow conditions that will fail in Rust.");
}
}
}}
@ -66,12 +68,14 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OverflowCheckConditional {
], {
if let BinOp_::BiGt = op.node {
if let BinOp_::BiAdd = op2.node {
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, "You are trying to use classic C overflow conditions that will fail in Rust.");
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
"You are trying to use classic C overflow conditions that will fail in Rust.");
}
}
if let BinOp_::BiLt = op.node {
if let BinOp_::BiSub = op2.node {
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span, "You are trying to use classic C underflow conditions that will fail in Rust.");
span_lint(cx, OVERFLOW_CHECK_CONDITIONAL, expr.span,
"You are trying to use classic C underflow conditions that will fail in Rust.");
}
}
}}

View file

@ -153,9 +153,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for StringLitAsBytes {
"calling `as_bytes()` on a string literal",
|db| {
let sugg = format!("b{}", snippet(cx, args[0].span, r#""foo""#));
db.span_suggestion(e.span,
"consider using a byte string literal instead",
sugg);
db.span_suggestion(e.span, "consider using a byte string literal instead", sugg);
});
}

View file

@ -1007,8 +1007,10 @@ fn err_upcast_comparison(cx: &LateContext, span: &Span, expr: &Expr, always: boo
}
}
fn upcast_comparison_bounds_err(cx: &LateContext, span: &Span, rel: comparisons::Rel,
lhs_bounds: Option<(FullInt, FullInt)>, lhs: &Expr, rhs: &Expr, invert: bool) {
fn upcast_comparison_bounds_err(
cx: &LateContext, span: &Span, rel: comparisons::Rel, lhs_bounds: Option<(FullInt, FullInt)>, lhs: &Expr,
rhs: &Expr, invert: bool
) {
use utils::comparisons::*;
if let Some((lb, ub)) = lhs_bounds {

View file

@ -41,8 +41,10 @@ impl LintPass for UnusedLabel {
}
impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedLabel {
fn check_fn(&mut self, cx: &LateContext<'a, 'tcx>, kind: FnKind<'tcx>, decl: &'tcx hir::FnDecl,
body: &'tcx hir::Expr, span: Span, fn_id: ast::NodeId) {
fn check_fn(
&mut self, cx: &LateContext<'a, 'tcx>, kind: FnKind<'tcx>, decl: &'tcx hir::FnDecl, body: &'tcx hir::Expr,
span: Span, fn_id: ast::NodeId
) {
if in_macro(cx, span) {
return;
}

View file

@ -73,7 +73,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
// }
// }
//
// fn check_variant(&mut self, cx: &LateContext<'a, 'tcx>, var: &'tcx hir::Variant, _: &hir::Generics) {
// fn check_variant(&mut self, cx: &LateContext<'a, 'tcx>, var: &'tcx hir::Variant, _:
// &hir::Generics) {
// if !has_attr(&var.node.attrs) {
// return;
// }

View file

@ -317,8 +317,7 @@ pub fn get_trait_def_id(cx: &LateContext, path: &[&str]) -> Option<DefId> {
/// Check whether a type implements a trait.
/// See also `get_trait_def_id`.
pub fn implements_trait<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>, trait_id: DefId,
ty_params: Vec<ty::Ty<'tcx>>)
pub fn implements_trait<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, ty: ty::Ty<'tcx>, trait_id: DefId, ty_params: Vec<ty::Ty<'tcx>>)
-> bool {
cx.tcx.populate_implementations_for_trait_if_necessary(trait_id);

View file

@ -4,3 +4,7 @@ fn_args_density = "Compressed"
fn_call_width = 80
fn_args_paren_newline = false
match_block_trailing_comma = true
fn_args_layout = "Block"
closure_block_indent_threshold = 0
fn_return_indent = "WithWhereClause"
wrap_comments = true

View file

@ -38,19 +38,22 @@ impl ClippyCompilerCalls {
}
impl<'a> CompilerCalls<'a> for ClippyCompilerCalls {
fn early_callback(&mut self, matches: &getopts::Matches, sopts: &config::Options, cfg: &ast::CrateConfig,
descriptions: &rustc_errors::registry::Registry, output: ErrorOutputType)
-> Compilation {
fn early_callback(
&mut self, matches: &getopts::Matches, sopts: &config::Options, cfg: &ast::CrateConfig,
descriptions: &rustc_errors::registry::Registry, output: ErrorOutputType
) -> Compilation {
self.default.early_callback(matches, sopts, cfg, descriptions, output)
}
fn no_input(&mut self, matches: &getopts::Matches, sopts: &config::Options, cfg: &ast::CrateConfig,
odir: &Option<PathBuf>, ofile: &Option<PathBuf>, descriptions: &rustc_errors::registry::Registry)
-> Option<(Input, Option<PathBuf>)> {
fn no_input(
&mut self, matches: &getopts::Matches, sopts: &config::Options, cfg: &ast::CrateConfig, odir: &Option<PathBuf>,
ofile: &Option<PathBuf>, descriptions: &rustc_errors::registry::Registry
) -> Option<(Input, Option<PathBuf>)> {
self.default.no_input(matches, sopts, cfg, odir, ofile, descriptions)
}
fn late_callback(&mut self, matches: &getopts::Matches, sess: &Session, input: &Input, odir: &Option<PathBuf>,
ofile: &Option<PathBuf>)
-> Compilation {
fn late_callback(
&mut self, matches: &getopts::Matches, sess: &Session, input: &Input, odir: &Option<PathBuf>,
ofile: &Option<PathBuf>
) -> Compilation {
self.default.late_callback(matches, sess, input, odir, ofile)
}
fn build_controller(&mut self, sess: &Session, matches: &getopts::Matches) -> driver::CompileController<'a> {