Skip to content

Commit e683231

Browse files
authored
Merge pull request #999 from Manishearth/whitelist
Some small fixes
2 parents 8e50e50 + e9360f7 commit e683231

File tree

7 files changed

+33
-20
lines changed

7 files changed

+33
-20
lines changed

clippy_lints/src/let_if_seq.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ impl<'a, 'tcx, 'v> hir::intravisit::Visitor<'v> for UsedVisitor<'a, 'tcx> {
150150

151151
fn check_assign<'e>(cx: &LateContext, decl: hir::def_id::DefId, block: &'e hir::Block) -> Option<&'e hir::Expr> {
152152
if_let_chain! {[
153+
block.expr.is_none(),
153154
let Some(expr) = block.stmts.iter().last(),
154155
let hir::StmtSemi(ref expr, _) = expr.node,
155156
let hir::ExprAssign(ref var, ref value) = expr.node,

clippy_lints/src/loops.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,11 @@ fn check_for_loop_reverse_range(cx: &LateContext, arg: &Expr, expr: &Expr) {
444444
if sup {
445445
let start_snippet = snippet(cx, start.span, "_");
446446
let end_snippet = snippet(cx, end.span, "_");
447+
let dots = if limits == ast::RangeLimits::Closed {
448+
"..."
449+
} else {
450+
".."
451+
};
447452

448453
span_lint_and_then(cx,
449454
REVERSE_RANGE_LOOP,
@@ -454,7 +459,10 @@ fn check_for_loop_reverse_range(cx: &LateContext, arg: &Expr, expr: &Expr) {
454459
"consider using the following if \
455460
you are attempting to iterate \
456461
over this range in reverse",
457-
format!("({}..{}).rev()", end_snippet, start_snippet));
462+
format!("({end}{dots}{start}).rev()",
463+
end=end_snippet,
464+
dots=dots,
465+
start=start_snippet));
458466
});
459467
} else if eq && limits != ast::RangeLimits::Closed {
460468
// if they are equal, it's also problematic - this loop

clippy_lints/src/returns.rs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use syntax::ast::*;
33
use syntax::codemap::{Span, Spanned};
44
use syntax::visit::FnKind;
55

6-
use utils::{span_lint, span_lint_and_then, snippet_opt, match_path_ast, in_external_macro};
6+
use utils::{span_note_and_lint, span_lint_and_then, snippet_opt, match_path_ast, in_external_macro};
77

88
/// **What it does:** This lint checks for return statements at the end of a block.
99
///
@@ -95,29 +95,23 @@ impl ReturnPass {
9595
let Some(ref retexpr) = block.expr,
9696
let StmtKind::Decl(ref decl, _) = stmt.node,
9797
let DeclKind::Local(ref local) = decl.node,
98+
local.ty.is_none(),
9899
let Some(ref initexpr) = local.init,
99100
let PatKind::Ident(_, Spanned { node: id, .. }, _) = local.pat.node,
100101
let ExprKind::Path(_, ref path) = retexpr.node,
101-
match_path_ast(path, &[&id.name.as_str()])
102+
match_path_ast(path, &[&id.name.as_str()]),
103+
!in_external_macro(cx, initexpr.span),
102104
], {
103-
self.emit_let_lint(cx, retexpr.span, initexpr.span);
105+
span_note_and_lint(cx,
106+
LET_AND_RETURN,
107+
retexpr.span,
108+
"returning the result of a let binding from a block. \
109+
Consider returning the expression directly.",
110+
initexpr.span,
111+
"this expression can be directly returned");
104112
}
105113
}
106114
}
107-
108-
fn emit_let_lint(&mut self, cx: &EarlyContext, lint_span: Span, note_span: Span) {
109-
if in_external_macro(cx, note_span) {
110-
return;
111-
}
112-
let mut db = span_lint(cx,
113-
LET_AND_RETURN,
114-
lint_span,
115-
"returning the result of a let binding from a block. Consider returning the \
116-
expression directly.");
117-
if cx.current_level(LET_AND_RETURN) != Level::Allow {
118-
db.span_note(note_span, "this expression can be directly returned");
119-
}
120-
}
121115
}
122116

123117
impl LintPass for ReturnPass {

clippy_lints/src/utils/conf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ define_Conf! {
151151
/// Lint: CYCLOMATIC_COMPLEXITY. The maximum cyclomatic complexity a function can have
152152
("cyclomatic-complexity-threshold", cyclomatic_complexity_threshold, 25 => u64),
153153
/// Lint: DOC_MARKDOWN. The list of words this lint should not consider as identifiers needing ticks
154-
("doc-valid-idents", doc_valid_idents, ["MiB", "GiB", "TiB", "PiB", "EiB", "GitHub"] => Vec<String>),
154+
("doc-valid-idents", doc_valid_idents, ["MiB", "GiB", "TiB", "PiB", "EiB", "GitHub", "NaN"] => Vec<String>),
155155
/// Lint: TOO_MANY_ARGUMENTS. The maximum number of argument a function or method can have
156156
("too-many-arguments-threshold", too_many_arguments_threshold, 7 => u64),
157157
/// Lint: TYPE_COMPLEXITY. The maximum complexity a type can have

tests/compile-fail/doc.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ fn test_emphasis() {
4646
/// 32kib 32Mib 32Gib 32Tib 32Pib 32Eib
4747
/// 32kB 32MB 32GB 32TB 32PB 32EB
4848
/// 32kb 32Mb 32Gb 32Tb 32Pb 32Eb
49+
/// NaN
4950
/// be_sure_we_got_to_the_end_of_it
5051
//~^ ERROR: you should put `be_sure_we_got_to_the_end_of_it` between ticks
5152
fn test_units() {

tests/compile-fail/for_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn main() {
169169
for i in 10...0 {
170170
//~^ERROR this range is empty so this for loop will never run
171171
//~|HELP consider
172-
//~|SUGGESTION (0..10).rev()
172+
//~|SUGGESTION (0...10).rev()
173173
println!("{}", i);
174174
}
175175

tests/compile-fail/let_if_seq.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,15 @@ fn main() {
9898
toto = 2;
9999
}
100100

101+
// found in libcore, the inner if is not a statement but the block's expr
102+
let mut ch = b'x';
103+
if f() {
104+
ch = b'*';
105+
if f() {
106+
ch = b'?';
107+
}
108+
}
109+
101110
// baz needs to be mut
102111
let mut baz = 0;
103112
//~^ ERROR `if _ { .. } else { .. }` is an expression

0 commit comments

Comments
 (0)