Merge pull request #999 from Manishearth/whitelist

Some small fixes
This commit is contained in:
llogiq 2016-06-10 00:04:50 +02:00 committed by GitHub
commit e6832317fa
7 changed files with 33 additions and 20 deletions

View file

@ -150,6 +150,7 @@ impl<'a, 'tcx, 'v> hir::intravisit::Visitor<'v> for UsedVisitor<'a, 'tcx> {
fn check_assign<'e>(cx: &LateContext, decl: hir::def_id::DefId, block: &'e hir::Block) -> Option<&'e hir::Expr> {
if_let_chain! {[
block.expr.is_none(),
let Some(expr) = block.stmts.iter().last(),
let hir::StmtSemi(ref expr, _) = expr.node,
let hir::ExprAssign(ref var, ref value) = expr.node,

View file

@ -444,6 +444,11 @@ fn check_for_loop_reverse_range(cx: &LateContext, arg: &Expr, expr: &Expr) {
if sup {
let start_snippet = snippet(cx, start.span, "_");
let end_snippet = snippet(cx, end.span, "_");
let dots = if limits == ast::RangeLimits::Closed {
"..."
} else {
".."
};
span_lint_and_then(cx,
REVERSE_RANGE_LOOP,
@ -454,7 +459,10 @@ fn check_for_loop_reverse_range(cx: &LateContext, arg: &Expr, expr: &Expr) {
"consider using the following if \
you are attempting to iterate \
over this range in reverse",
format!("({}..{}).rev()", end_snippet, start_snippet));
format!("({end}{dots}{start}).rev()",
end=end_snippet,
dots=dots,
start=start_snippet));
});
} else if eq && limits != ast::RangeLimits::Closed {
// if they are equal, it's also problematic - this loop

View file

@ -3,7 +3,7 @@ use syntax::ast::*;
use syntax::codemap::{Span, Spanned};
use syntax::visit::FnKind;
use utils::{span_lint, span_lint_and_then, snippet_opt, match_path_ast, in_external_macro};
use utils::{span_note_and_lint, span_lint_and_then, snippet_opt, match_path_ast, in_external_macro};
/// **What it does:** This lint checks for return statements at the end of a block.
///
@ -95,27 +95,21 @@ impl ReturnPass {
let Some(ref retexpr) = block.expr,
let StmtKind::Decl(ref decl, _) = stmt.node,
let DeclKind::Local(ref local) = decl.node,
local.ty.is_none(),
let Some(ref initexpr) = local.init,
let PatKind::Ident(_, Spanned { node: id, .. }, _) = local.pat.node,
let ExprKind::Path(_, ref path) = retexpr.node,
match_path_ast(path, &[&id.name.as_str()])
match_path_ast(path, &[&id.name.as_str()]),
!in_external_macro(cx, initexpr.span),
], {
self.emit_let_lint(cx, retexpr.span, initexpr.span);
}
}
}
fn emit_let_lint(&mut self, cx: &EarlyContext, lint_span: Span, note_span: Span) {
if in_external_macro(cx, note_span) {
return;
}
let mut db = span_lint(cx,
span_note_and_lint(cx,
LET_AND_RETURN,
lint_span,
"returning the result of a let binding from a block. Consider returning the \
expression directly.");
if cx.current_level(LET_AND_RETURN) != Level::Allow {
db.span_note(note_span, "this expression can be directly returned");
retexpr.span,
"returning the result of a let binding from a block. \
Consider returning the expression directly.",
initexpr.span,
"this expression can be directly returned");
}
}
}
}

View file

@ -151,7 +151,7 @@ define_Conf! {
/// Lint: CYCLOMATIC_COMPLEXITY. The maximum cyclomatic complexity a function can have
("cyclomatic-complexity-threshold", cyclomatic_complexity_threshold, 25 => u64),
/// Lint: DOC_MARKDOWN. The list of words this lint should not consider as identifiers needing ticks
("doc-valid-idents", doc_valid_idents, ["MiB", "GiB", "TiB", "PiB", "EiB", "GitHub"] => Vec<String>),
("doc-valid-idents", doc_valid_idents, ["MiB", "GiB", "TiB", "PiB", "EiB", "GitHub", "NaN"] => Vec<String>),
/// Lint: TOO_MANY_ARGUMENTS. The maximum number of argument a function or method can have
("too-many-arguments-threshold", too_many_arguments_threshold, 7 => u64),
/// Lint: TYPE_COMPLEXITY. The maximum complexity a type can have

View file

@ -46,6 +46,7 @@ fn test_emphasis() {
/// 32kib 32Mib 32Gib 32Tib 32Pib 32Eib
/// 32kB 32MB 32GB 32TB 32PB 32EB
/// 32kb 32Mb 32Gb 32Tb 32Pb 32Eb
/// NaN
/// be_sure_we_got_to_the_end_of_it
//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
fn test_units() {

View file

@ -169,7 +169,7 @@ fn main() {
for i in 10...0 {
//~^ERROR this range is empty so this for loop will never run
//~|HELP consider
//~|SUGGESTION (0..10).rev()
//~|SUGGESTION (0...10).rev()
println!("{}", i);
}

View file

@ -98,6 +98,15 @@ fn main() {
toto = 2;
}
// found in libcore, the inner if is not a statement but the block's expr
let mut ch = b'x';
if f() {
ch = b'*';
if f() {
ch = b'?';
}
}
// baz needs to be mut
let mut baz = 0;
//~^ ERROR `if _ { .. } else { .. }` is an expression