Skip to content

Commit 5416a71

Browse files
committed
Merge remote-tracking branch 'origin/master' into 8282-single-match
2 parents 49ae73b + a26c412 commit 5416a71

File tree

118 files changed

+2418
-1031
lines changed

Some content is hidden

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

118 files changed

+2418
-1031
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,7 +981,7 @@ Released 2021-03-25
981981
[#6532](https://github.com/rust-lang/rust-clippy/pull/6532)
982982
* [`single_match`] Suggest `if` over `if let` when possible
983983
[#6574](https://github.com/rust-lang/rust-clippy/pull/6574)
984-
* [`ref_in_deref`] Use parentheses correctly in suggestion
984+
* `ref_in_deref` Use parentheses correctly in suggestion
985985
[#6609](https://github.com/rust-lang/rust-clippy/pull/6609)
986986
* [`stable_sort_primitive`] Clarify error message
987987
[#6611](https://github.com/rust-lang/rust-clippy/pull/6611)
@@ -3049,6 +3049,7 @@ Released 2018-09-13
30493049
[`iter_not_returning_iterator`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_not_returning_iterator
30503050
[`iter_nth`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth
30513051
[`iter_nth_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_nth_zero
3052+
[`iter_overeager_cloned`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_overeager_cloned
30523053
[`iter_skip_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next
30533054
[`iterator_step_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iterator_step_by_zero
30543055
[`just_underscores_and_digits`]: https://rust-lang.github.io/rust-clippy/master/index.html#just_underscores_and_digits
@@ -3226,7 +3227,6 @@ Released 2018-09-13
32263227
[`redundant_slicing`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_slicing
32273228
[`redundant_static_lifetimes`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes
32283229
[`ref_binding_to_reference`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_binding_to_reference
3229-
[`ref_in_deref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_in_deref
32303230
[`ref_option_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#ref_option_ref
32313231
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
32323232
[`repeat_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#repeat_once

COPYRIGHT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright 2014-2021 The Rust Project Developers
1+
Copyright 2014-2022 The Rust Project Developers
22

33
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
44
http://www.apache.org/licenses/LICENSE-2.0> or the MIT license

LICENSE-APACHE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work.
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2014-2021 The Rust Project Developers
189+
Copyright 2014-2022 The Rust Project Developers
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2014-2021 The Rust Project Developers
3+
Copyright (c) 2014-2022 The Rust Project Developers
44

55
Permission is hereby granted, free of charge, to any
66
person obtaining a copy of this software and associated

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ If you want to contribute to Clippy, you can find more information in [CONTRIBUT
238238

239239
## License
240240

241-
Copyright 2014-2021 The Rust Project Developers
241+
Copyright 2014-2022 The Rust Project Developers
242242

243243
Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
244244
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)> or the MIT license

clippy_dev/src/bless.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ use walkdir::WalkDir;
99

1010
use crate::clippy_project_root;
1111

12+
#[cfg(not(windows))]
13+
static CARGO_CLIPPY_EXE: &str = "cargo-clippy";
14+
#[cfg(windows)]
15+
static CARGO_CLIPPY_EXE: &str = "cargo-clippy.exe";
16+
1217
static CLIPPY_BUILD_TIME: SyncLazy<Option<std::time::SystemTime>> = SyncLazy::new(|| {
1318
let mut path = std::env::current_exe().unwrap();
14-
path.set_file_name("cargo-clippy");
19+
path.set_file_name(CARGO_CLIPPY_EXE);
1520
fs::metadata(path).ok()?.modified().ok()
1621
});
1722

clippy_dev/src/lint.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ pub fn run(filename: &str) {
77
.args(["-Z", "no-codegen"])
88
.args(["--edition", "2021"])
99
.arg(filename)
10-
.env("__CLIPPY_INTERNAL_TESTS", "true")
1110
.status()
1211
.expect("failed to run cargo")
1312
.code();

clippy_lints/src/bit_mask.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ declare_clippy_lint! {
1818
/// {`!=`, `>=`, `>`, `!=`, `>=`, `>`}) can be determined from the following
1919
/// table:
2020
///
21-
/// |Comparison |Bit Op|Example |is always|Formula |
22-
/// |------------|------|------------|---------|----------------------|
23-
/// |`==` or `!=`| `&` |`x & 2 == 3`|`false` |`c & m != c` |
24-
/// |`<` or `>=`| `&` |`x & 2 < 3` |`true` |`m < c` |
25-
/// |`>` or `<=`| `&` |`x & 1 > 1` |`false` |`m <= c` |
26-
/// |`==` or `!=`| `|` |`x | 1 == 0`|`false` |`c | m != c` |
27-
/// |`<` or `>=`| `|` |`x | 1 < 1` |`false` |`m >= c` |
28-
/// |`<=` or `>` | `|` |`x | 1 > 0` |`true` |`m > c` |
21+
/// |Comparison |Bit Op|Example |is always|Formula |
22+
/// |------------|------|-------------|---------|----------------------|
23+
/// |`==` or `!=`| `&` |`x & 2 == 3` |`false` |`c & m != c` |
24+
/// |`<` or `>=`| `&` |`x & 2 < 3` |`true` |`m < c` |
25+
/// |`>` or `<=`| `&` |`x & 1 > 1` |`false` |`m <= c` |
26+
/// |`==` or `!=`| `\|` |`x \| 1 == 0`|`false` |`c \| m != c` |
27+
/// |`<` or `>=`| `\|` |`x \| 1 < 1` |`false` |`m >= c` |
28+
/// |`<=` or `>` | `\|` |`x \| 1 > 0` |`true` |`m > c` |
2929
///
3030
/// ### Why is this bad?
3131
/// If the bits that the comparison cares about are always
@@ -53,10 +53,10 @@ declare_clippy_lint! {
5353
/// without changing the outcome. The basic structure can be seen in the
5454
/// following table:
5555
///
56-
/// |Comparison| Bit Op |Example |equals |
57-
/// |----------|---------|-----------|-------|
58-
/// |`>` / `<=`|`|` / `^`|`x | 2 > 3`|`x > 3`|
59-
/// |`<` / `>=`|`|` / `^`|`x ^ 1 < 4`|`x < 4`|
56+
/// |Comparison| Bit Op |Example |equals |
57+
/// |----------|----------|------------|-------|
58+
/// |`>` / `<=`|`\|` / `^`|`x \| 2 > 3`|`x > 3`|
59+
/// |`<` / `>=`|`\|` / `^`|`x ^ 1 < 4` |`x < 4`|
6060
///
6161
/// ### Why is this bad?
6262
/// Not equally evil as [`bad_bit_mask`](#bad_bit_mask),

clippy_lints/src/borrow_as_ptr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::{meets_msrv, msrvs};
55
use if_chain::if_chain;
66
use rustc_errors::Applicability;
77
use rustc_hir::{BorrowKind, Expr, ExprKind, Mutability, TyKind};
8-
use rustc_lint::{LateContext, LateLintPass};
8+
use rustc_lint::{LateContext, LateLintPass, LintContext};
99
use rustc_semver::RustcVersion;
1010
use rustc_session::{declare_tool_lint, impl_lint_pass};
1111

@@ -94,4 +94,6 @@ impl<'tcx> LateLintPass<'tcx> for BorrowAsPtr {
9494
}
9595
}
9696
}
97+
98+
extract_msrv_attr!(LateContext);
9799
}

clippy_lints/src/copies.rs

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste {
183183
lint_same_cond(cx, &conds);
184184
lint_same_fns_in_if_cond(cx, &conds);
185185
// Block duplication
186-
lint_same_then_else(cx, &blocks, conds.len() == blocks.len(), expr);
186+
lint_same_then_else(cx, &conds, &blocks, conds.len() == blocks.len(), expr);
187187
}
188188
}
189189
}
@@ -192,6 +192,7 @@ impl<'tcx> LateLintPass<'tcx> for CopyAndPaste {
192192
/// Implementation of `BRANCHES_SHARING_CODE` and `IF_SAME_THEN_ELSE` if the blocks are equal.
193193
fn lint_same_then_else<'tcx>(
194194
cx: &LateContext<'tcx>,
195+
conds: &[&'tcx Expr<'_>],
195196
blocks: &[&Block<'tcx>],
196197
has_conditional_else: bool,
197198
expr: &'tcx Expr<'_>,
@@ -204,7 +205,7 @@ fn lint_same_then_else<'tcx>(
204205
// Check if each block has shared code
205206
let has_expr = blocks[0].expr.is_some();
206207

207-
let (start_eq, mut end_eq, expr_eq) = if let Some(block_eq) = scan_block_for_eq(cx, blocks) {
208+
let (start_eq, mut end_eq, expr_eq) = if let Some(block_eq) = scan_block_for_eq(cx, conds, blocks) {
208209
(block_eq.start_eq, block_eq.end_eq, block_eq.expr_eq)
209210
} else {
210211
return;
@@ -316,14 +317,14 @@ struct BlockEqual {
316317

317318
/// This function can also trigger the `IF_SAME_THEN_ELSE` in which case it'll return `None` to
318319
/// abort any further processing and avoid duplicate lint triggers.
319-
fn scan_block_for_eq(cx: &LateContext<'_>, blocks: &[&Block<'_>]) -> Option<BlockEqual> {
320+
fn scan_block_for_eq(cx: &LateContext<'_>, conds: &[&Expr<'_>], blocks: &[&Block<'_>]) -> Option<BlockEqual> {
320321
let mut start_eq = usize::MAX;
321322
let mut end_eq = usize::MAX;
322323
let mut expr_eq = true;
323-
let mut iter = blocks.windows(2);
324-
while let Some(&[win0, win1]) = iter.next() {
325-
let l_stmts = win0.stmts;
326-
let r_stmts = win1.stmts;
324+
let mut iter = blocks.windows(2).enumerate();
325+
while let Some((i, &[block0, block1])) = iter.next() {
326+
let l_stmts = block0.stmts;
327+
let r_stmts = block1.stmts;
327328

328329
// `SpanlessEq` now keeps track of the locals and is therefore context sensitive clippy#6752.
329330
// The comparison therefore needs to be done in a way that builds the correct context.
@@ -340,22 +341,26 @@ fn scan_block_for_eq(cx: &LateContext<'_>, blocks: &[&Block<'_>]) -> Option<Bloc
340341
it1.zip(it2)
341342
.fold(0, |acc, (l, r)| if evaluator.eq_stmt(l, r) { acc + 1 } else { 0 })
342343
};
343-
let block_expr_eq = both(&win0.expr, &win1.expr, |l, r| evaluator.eq_expr(l, r));
344+
let block_expr_eq = both(&block0.expr, &block1.expr, |l, r| evaluator.eq_expr(l, r));
344345

345346
// IF_SAME_THEN_ELSE
346347
if_chain! {
347348
if block_expr_eq;
348349
if l_stmts.len() == r_stmts.len();
349350
if l_stmts.len() == current_start_eq;
350-
if !is_lint_allowed(cx, IF_SAME_THEN_ELSE, win0.hir_id);
351-
if !is_lint_allowed(cx, IF_SAME_THEN_ELSE, win1.hir_id);
351+
// `conds` may have one last item than `blocks`.
352+
// Any `i` from `blocks.windows(2)` will exist in `conds`, but `i+1` may not exist on the last iteration.
353+
if !matches!(conds[i].kind, ExprKind::Let(..));
354+
if !matches!(conds.get(i + 1).map(|e| &e.kind), Some(ExprKind::Let(..)));
355+
if !is_lint_allowed(cx, IF_SAME_THEN_ELSE, block0.hir_id);
356+
if !is_lint_allowed(cx, IF_SAME_THEN_ELSE, block1.hir_id);
352357
then {
353358
span_lint_and_note(
354359
cx,
355360
IF_SAME_THEN_ELSE,
356-
win0.span,
361+
block0.span,
357362
"this `if` has identical blocks",
358-
Some(win1.span),
363+
Some(block1.span),
359364
"same as this",
360365
);
361366

0 commit comments

Comments
 (0)