Skip to content

Commit 770792f

Browse files
committed
Auto merge of #84980 - flip1995:clippyup, r=Manishearth
Update Clippy Bi-weekly Clippy update. r? `@Manishearth`
2 parents ca712bc + c24058b commit 770792f

Some content is hidden

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

66 files changed

+2327
-1060
lines changed

Cargo.lock

+4-3
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ dependencies = [
548548

549549
[[package]]
550550
name = "clippy"
551-
version = "0.1.53"
551+
version = "0.1.54"
552552
dependencies = [
553553
"cargo_metadata 0.12.0",
554554
"clippy-mini-macro-test",
@@ -585,7 +585,7 @@ dependencies = [
585585

586586
[[package]]
587587
name = "clippy_lints"
588-
version = "0.1.53"
588+
version = "0.1.54"
589589
dependencies = [
590590
"cargo_metadata 0.12.0",
591591
"clippy_utils",
@@ -597,14 +597,15 @@ dependencies = [
597597
"rustc-semver",
598598
"semver 0.11.0",
599599
"serde",
600+
"serde_json",
600601
"toml",
601602
"unicode-normalization",
602603
"url 2.1.1",
603604
]
604605

605606
[[package]]
606607
name = "clippy_utils"
607-
version = "0.1.53"
608+
version = "0.1.54"
608609
dependencies = [
609610
"if_chain",
610611
"itertools 0.9.0",

src/tools/clippy/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ out
2929

3030
# gh pages docs
3131
util/gh-pages/lints.json
32+
**/metadata_collection.json
3233

3334
# rustfmt backups
3435
*.rs.bk

src/tools/clippy/CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ which `IntelliJ Rust` will be able to understand.
118118
Run `cargo dev ide_setup --repo-path <repo-path>` where `<repo-path>` is a path to the rustc repo
119119
you just cloned.
120120
The command will add path-dependencies pointing towards rustc-crates inside the rustc repo to
121-
Clippys `Cargo.toml`s and should allow rust-analyzer to understand most of the types that Clippy uses.
121+
Clippys `Cargo.toml`s and should allow `IntelliJ Rust` to understand most of the types that Clippy uses.
122122
Just make sure to remove the dependencies again before finally making a pull request!
123123

124124
[rustc_repo]: https://github.com/rust-lang/rust/

src/tools/clippy/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.53"
3+
version = "0.1.54"
44
authors = ["The Rust Clippy Developers"]
55
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
66
repository = "https://github.com/rust-lang/rust-clippy"
@@ -52,6 +52,7 @@ rustc_tools_util = { version = "0.2.0", path = "rustc_tools_util" }
5252
deny-warnings = []
5353
integration = ["tempfile"]
5454
internal-lints = ["clippy_lints/internal-lints"]
55+
metadata-collector-lint = ["internal-lints", "clippy_lints/metadata-collector-lint"]
5556

5657
[package.metadata.rust-analyzer]
5758
# This package uses #[feature(rustc_private)]

src/tools/clippy/clippy_lints/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "clippy_lints"
33
# begin automatic update
4-
version = "0.1.53"
4+
version = "0.1.54"
55
# end automatic update
66
authors = ["The Rust Clippy Developers"]
77
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
@@ -20,6 +20,7 @@ pulldown-cmark = { version = "0.8", default-features = false }
2020
quine-mc_cluskey = "0.2.2"
2121
regex-syntax = "0.6"
2222
serde = { version = "1.0", features = ["derive"] }
23+
serde_json = { version = "1.0", optional = true }
2324
toml = "0.5.3"
2425
unicode-normalization = "0.1"
2526
semver = "0.11"
@@ -32,6 +33,7 @@ url = { version = "2.1.0", features = ["serde"] }
3233
deny-warnings = []
3334
# build clippy with internal lints enabled, off by default
3435
internal-lints = ["clippy_utils/internal-lints"]
36+
metadata-collector-lint = ["serde_json", "clippy_utils/metadata-collector-lint"]
3537

3638
[package.metadata.rust-analyzer]
3739
# This crate uses #[feature(rustc_private)]

src/tools/clippy/clippy_lints/src/comparison_chain.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use clippy_utils::ty::implements_trait;
3-
use clippy_utils::{get_trait_def_id, if_sequence, is_else_clause, paths, SpanlessEq};
3+
use clippy_utils::{get_trait_def_id, if_sequence, in_constant, is_else_clause, paths, SpanlessEq};
44
use rustc_hir::{BinOpKind, Expr, ExprKind};
55
use rustc_lint::{LateContext, LateLintPass};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -64,6 +64,10 @@ impl<'tcx> LateLintPass<'tcx> for ComparisonChain {
6464
return;
6565
}
6666

67+
if in_constant(cx, expr.hir_id) {
68+
return;
69+
}
70+
6771
// Check that there exists at least one explicit else condition
6872
let (conds, _) = if_sequence(expr);
6973
if conds.len() < 2 {

src/tools/clippy/clippy_lints/src/default.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use clippy_utils::diagnostics::{span_lint_and_note, span_lint_and_sugg};
22
use clippy_utils::source::snippet_with_macro_callsite;
3-
use clippy_utils::{any_parent_is_automatically_derived, contains_name, match_def_path, paths};
3+
use clippy_utils::{any_parent_is_automatically_derived, contains_name, in_macro, match_def_path, paths};
44
use if_chain::if_chain;
55
use rustc_data_structures::fx::FxHashSet;
66
use rustc_errors::Applicability;
@@ -75,6 +75,7 @@ impl_lint_pass!(Default => [DEFAULT_TRAIT_ACCESS, FIELD_REASSIGN_WITH_DEFAULT]);
7575
impl LateLintPass<'_> for Default {
7676
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
7777
if_chain! {
78+
if !in_macro(expr.span);
7879
// Avoid cases already linted by `field_reassign_with_default`
7980
if !self.reassigned_linted.contains(&expr.span);
8081
if let ExprKind::Call(path, ..) = expr.kind;

src/tools/clippy/clippy_lints/src/eval_order_dependence.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_note};
22
use clippy_utils::{get_parent_expr, path_to_local, path_to_local_id};
3+
use if_chain::if_chain;
34
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
45
use rustc_hir::{BinOpKind, Block, Expr, ExprKind, Guard, HirId, Local, Node, Stmt, StmtKind};
56
use rustc_lint::{LateContext, LateLintPass};
@@ -70,20 +71,19 @@ declare_lint_pass!(EvalOrderDependence => [EVAL_ORDER_DEPENDENCE, DIVERGING_SUB_
7071
impl<'tcx> LateLintPass<'tcx> for EvalOrderDependence {
7172
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) {
7273
// Find a write to a local variable.
73-
match expr.kind {
74-
ExprKind::Assign(lhs, ..) | ExprKind::AssignOp(_, lhs, _) => {
75-
if let Some(var) = path_to_local(lhs) {
76-
let mut visitor = ReadVisitor {
77-
cx,
78-
var,
79-
write_expr: expr,
80-
last_expr: expr,
81-
};
82-
check_for_unsequenced_reads(&mut visitor);
83-
}
84-
},
85-
_ => {},
86-
}
74+
let var = if_chain! {
75+
if let ExprKind::Assign(lhs, ..) | ExprKind::AssignOp(_, lhs, _) = expr.kind;
76+
if let Some(var) = path_to_local(lhs);
77+
if expr.span.desugaring_kind().is_none();
78+
then { var } else { return; }
79+
};
80+
let mut visitor = ReadVisitor {
81+
cx,
82+
var,
83+
write_expr: expr,
84+
last_expr: expr,
85+
};
86+
check_for_unsequenced_reads(&mut visitor);
8787
}
8888
fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx Stmt<'_>) {
8989
match stmt.kind {
@@ -305,7 +305,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ReadVisitor<'a, 'tcx> {
305305
self.cx,
306306
EVAL_ORDER_DEPENDENCE,
307307
expr.span,
308-
"unsequenced read of a variable",
308+
&format!("unsequenced read of `{}`", self.cx.tcx.hir().name(self.var)),
309309
Some(self.write_expr.span),
310310
"whether read occurs before this write depends on evaluation order",
311311
);

0 commit comments

Comments
 (0)