Skip to content

Commit 1316702

Browse files
committed
Auto merge of #83480 - flip1995:clippyup, r=Dylan-DPC
Update Clippy Bi-weekly Clippy update. r? `@Manishearth`
2 parents 7637fd5 + 0f1ff45 commit 1316702

File tree

413 files changed

+5719
-2856
lines changed

Some content is hidden

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

413 files changed

+5719
-2856
lines changed

Cargo.lock

+5-8
Original file line numberDiff line numberDiff line change
@@ -557,18 +557,20 @@ dependencies = [
557557

558558
[[package]]
559559
name = "clippy"
560-
version = "0.1.52"
560+
version = "0.1.53"
561561
dependencies = [
562562
"cargo_metadata 0.12.0",
563563
"clippy-mini-macro-test",
564564
"clippy_lints",
565565
"compiletest_rs 0.6.0",
566566
"derive-new",
567+
"quote",
567568
"regex",
568569
"rustc-workspace-hack",
569570
"rustc_tools_util 0.2.0",
570571
"semver 0.11.0",
571572
"serde",
573+
"syn",
572574
"tempfile",
573575
"tester 0.9.0",
574576
]
@@ -579,37 +581,32 @@ version = "0.2.0"
579581

580582
[[package]]
581583
name = "clippy_lints"
582-
version = "0.1.52"
584+
version = "0.1.53"
583585
dependencies = [
584586
"cargo_metadata 0.12.0",
585587
"clippy_utils",
586588
"if_chain",
587589
"itertools 0.9.0",
588590
"pulldown-cmark 0.8.0",
589591
"quine-mc_cluskey",
590-
"quote",
591592
"regex-syntax",
592593
"rustc-semver",
593594
"semver 0.11.0",
594595
"serde",
595-
"smallvec 1.6.1",
596-
"syn",
597596
"toml",
598597
"unicode-normalization",
599598
"url 2.1.1",
600599
]
601600

602601
[[package]]
603602
name = "clippy_utils"
604-
version = "0.1.52"
603+
version = "0.1.53"
605604
dependencies = [
606605
"if_chain",
607606
"itertools 0.9.0",
608607
"regex-syntax",
609608
"rustc-semver",
610609
"serde",
611-
"smallvec 1.6.1",
612-
"toml",
613610
"unicode-normalization",
614611
]
615612

src/tools/clippy/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2103,6 +2103,7 @@ Released 2018-09-13
21032103
[`if_let_some_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_let_some_result
21042104
[`if_not_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else
21052105
[`if_same_then_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else
2106+
[`if_then_some_else_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none
21062107
[`ifs_same_cond`]: https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond
21072108
[`implicit_clone`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_clone
21082109
[`implicit_hasher`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_hasher

src/tools/clippy/CONTRIBUTING.md

+29-7
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ All contributors are expected to follow the [Rust Code of Conduct].
1818
- [Finding something to fix/improve](#finding-something-to-fiximprove)
1919
- [Writing code](#writing-code)
2020
- [Getting code-completion for rustc internals to work](#getting-code-completion-for-rustc-internals-to-work)
21+
- [IntelliJ Rust](#intellij-rust)
22+
- [Rust Analyzer](#rust-analyzer)
2123
- [How Clippy works](#how-clippy-works)
22-
- [Syncing changes between Clippy and `rust-lang/rust`](#syncing-changes-between-clippy-and-rust-langrust)
24+
- [Syncing changes between Clippy and [`rust-lang/rust`]](#syncing-changes-between-clippy-and-rust-langrust)
2325
- [Patching git-subtree to work with big repos](#patching-git-subtree-to-work-with-big-repos)
24-
- [Performing the sync from `rust-lang/rust` to Clippy](#performing-the-sync-from-rust-langrust-to-clippy)
25-
- [Performing the sync from Clippy to `rust-lang/rust`](#performing-the-sync-from-clippy-to-rust-langrust)
26+
- [Performing the sync from [`rust-lang/rust`] to Clippy](#performing-the-sync-from-rust-langrust-to-clippy)
27+
- [Performing the sync from Clippy to [`rust-lang/rust`]](#performing-the-sync-from-clippy-to-rust-langrust)
2628
- [Defining remotes](#defining-remotes)
2729
- [Issue and PR triage](#issue-and-pr-triage)
2830
- [Bors and Homu](#bors-and-homu)
@@ -105,21 +107,41 @@ quick read.
105107

106108
## Getting code-completion for rustc internals to work
107109

108-
Unfortunately, [`rust-analyzer`][ra_homepage] does not (yet?) understand how Clippy uses compiler-internals
110+
### IntelliJ Rust
111+
Unfortunately, [`IntelliJ Rust`][IntelliJ_rust_homepage] does not (yet?) understand how Clippy uses compiler-internals
109112
using `extern crate` and it also needs to be able to read the source files of the rustc-compiler which are not
110113
available via a `rustup` component at the time of writing.
111114
To work around this, you need to have a copy of the [rustc-repo][rustc_repo] available which can be obtained via
112115
`git clone https://github.com/rust-lang/rust/`.
113116
Then you can run a `cargo dev` command to automatically make Clippy use the rustc-repo via path-dependencies
114-
which rust-analyzer will be able to understand.
115-
Run `cargo dev ra_setup --repo-path <repo-path>` where `<repo-path>` is an absolute path to the rustc repo
117+
which `IntelliJ Rust` will be able to understand.
118+
Run `cargo dev ide_setup --repo-path <repo-path>` where `<repo-path>` is a path to the rustc repo
116119
you just cloned.
117120
The command will add path-dependencies pointing towards rustc-crates inside the rustc repo to
118121
Clippys `Cargo.toml`s and should allow rust-analyzer to understand most of the types that Clippy uses.
119122
Just make sure to remove the dependencies again before finally making a pull request!
120123

121-
[ra_homepage]: https://rust-analyzer.github.io/
122124
[rustc_repo]: https://github.com/rust-lang/rust/
125+
[IntelliJ_rust_homepage]: https://intellij-rust.github.io/
126+
127+
### Rust Analyzer
128+
As of [#6869][6869], [`rust-analyzer`][ra_homepage] can understand that Clippy uses compiler-internals
129+
using `extern crate` when `package.metadata.rust-analyzer.rustc_private` is set to `true` in Clippys `Cargo.toml.`
130+
You will required a `nightly` toolchain with the `rustc-dev` component installed.
131+
Make sure that in the `rust-analyzer` configuration, you set
132+
```
133+
{ "rust-analyzer.rustcSource": "discover" }
134+
```
135+
and
136+
```
137+
{ "rust-analyzer.updates.channel": "nightly" }
138+
```
139+
You should be able to see information on things like `Expr` or `EarlyContext` now if you hover them, also
140+
a lot more type hints.
141+
This will work with `rust-analyzer 2021-03-15` shipped in nightly `1.52.0-nightly (107896c32 2021-03-15)` or later.
142+
143+
[ra_homepage]: https://rust-analyzer.github.io/
144+
[6869]: https://github.com/rust-lang/rust-clippy/pull/6869
123145

124146
## How Clippy works
125147

src/tools/clippy/Cargo.toml

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.52"
3+
version = "0.1.53"
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"
@@ -37,6 +37,8 @@ clippy-mini-macro-test = { version = "0.2", path = "mini-macro" }
3737
serde = { version = "1.0", features = ["derive"] }
3838
derive-new = "0.5"
3939
regex = "1.4"
40+
quote = "1"
41+
syn = { version = "1", features = ["full"] }
4042

4143
# A noop dependency that changes in the Rust repository, it's a bit of a hack.
4244
# See the `src/tools/rustc-workspace-hack/README.md` file in `rust-lang/rust`

src/tools/clippy/clippy_dev/src/fmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub fn run(check: bool, verbose: bool) {
9090
},
9191
CliError::RaSetupActive => {
9292
eprintln!(
93-
"error: a local rustc repo is enabled as path dependency via `cargo dev ra_setup`.
93+
"error: a local rustc repo is enabled as path dependency via `cargo dev ide_setup`.
9494
Not formatting because that would format the local repo as well!
9595
Please revert the changes to Cargo.tomls first."
9696
);

src/tools/clippy/clippy_dev/src/ra_setup.rs src/tools/clippy/clippy_dev/src/ide_setup.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn inject_deps_into_manifest(
5555
// do not inject deps if we have aleady done so
5656
if cargo_toml.contains("[target.'cfg(NOT_A_PLATFORM)'.dependencies]") {
5757
eprintln!(
58-
"cargo dev ra_setup: warning: deps already found inside {}, doing nothing.",
58+
"cargo dev ide_setup: warning: deps already found inside {}, doing nothing.",
5959
manifest_path
6060
);
6161
return Ok(());

src/tools/clippy/clippy_dev/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ use walkdir::WalkDir;
1212

1313
pub mod bless;
1414
pub mod fmt;
15+
pub mod ide_setup;
1516
pub mod new_lint;
16-
pub mod ra_setup;
1717
pub mod serve;
1818
pub mod stderr_length_check;
1919
pub mod update_lints;

src/tools/clippy/clippy_dev/src/main.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
22

33
use clap::{App, Arg, ArgMatches, SubCommand};
4-
use clippy_dev::{bless, fmt, new_lint, ra_setup, serve, stderr_length_check, update_lints};
4+
use clippy_dev::{bless, fmt, ide_setup, new_lint, serve, stderr_length_check, update_lints};
55
fn main() {
66
let matches = get_clap_config();
77

@@ -34,7 +34,7 @@ fn main() {
3434
("limit_stderr_length", _) => {
3535
stderr_length_check::check();
3636
},
37-
("ra_setup", Some(matches)) => ra_setup::run(matches.value_of("rustc-repo-path")),
37+
("ide_setup", Some(matches)) => ide_setup::run(matches.value_of("rustc-repo-path")),
3838
("serve", Some(matches)) => {
3939
let port = matches.value_of("port").unwrap().parse().unwrap();
4040
let lint = matches.value_of("lint");
@@ -138,8 +138,8 @@ fn get_clap_config<'a>() -> ArgMatches<'a> {
138138
.about("Ensures that stderr files do not grow longer than a certain amount of lines."),
139139
)
140140
.subcommand(
141-
SubCommand::with_name("ra_setup")
142-
.about("Alter dependencies so rust-analyzer can find rustc internals")
141+
SubCommand::with_name("ide_setup")
142+
.about("Alter dependencies so Intellij Rust can find rustc internals")
143143
.arg(
144144
Arg::with_name("rustc-repo-path")
145145
.long("repo-path")

src/tools/clippy/clippy_lints/Cargo.toml

+1-4
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.52"
4+
version = "0.1.53"
55
# end automatic update
66
authors = ["The Rust Clippy Developers"]
77
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
@@ -20,16 +20,13 @@ 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-
smallvec = { version = "1", features = ["union"] }
2423
toml = "0.5.3"
2524
unicode-normalization = "0.1"
2625
semver = "0.11"
2726
rustc-semver = "1.1.0"
2827
# NOTE: cargo requires serde feat in its url dep
2928
# see <https://github.com/rust-lang/rust/pull/63587#issuecomment-522343864>
3029
url = { version = "2.1.0", features = ["serde"] }
31-
quote = "1"
32-
syn = { version = "1", features = ["full"] }
3330

3431
[features]
3532
deny-warnings = []

src/tools/clippy/clippy_lints/src/approx_const.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::span_lint;
1+
use clippy_utils::diagnostics::span_lint;
22
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
33
use rustc_hir::{Expr, ExprKind};
44
use rustc_lint::{LateContext, LateLintPass};

src/tools/clippy/clippy_lints/src/arithmetic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::consts::constant_simple;
2-
use crate::utils::span_lint;
2+
use clippy_utils::diagnostics::span_lint;
33
use rustc_hir as hir;
44
use rustc_lint::{LateContext, LateLintPass};
55
use rustc_session::{declare_tool_lint, impl_lint_pass};

src/tools/clippy/clippy_lints/src/as_conversions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
use clippy_utils::diagnostics::span_lint_and_help;
12
use rustc_ast::ast::{Expr, ExprKind};
23
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
34
use rustc_middle::lint::in_external_macro;
45
use rustc_session::{declare_lint_pass, declare_tool_lint};
56

6-
use crate::utils::span_lint_and_help;
7-
87
declare_clippy_lint! {
98
/// **What it does:** Checks for usage of `as` conversions.
109
///

src/tools/clippy/clippy_lints/src/asm_syntax.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::fmt;
22

3-
use crate::utils::span_lint_and_help;
3+
use clippy_utils::diagnostics::span_lint_and_help;
44
use rustc_ast::ast::{Expr, ExprKind, InlineAsmOptions};
55
use rustc_lint::{EarlyContext, EarlyLintPass, Lint};
66
use rustc_session::{declare_lint_pass, declare_tool_lint};

src/tools/clippy/clippy_lints/src/assertions_on_constants.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use crate::consts::{constant, Constant};
2-
use crate::utils::{is_direct_expn_of, is_expn_of, match_panic_call, snippet_opt, span_lint_and_help};
2+
use clippy_utils::diagnostics::span_lint_and_help;
3+
use clippy_utils::source::snippet_opt;
4+
use clippy_utils::{is_direct_expn_of, is_expn_of, match_panic_call};
35
use if_chain::if_chain;
46
use rustc_hir::{Expr, ExprKind, UnOp};
57
use rustc_lint::{LateContext, LateLintPass};

src/tools/clippy/clippy_lints/src/assign_ops.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use crate::utils::{
2-
eq_expr_value, get_trait_def_id, implements_trait, snippet_opt, span_lint_and_then, trait_ref_of_method,
3-
};
4-
use crate::utils::{higher, sugg};
1+
use clippy_utils::diagnostics::span_lint_and_then;
2+
use clippy_utils::source::snippet_opt;
3+
use clippy_utils::ty::implements_trait;
4+
use clippy_utils::{eq_expr_value, get_trait_def_id, trait_ref_of_method};
5+
use clippy_utils::{higher, paths, sugg};
56
use if_chain::if_chain;
67
use rustc_errors::Applicability;
78
use rustc_hir as hir;
@@ -92,7 +93,7 @@ impl<'tcx> LateLintPass<'tcx> for AssignOps {
9293
$($trait_name:ident),+) => {
9394
match $op {
9495
$(hir::BinOpKind::$trait_name => {
95-
let [krate, module] = crate::utils::paths::OPS_MODULE;
96+
let [krate, module] = paths::OPS_MODULE;
9697
let path: [&str; 3] = [krate, module, concat!(stringify!($trait_name), "Assign")];
9798
let trait_id = if let Some(trait_id) = get_trait_def_id($cx, &path) {
9899
trait_id

src/tools/clippy/clippy_lints/src/async_yields_async.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
use crate::utils::{implements_trait, snippet, span_lint_and_then};
1+
use clippy_utils::diagnostics::span_lint_and_then;
2+
use clippy_utils::source::snippet;
3+
use clippy_utils::ty::implements_trait;
24
use rustc_errors::Applicability;
35
use rustc_hir::{AsyncGeneratorKind, Body, BodyId, ExprKind, GeneratorKind, QPath};
46
use rustc_lint::{LateContext, LateLintPass};

src/tools/clippy/clippy_lints/src/atomic_ordering.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::utils::{match_def_path, span_lint_and_help};
1+
use clippy_utils::diagnostics::span_lint_and_help;
2+
use clippy_utils::match_def_path;
23
use if_chain::if_chain;
34
use rustc_hir::def_id::DefId;
45
use rustc_hir::{Expr, ExprKind};

src/tools/clippy/clippy_lints/src/attrs.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
//! checks for attributes
22
3-
use crate::utils::{
4-
first_line_of_span, is_present_in_source, match_panic_def_id, snippet_opt, span_lint, span_lint_and_help,
5-
span_lint_and_sugg, span_lint_and_then, without_block_comments,
6-
};
3+
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
4+
use clippy_utils::match_panic_def_id;
5+
use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments};
76
use if_chain::if_chain;
87
use rustc_ast::{AttrKind, AttrStyle, Attribute, Lit, LitKind, MetaItemKind, NestedMetaItem};
98
use rustc_errors::Applicability;
@@ -431,7 +430,7 @@ fn is_relevant_block(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_
431430
|stmt| match &stmt.kind {
432431
StmtKind::Local(_) => true,
433432
StmtKind::Expr(expr) | StmtKind::Semi(expr) => is_relevant_expr(cx, typeck_results, expr),
434-
_ => false,
433+
StmtKind::Item(_) => false,
435434
},
436435
)
437436
}
@@ -565,7 +564,7 @@ fn check_deprecated_cfg_attr(cx: &EarlyContext<'_>, attr: &Attribute) {
565564
// check for `rustfmt_skip` and `rustfmt::skip`
566565
if let Some(skip_item) = &items[1].meta_item();
567566
if skip_item.has_name(sym!(rustfmt_skip)) ||
568-
skip_item.path.segments.last().expect("empty path in attribute").ident.name == sym!(skip);
567+
skip_item.path.segments.last().expect("empty path in attribute").ident.name == sym::skip;
569568
// Only lint outer attributes, because custom inner attributes are unstable
570569
// Tracking issue: https://github.com/rust-lang/rust/issues/54726
571570
if let AttrStyle::Outer = attr.style;
@@ -614,7 +613,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
614613
}
615614
}
616615
},
617-
_ => {},
616+
MetaItemKind::NameValue(..) => {},
618617
}
619618
}
620619
}

src/tools/clippy/clippy_lints/src/await_holding_invalid.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
use crate::utils::{match_def_path, paths, span_lint_and_note};
1+
use clippy_utils::diagnostics::span_lint_and_note;
2+
use clippy_utils::{match_def_path, paths};
23
use rustc_hir::def_id::DefId;
34
use rustc_hir::{AsyncGeneratorKind, Body, BodyId, GeneratorKind};
45
use rustc_lint::{LateContext, LateLintPass};

src/tools/clippy/clippy_lints/src/bit_mask.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::consts::{constant, Constant};
2-
use crate::utils::sugg::Sugg;
3-
use crate::utils::{span_lint, span_lint_and_then};
2+
use clippy_utils::diagnostics::{span_lint, span_lint_and_then};
3+
use clippy_utils::sugg::Sugg;
44
use if_chain::if_chain;
55
use rustc_ast::ast::LitKind;
66
use rustc_errors::Applicability;

src/tools/clippy/clippy_lints/src/blacklisted_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils::span_lint;
1+
use clippy_utils::diagnostics::span_lint;
22
use rustc_data_structures::fx::FxHashSet;
33
use rustc_hir::{Pat, PatKind};
44
use rustc_lint::{LateContext, LateLintPass};

0 commit comments

Comments
 (0)