Skip to content

Commit 54efba1

Browse files
committed
Merge remote-tracking branch 'upstream/master' into rustup
2 parents 72df99a + de80188 commit 54efba1

File tree

101 files changed

+2061
-484
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+2061
-484
lines changed

.github/workflows/clippy_dev.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ jobs:
4242
run: cargo build --features deny-warnings
4343
working-directory: clippy_dev
4444

45-
- name: Test limit_stderr_length
46-
run: cargo dev limit_stderr_length
47-
4845
- name: Test update_lints
4946
run: cargo dev update_lints --check
5047

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2712,7 +2712,6 @@ Released 2018-09-13
27122712
[`integer_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_arithmetic
27132713
[`integer_division`]: https://rust-lang.github.io/rust-clippy/master/index.html#integer_division
27142714
[`into_iter_on_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#into_iter_on_ref
2715-
[`invalid_atomic_ordering`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_atomic_ordering
27162715
[`invalid_null_ptr_usage`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_null_ptr_usage
27172716
[`invalid_regex`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_regex
27182717
[`invalid_upcast_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#invalid_upcast_comparisons
@@ -2754,6 +2753,7 @@ Released 2018-09-13
27542753
[`manual_ok_or`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_ok_or
27552754
[`manual_range_contains`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains
27562755
[`manual_saturating_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_saturating_arithmetic
2756+
[`manual_split_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_split_once
27572757
[`manual_str_repeat`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_str_repeat
27582758
[`manual_strip`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_strip
27592759
[`manual_swap`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_swap
@@ -2795,6 +2795,7 @@ Released 2018-09-13
27952795
[`missing_safety_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#missing_safety_doc
27962796
[`mistyped_literal_suffixes`]: https://rust-lang.github.io/rust-clippy/master/index.html#mistyped_literal_suffixes
27972797
[`mixed_case_hex_literals`]: https://rust-lang.github.io/rust-clippy/master/index.html#mixed_case_hex_literals
2798+
[`mod_module_files`]: https://rust-lang.github.io/rust-clippy/master/index.html#mod_module_files
27982799
[`module_inception`]: https://rust-lang.github.io/rust-clippy/master/index.html#module_inception
27992800
[`module_name_repetitions`]: https://rust-lang.github.io/rust-clippy/master/index.html#module_name_repetitions
28002801
[`modulo_arithmetic`]: https://rust-lang.github.io/rust-clippy/master/index.html#modulo_arithmetic
@@ -2828,6 +2829,7 @@ Released 2018-09-13
28282829
[`needless_update`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_update
28292830
[`neg_cmp_op_on_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#neg_cmp_op_on_partial_ord
28302831
[`neg_multiply`]: https://rust-lang.github.io/rust-clippy/master/index.html#neg_multiply
2832+
[`negative_feature_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#negative_feature_names
28312833
[`never_loop`]: https://rust-lang.github.io/rust-clippy/master/index.html#never_loop
28322834
[`new_ret_no_self`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_ret_no_self
28332835
[`new_without_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
@@ -2881,6 +2883,7 @@ Released 2018-09-13
28812883
[`redundant_closure_call`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_call
28822884
[`redundant_closure_for_method_calls`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
28832885
[`redundant_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else
2886+
[`redundant_feature_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_feature_names
28842887
[`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
28852888
[`redundant_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern
28862889
[`redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
@@ -2903,6 +2906,7 @@ Released 2018-09-13
29032906
[`search_is_some`]: https://rust-lang.github.io/rust-clippy/master/index.html#search_is_some
29042907
[`self_assignment`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_assignment
29052908
[`self_named_constructors`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_named_constructors
2909+
[`self_named_module_files`]: https://rust-lang.github.io/rust-clippy/master/index.html#self_named_module_files
29062910
[`semicolon_if_nothing_returned`]: https://rust-lang.github.io/rust-clippy/master/index.html#semicolon_if_nothing_returned
29072911
[`serde_api_misuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#serde_api_misuse
29082912
[`shadow_reuse`]: https://rust-lang.github.io/rust-clippy/master/index.html#shadow_reuse

clippy_dev/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub mod fmt;
1717
pub mod new_lint;
1818
pub mod serve;
1919
pub mod setup;
20-
pub mod stderr_length_check;
2120
pub mod update_lints;
2221

2322
static DEC_CLIPPY_LINT_RE: SyncLazy<Regex> = SyncLazy::new(|| {

clippy_dev/src/main.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![warn(rust_2018_idioms, unused_lifetimes)]
44

55
use clap::{App, AppSettings, Arg, ArgMatches, SubCommand};
6-
use clippy_dev::{bless, fmt, new_lint, serve, setup, stderr_length_check, update_lints};
6+
use clippy_dev::{bless, fmt, new_lint, serve, setup, update_lints};
77
fn main() {
88
let matches = get_clap_config();
99

@@ -33,9 +33,6 @@ fn main() {
3333
Err(e) => eprintln!("Unable to create lint: {}", e),
3434
}
3535
},
36-
("limit_stderr_length", _) => {
37-
stderr_length_check::check();
38-
},
3936
("setup", Some(sub_command)) => match sub_command.subcommand() {
4037
("intellij", Some(matches)) => setup::intellij::setup_rustc_src(
4138
matches
@@ -152,10 +149,6 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
152149
.takes_value(true),
153150
),
154151
)
155-
.subcommand(
156-
SubCommand::with_name("limit_stderr_length")
157-
.about("Ensures that stderr files do not grow longer than a certain amount of lines."),
158-
)
159152
.subcommand(
160153
SubCommand::with_name("setup")
161154
.about("Support for setting up your personal development environment")

clippy_dev/src/stderr_length_check.rs

Lines changed: 0 additions & 51 deletions
This file was deleted.

clippy_lints/src/bytecount.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_sugg;
22
use clippy_utils::source::snippet_with_applicability;
33
use clippy_utils::ty::match_type;
4-
use clippy_utils::visitors::LocalUsedVisitor;
4+
use clippy_utils::visitors::is_local_used;
55
use clippy_utils::{path_to_local_id, paths, peel_ref_operators, remove_blocks, strip_pat_refs};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
@@ -65,7 +65,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
6565
return;
6666
};
6767
if ty::Uint(UintTy::U8) == *cx.typeck_results().expr_ty(needle).peel_refs().kind();
68-
if !LocalUsedVisitor::new(cx, arg_id).check_expr(needle);
68+
if !is_local_used(cx, needle, arg_id);
6969
then {
7070
let haystack = if let ExprKind::MethodCall(path, _, args, _) =
7171
filter_recv.kind {

clippy_lints/src/collapsible_match.rs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use clippy_utils::diagnostics::span_lint_and_then;
2-
use clippy_utils::visitors::LocalUsedVisitor;
2+
use clippy_utils::visitors::is_local_used;
33
use clippy_utils::{higher, is_lang_ctor, is_unit_expr, path_to_local, peel_ref_operators, SpanlessEq};
44
use if_chain::if_chain;
55
use rustc_hir::LangItem::OptionNone;
@@ -56,11 +56,11 @@ impl<'tcx> LateLintPass<'tcx> for CollapsibleMatch {
5656
check_arm(cx, true, arm.pat, arm.body, arm.guard.as_ref(), Some(els_arm.body));
5757
}
5858
}
59-
}
59+
},
6060
Some(IfLetOrMatch::IfLet(_, pat, body, els)) => {
6161
check_arm(cx, false, pat, body, None, els);
62-
}
63-
None => {}
62+
},
63+
None => {},
6464
}
6565
}
6666
}
@@ -71,7 +71,7 @@ fn check_arm<'tcx>(
7171
outer_pat: &'tcx Pat<'tcx>,
7272
outer_then_body: &'tcx Expr<'tcx>,
7373
outer_guard: Option<&'tcx Guard<'tcx>>,
74-
outer_else_body: Option<&'tcx Expr<'tcx>>
74+
outer_else_body: Option<&'tcx Expr<'tcx>>,
7575
) {
7676
let inner_expr = strip_singleton_blocks(outer_then_body);
7777
if_chain! {
@@ -106,14 +106,13 @@ fn check_arm<'tcx>(
106106
(Some(a), Some(b)) => SpanlessEq::new(cx).eq_expr(a, b),
107107
};
108108
// the binding must not be used in the if guard
109-
let mut used_visitor = LocalUsedVisitor::new(cx, binding_id);
110-
if outer_guard.map_or(true, |(Guard::If(e) | Guard::IfLet(_, e))| !used_visitor.check_expr(e));
109+
if outer_guard.map_or(true, |(Guard::If(e) | Guard::IfLet(_, e))| !is_local_used(cx, *e, binding_id));
111110
// ...or anywhere in the inner expression
112111
if match inner {
113112
IfLetOrMatch::IfLet(_, _, body, els) => {
114-
!used_visitor.check_expr(body) && els.map_or(true, |e| !used_visitor.check_expr(e))
113+
!is_local_used(cx, body, binding_id) && els.map_or(true, |e| !is_local_used(cx, e, binding_id))
115114
},
116-
IfLetOrMatch::Match(_, arms, ..) => !arms.iter().any(|arm| used_visitor.check_arm(arm)),
115+
IfLetOrMatch::Match(_, arms, ..) => !arms.iter().any(|arm| is_local_used(cx, arm, binding_id)),
117116
};
118117
then {
119118
let msg = format!(
@@ -154,16 +153,26 @@ fn strip_singleton_blocks<'hir>(mut expr: &'hir Expr<'hir>) -> &'hir Expr<'hir>
154153
enum IfLetOrMatch<'hir> {
155154
Match(&'hir Expr<'hir>, &'hir [Arm<'hir>], MatchSource),
156155
/// scrutinee, pattern, then block, else block
157-
IfLet(&'hir Expr<'hir>, &'hir Pat<'hir>, &'hir Expr<'hir>, Option<&'hir Expr<'hir>>),
156+
IfLet(
157+
&'hir Expr<'hir>,
158+
&'hir Pat<'hir>,
159+
&'hir Expr<'hir>,
160+
Option<&'hir Expr<'hir>>,
161+
),
158162
}
159163

160164
impl<'hir> IfLetOrMatch<'hir> {
161165
fn parse(cx: &LateContext<'_>, expr: &Expr<'hir>) -> Option<Self> {
162166
match expr.kind {
163167
ExprKind::Match(expr, arms, source) => Some(Self::Match(expr, arms, source)),
164-
_ => higher::IfLet::hir(cx, expr).map(|higher::IfLet { let_expr, let_pat, if_then, if_else }| {
165-
Self::IfLet(let_expr, let_pat, if_then, if_else)
166-
})
168+
_ => higher::IfLet::hir(cx, expr).map(
169+
|higher::IfLet {
170+
let_expr,
171+
let_pat,
172+
if_then,
173+
if_else,
174+
}| { Self::IfLet(let_expr, let_pat, if_then, if_else) },
175+
),
167176
}
168177
}
169178
}

clippy_lints/src/copies.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ declare_clippy_lint! {
148148
/// };
149149
/// ```
150150
pub BRANCHES_SHARING_CODE,
151-
complexity,
151+
nursery,
152152
"`if` statement with shared code in all blocks"
153153
}
154154

clippy_lints/src/derive.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ declare_clippy_lint! {
105105
/// nothing more than copy the object, which is what `#[derive(Copy, Clone)]`
106106
/// gets you.
107107
///
108-
/// ### Known problems
109-
/// Bounds of generic types are sometimes wrong: https://github.com/rust-lang/rust/issues/26925
110-
///
111108
/// ### Example
112109
/// ```rust,ignore
113110
/// #[derive(Copy)]

clippy_lints/src/entry.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use clippy_utils::{
99
use core::fmt::Write;
1010
use rustc_errors::Applicability;
1111
use rustc_hir::{
12+
hir_id::HirIdSet,
1213
intravisit::{walk_expr, ErasedMap, NestedVisitorMap, Visitor},
13-
Block, Expr, ExprKind, Guard, HirId, Local, Stmt, StmtKind, UnOp,
14+
Block, Expr, ExprKind, Guard, HirId, Pat, Stmt, StmtKind, UnOp,
1415
};
1516
use rustc_lint::{LateContext, LateLintPass};
1617
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -338,6 +339,8 @@ struct InsertSearcher<'cx, 'tcx> {
338339
edits: Vec<Edit<'tcx>>,
339340
/// A stack of loops the visitor is currently in.
340341
loops: Vec<HirId>,
342+
/// Local variables created in the expression. These don't need to be captured.
343+
locals: HirIdSet,
341344
}
342345
impl<'tcx> InsertSearcher<'_, 'tcx> {
343346
/// Visit the expression as a branch in control flow. Multiple insert calls can be used, but
@@ -385,13 +388,16 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
385388
}
386389
},
387390
StmtKind::Expr(e) => self.visit_expr(e),
388-
StmtKind::Local(Local { init: Some(e), .. }) => {
389-
self.allow_insert_closure &= !self.in_tail_pos;
390-
self.in_tail_pos = false;
391-
self.is_single_insert = false;
392-
self.visit_expr(e);
391+
StmtKind::Local(l) => {
392+
self.visit_pat(l.pat);
393+
if let Some(e) = l.init {
394+
self.allow_insert_closure &= !self.in_tail_pos;
395+
self.in_tail_pos = false;
396+
self.is_single_insert = false;
397+
self.visit_expr(e);
398+
}
393399
},
394-
_ => {
400+
StmtKind::Item(_) => {
395401
self.allow_insert_closure &= !self.in_tail_pos;
396402
self.is_single_insert = false;
397403
},
@@ -473,6 +479,7 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
473479
// Each branch may contain it's own insert expression.
474480
let mut is_map_used = self.is_map_used;
475481
for arm in arms {
482+
self.visit_pat(arm.pat);
476483
if let Some(Guard::If(guard) | Guard::IfLet(_, guard)) = arm.guard {
477484
self.visit_non_tail_expr(guard);
478485
}
@@ -498,7 +505,8 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
498505
},
499506
_ => {
500507
self.allow_insert_closure &= !self.in_tail_pos;
501-
self.allow_insert_closure &= can_move_expr_to_closure_no_visit(self.cx, expr, &self.loops);
508+
self.allow_insert_closure &=
509+
can_move_expr_to_closure_no_visit(self.cx, expr, &self.loops, &self.locals);
502510
// Sub expressions are no longer in the tail position.
503511
self.is_single_insert = false;
504512
self.in_tail_pos = false;
@@ -507,6 +515,12 @@ impl<'tcx> Visitor<'tcx> for InsertSearcher<'_, 'tcx> {
507515
},
508516
}
509517
}
518+
519+
fn visit_pat(&mut self, p: &'tcx Pat<'tcx>) {
520+
p.each_binding_or_first(&mut |_, id, _, _| {
521+
self.locals.insert(id);
522+
});
523+
}
510524
}
511525

512526
struct InsertSearchResults<'tcx> {
@@ -632,6 +646,7 @@ fn find_insert_calls(
632646
in_tail_pos: true,
633647
is_single_insert: true,
634648
loops: Vec::new(),
649+
locals: HirIdSet::default(),
635650
};
636651
s.visit_expr(expr);
637652
let allow_insert_closure = s.allow_insert_closure;

0 commit comments

Comments
 (0)