Skip to content

Commit 96905b8

Browse files
committed
submodules: update clippy from 1b89724 to 1838bfe
Changes: ```` Fixing typo in CONTRIBUTING.md Fix breakage due to rust-lang/rust#57651 Run rustfmt Fixed breakage due to rust-lang/rust#57489 Fix breakage due to rust-lang/rust#57755 Catch up with `format_args` change Fix bad `while_let_on_iterator` suggestion. rustup rust-lang/rust#57747 Fixing issues pointed out by dogfood tests. Update to collect all the files then throw the error. Adding a test for checking if test files are missing. Remove bors.toml add applicability to lint name suggestion ````
1 parent eba7337 commit 96905b8

35 files changed

+300
-258
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ to lint-writing, though it does get into advanced stuff. Most lints consist of a
7979
of this.
8080

8181
If you want to add a new lint or change existing ones apart from bugfixing, it's
82-
also a good idea to give the [stability guaratees][rfc_stability] and
82+
also a good idea to give the [stability guarantees][rfc_stability] and
8383
[lint categories][rfc_lint_cats] sections of the [Clippy 1.0 RFC][clippy_rfc] a
8484
quick read.
8585

bors.toml

-4
This file was deleted.

clippy_lints/src/attrs.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,12 @@ fn check_clippy_lint_names(cx: &LateContext<'_, '_>, items: &[NestedMetaItem]) {
332332
// https://github.com/rust-lang/rust/pull/56992
333333
CheckLintNameResult::NoLint(None) => (),
334334
_ => {
335-
db.span_suggestion(lint.span,
336-
"lowercase the lint name",
337-
name_lower);
335+
db.span_suggestion_with_applicability(
336+
lint.span,
337+
"lowercase the lint name",
338+
name_lower,
339+
Applicability::MaybeIncorrect,
340+
);
338341
}
339342
}
340343
}
@@ -373,8 +376,9 @@ fn is_relevant_trait(tcx: TyCtxt<'_, '_, '_>, item: &TraitItem) -> bool {
373376
fn is_relevant_block(tcx: TyCtxt<'_, '_, '_>, tables: &ty::TypeckTables<'_>, block: &Block) -> bool {
374377
if let Some(stmt) = block.stmts.first() {
375378
match &stmt.node {
376-
StmtKind::Decl(_, _) => true,
377-
StmtKind::Expr(expr, _) | StmtKind::Semi(expr, _) => is_relevant_expr(tcx, tables, expr),
379+
StmtKind::Local(_) => true,
380+
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(tcx, tables, expr),
381+
_ => false,
378382
}
379383
} else {
380384
block.expr.as_ref().map_or(false, |e| is_relevant_expr(tcx, tables, e))

clippy_lints/src/consts.rs

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::convert::TryInto;
1414
use std::hash::{Hash, Hasher};
1515
use syntax::ast::{FloatTy, LitKind};
1616
use syntax::ptr::P;
17+
use syntax_pos::symbol::Symbol;
1718

1819
/// A `LitKind`-like enum to fold constant `Expr`s into.
1920
#[derive(Debug, Clone)]
@@ -38,6 +39,8 @@ pub enum Constant {
3839
Repeat(Box<Constant>, u64),
3940
/// a tuple of constants
4041
Tuple(Vec<Constant>),
42+
/// a literal with syntax error
43+
Err(Symbol),
4144
}
4245

4346
impl PartialEq for Constant {
@@ -103,6 +106,9 @@ impl Hash for Constant {
103106
c.hash(state);
104107
l.hash(state);
105108
},
109+
Constant::Err(ref s) => {
110+
s.hash(state);
111+
},
106112
}
107113
}
108114
}
@@ -155,6 +161,7 @@ pub fn lit_to_constant<'tcx>(lit: &LitKind, ty: Ty<'tcx>) -> Constant {
155161
_ => bug!(),
156162
},
157163
LitKind::Bool(b) => Constant::Bool(b),
164+
LitKind::Err(s) => Constant::Err(s),
158165
}
159166
}
160167

clippy_lints/src/escape.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,16 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
120120
if let Categorization::Rvalue(..) = cmt.cat {
121121
let id = map.hir_to_node_id(cmt.hir_id);
122122
if let Some(Node::Stmt(st)) = map.find(map.get_parent_node(id)) {
123-
if let StmtKind::Decl(ref decl, _) = st.node {
124-
if let DeclKind::Local(ref loc) = decl.node {
125-
if let Some(ref ex) = loc.init {
126-
if let ExprKind::Box(..) = ex.node {
127-
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
128-
// let x = box (...)
129-
self.set.insert(consume_pat.id);
130-
}
131-
// TODO Box::new
132-
// TODO vec![]
133-
// TODO "foo".to_owned() and friends
123+
if let StmtKind::Local(ref loc) = st.node {
124+
if let Some(ref ex) = loc.init {
125+
if let ExprKind::Box(..) = ex.node {
126+
if is_non_trait_box(cmt.ty) && !self.is_large_box(cmt.ty) {
127+
// let x = box (...)
128+
self.set.insert(consume_pat.id);
134129
}
130+
// TODO Box::new
131+
// TODO vec![]
132+
// TODO "foo".to_owned() and friends
135133
}
136134
}
137135
}

clippy_lints/src/eval_order_dependence.rs

+13-18
Original file line numberDiff line numberDiff line change
@@ -89,14 +89,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for EvalOrderDependence {
8989
}
9090
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
9191
match stmt.node {
92-
StmtKind::Expr(ref e, _) | StmtKind::Semi(ref e, _) => DivergenceVisitor { cx }.maybe_walk_expr(e),
93-
StmtKind::Decl(ref d, _) => {
94-
if let DeclKind::Local(ref local) = d.node {
95-
if let Local { init: Some(ref e), .. } = **local {
96-
DivergenceVisitor { cx }.visit_expr(e);
97-
}
92+
StmtKind::Local(ref local) => {
93+
if let Local { init: Some(ref e), .. } = **local {
94+
DivergenceVisitor { cx }.visit_expr(e);
9895
}
9996
},
97+
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => DivergenceVisitor { cx }.maybe_walk_expr(e),
98+
StmtKind::Item(..) => {},
10099
}
101100
}
102101
}
@@ -269,18 +268,14 @@ fn check_expr<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, expr: &'tcx Expr) -> St
269268

270269
fn check_stmt<'a, 'tcx>(vis: &mut ReadVisitor<'a, 'tcx>, stmt: &'tcx Stmt) -> StopEarly {
271270
match stmt.node {
272-
StmtKind::Expr(ref expr, _) | StmtKind::Semi(ref expr, _) => check_expr(vis, expr),
273-
StmtKind::Decl(ref decl, _) => {
274-
// If the declaration is of a local variable, check its initializer
275-
// expression if it has one. Otherwise, keep going.
276-
let local = match decl.node {
277-
DeclKind::Local(ref local) => Some(local),
278-
_ => None,
279-
};
280-
local
281-
.and_then(|local| local.init.as_ref())
282-
.map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr))
283-
},
271+
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => check_expr(vis, expr),
272+
// If the declaration is of a local variable, check its initializer
273+
// expression if it has one. Otherwise, keep going.
274+
StmtKind::Local(ref local) => local
275+
.init
276+
.as_ref()
277+
.map_or(StopEarly::KeepGoing, |expr| check_expr(vis, expr)),
278+
_ => StopEarly::KeepGoing,
284279
}
285280
}
286281

clippy_lints/src/format.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,17 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
5353
ExprKind::Call(ref fun, ref args) => {
5454
if_chain! {
5555
if let ExprKind::Path(ref qpath) = fun.node;
56-
if args.len() == 3;
5756
if let Some(fun_def_id) = opt_def_id(resolve_node(cx, qpath, fun.hir_id));
58-
if match_def_path(cx.tcx, fun_def_id, &paths::FMT_ARGUMENTS_NEWV1FORMATTED);
57+
let new_v1 = match_def_path(cx.tcx, fun_def_id, &paths::FMT_ARGUMENTS_NEWV1);
58+
let new_v1_fmt = match_def_path(
59+
cx.tcx,
60+
fun_def_id,
61+
&paths::FMT_ARGUMENTS_NEWV1FORMATTED
62+
);
63+
if new_v1 || new_v1_fmt;
5964
if check_single_piece(&args[0]);
6065
if let Some(format_arg) = get_single_string_arg(cx, &args[1]);
61-
if check_unformatted(&args[2]);
66+
if new_v1 || check_unformatted(&args[2]);
6267
if let ExprKind::AddrOf(_, ref format_arg) = format_arg.node;
6368
then {
6469
let (message, sugg) = if_chain! {

clippy_lints/src/let_if_seq.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
6868
while let Some(stmt) = it.next() {
6969
if_chain! {
7070
if let Some(expr) = it.peek();
71-
if let hir::StmtKind::Decl(ref decl, _) = stmt.node;
72-
if let hir::DeclKind::Local(ref decl) = decl.node;
73-
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = decl.pat.node;
74-
if let hir::StmtKind::Expr(ref if_, _) = expr.node;
71+
if let hir::StmtKind::Local(ref local) = stmt.node;
72+
if let hir::PatKind::Binding(mode, canonical_id, ident, None) = local.pat.node;
73+
if let hir::StmtKind::Expr(ref if_) = expr.node;
7574
if let hir::ExprKind::If(ref cond, ref then, ref else_) = if_.node;
7675
if !used_in_expr(cx, canonical_id, cond);
7776
if let hir::ExprKind::Block(ref then, _) = then.node;
@@ -84,15 +83,15 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for LetIfSeq {
8483
if let hir::ExprKind::Block(ref else_, _) = else_.node {
8584
if let Some(default) = check_assign(cx, canonical_id, else_) {
8685
(else_.stmts.len() > 1, default)
87-
} else if let Some(ref default) = decl.init {
86+
} else if let Some(ref default) = local.init {
8887
(true, &**default)
8988
} else {
9089
continue;
9190
}
9291
} else {
9392
continue;
9493
}
95-
} else if let Some(ref default) = decl.init {
94+
} else if let Some(ref default) = local.init {
9695
(false, &**default)
9796
} else {
9897
continue;
@@ -169,7 +168,7 @@ fn check_assign<'a, 'tcx>(
169168
if_chain! {
170169
if block.expr.is_none();
171170
if let Some(expr) = block.stmts.iter().last();
172-
if let hir::StmtKind::Semi(ref expr, _) = expr.node;
171+
if let hir::StmtKind::Semi(ref expr) = expr.node;
173172
if let hir::ExprKind::Assign(ref var, ref value) = expr.node;
174173
if let hir::ExprKind::Path(ref qpath) = var.node;
175174
if let Def::Local(local_id) = cx.tables.qpath_def(qpath, var.hir_id);

clippy_lints/src/loops.rs

+28-24
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use if_chain::if_chain;
33
use itertools::Itertools;
44
use rustc::hir::def::Def;
55
use rustc::hir::def_id;
6-
use rustc::hir::intravisit::{walk_block, walk_decl, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
6+
use rustc::hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
77
use rustc::hir::*;
88
use rustc::lint::{in_external_macro, LateContext, LateLintPass, LintArray, LintContext, LintPass};
99
use rustc::middle::region;
@@ -565,6 +565,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
565565
&& lhs_constructor.ident.name == "Some"
566566
&& (pat_args.is_empty()
567567
|| !is_refutable(cx, &pat_args[0])
568+
&& !is_used_inside(cx, iter_expr, &arms[0].body)
568569
&& !is_iterator_used_after_while_let(cx, iter_expr)
569570
&& !is_nested(cx, expr, &method_args[0]))
570571
{
@@ -596,7 +597,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
596597
}
597598

598599
fn check_stmt(&mut self, cx: &LateContext<'a, 'tcx>, stmt: &'tcx Stmt) {
599-
if let StmtKind::Semi(ref expr, _) = stmt.node {
600+
if let StmtKind::Semi(ref expr) = stmt.node {
600601
if let ExprKind::MethodCall(ref method, _, ref args) = expr.node {
601602
if args.len() == 1 && method.ident.name == "collect" && match_trait_method(cx, expr, &paths::ITERATOR) {
602603
span_lint(
@@ -667,13 +668,7 @@ fn never_loop_block(block: &Block, main_loop_id: NodeId) -> NeverLoopResult {
667668
fn stmt_to_expr(stmt: &Stmt) -> Option<&Expr> {
668669
match stmt.node {
669670
StmtKind::Semi(ref e, ..) | StmtKind::Expr(ref e, ..) => Some(e),
670-
StmtKind::Decl(ref d, ..) => decl_to_expr(d),
671-
}
672-
}
673-
674-
fn decl_to_expr(decl: &Decl) -> Option<&Expr> {
675-
match decl.node {
676-
DeclKind::Local(ref local) => local.init.as_ref().map(|p| &**p),
671+
StmtKind::Local(ref local) => local.init.as_ref().map(|p| &**p),
677672
_ => None,
678673
}
679674
}
@@ -941,8 +936,8 @@ fn get_indexed_assignments<'a, 'tcx>(
941936
stmts
942937
.iter()
943938
.map(|stmt| match stmt.node {
944-
StmtKind::Decl(..) => None,
945-
StmtKind::Expr(ref e, _node_id) | StmtKind::Semi(ref e, _node_id) => Some(get_assignment(cx, e, var)),
939+
StmtKind::Local(..) | StmtKind::Item(..) => None,
940+
StmtKind::Expr(ref e) | StmtKind::Semi(ref e) => Some(get_assignment(cx, e, var)),
946941
})
947942
.chain(expr.as_ref().into_iter().map(|e| Some(get_assignment(cx, &*e, var))))
948943
.filter_map(|op| op)
@@ -1888,6 +1883,19 @@ impl<'a, 'tcx> Visitor<'tcx> for VarVisitor<'a, 'tcx> {
18881883
}
18891884
}
18901885

1886+
fn is_used_inside<'a, 'tcx: 'a>(cx: &'a LateContext<'a, 'tcx>, expr: &'tcx Expr, container: &'tcx Expr) -> bool {
1887+
let def_id = match var_def_id(cx, expr) {
1888+
Some(id) => id,
1889+
None => return false,
1890+
};
1891+
if let Some(used_mutably) = mutated_variables(container, cx) {
1892+
if used_mutably.contains(&def_id) {
1893+
return true;
1894+
}
1895+
}
1896+
false
1897+
}
1898+
18911899
fn is_iterator_used_after_while_let<'a, 'tcx: 'a>(cx: &LateContext<'a, 'tcx>, iter_expr: &'tcx Expr) -> bool {
18921900
let def_id = match var_def_id(cx, iter_expr) {
18931901
Some(id) => id,
@@ -1962,13 +1970,9 @@ fn extract_expr_from_first_stmt(block: &Block) -> Option<&Expr> {
19621970
if block.stmts.is_empty() {
19631971
return None;
19641972
}
1965-
if let StmtKind::Decl(ref decl, _) = block.stmts[0].node {
1966-
if let DeclKind::Local(ref local) = decl.node {
1967-
if let Some(ref expr) = local.init {
1968-
Some(expr)
1969-
} else {
1970-
None
1971-
}
1973+
if let StmtKind::Local(ref local) = block.stmts[0].node {
1974+
if let Some(ref expr) = local.init {
1975+
Some(expr)
19721976
} else {
19731977
None
19741978
}
@@ -1982,8 +1986,8 @@ fn extract_first_expr(block: &Block) -> Option<&Expr> {
19821986
match block.expr {
19831987
Some(ref expr) if block.stmts.is_empty() => Some(expr),
19841988
None if !block.stmts.is_empty() => match block.stmts[0].node {
1985-
StmtKind::Expr(ref expr, _) | StmtKind::Semi(ref expr, _) => Some(expr),
1986-
StmtKind::Decl(..) => None,
1989+
StmtKind::Expr(ref expr) | StmtKind::Semi(ref expr) => Some(expr),
1990+
StmtKind::Local(..) | StmtKind::Item(..) => None,
19871991
},
19881992
_ => None,
19891993
}
@@ -2081,9 +2085,9 @@ struct InitializeVisitor<'a, 'tcx: 'a> {
20812085
}
20822086

20832087
impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
2084-
fn visit_decl(&mut self, decl: &'tcx Decl) {
2088+
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
20852089
// Look for declarations of the variable
2086-
if let DeclKind::Local(ref local) = decl.node {
2090+
if let StmtKind::Local(ref local) = stmt.node {
20872091
if local.pat.id == self.var_id {
20882092
if let PatKind::Binding(_, _, ident, _) = local.pat.node {
20892093
self.name = Some(ident.name);
@@ -2100,7 +2104,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
21002104
}
21012105
}
21022106
}
2103-
walk_decl(self, decl);
2107+
walk_stmt(self, stmt);
21042108
}
21052109

21062110
fn visit_expr(&mut self, expr: &'tcx Expr) {
@@ -2247,7 +2251,7 @@ struct LoopNestVisitor {
22472251

22482252
impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
22492253
fn visit_stmt(&mut self, stmt: &'tcx Stmt) {
2250-
if stmt.node.id() == self.id {
2254+
if stmt.id == self.id {
22512255
self.nesting = LookFurther;
22522256
} else if self.nesting == Unknown {
22532257
walk_stmt(self, stmt);

clippy_lints/src/map_unit_fn.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,10 @@ fn reduce_unit_expression<'a>(cx: &LateContext<'_, '_>, expr: &'a hir::Expr) ->
131131
// If block only contains statements,
132132
// reduce `{ X; }` to `X` or `X;`
133133
match inner_stmt.node {
134-
hir::StmtKind::Decl(ref d, _) => Some(d.span),
135-
hir::StmtKind::Expr(ref e, _) => Some(e.span),
136-
hir::StmtKind::Semi(_, _) => Some(inner_stmt.span),
134+
hir::StmtKind::Local(ref local) => Some(local.span),
135+
hir::StmtKind::Expr(ref e) => Some(e.span),
136+
hir::StmtKind::Semi(..) => Some(inner_stmt.span),
137+
hir::StmtKind::Item(..) => None,
137138
}
138139
},
139140
_ => {
@@ -250,7 +251,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Pass {
250251
return;
251252
}
252253

253-
if let hir::StmtKind::Semi(ref expr, _) = stmt.node {
254+
if let hir::StmtKind::Semi(ref expr) = stmt.node {
254255
if let Some(arglists) = method_chain_args(expr, &["map"]) {
255256
lint_map_unit_fn(cx, stmt, expr, arglists[0]);
256257
}

0 commit comments

Comments
 (0)