Skip to content

Commit 67100f6

Browse files
committed
Auto merge of #73660 - flip1995:clippyup, r=nikomatsakis
Update Clippy
2 parents d8ed1b0 + a2c0499 commit 67100f6

Some content is hidden

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

48 files changed

+1077
-293
lines changed

src/tools/clippy/.github/ISSUE_TEMPLATE.md

-8
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
name: Blank Issue
3+
about: Create a blank issue.
4+
---
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
name: Bug Report
3+
about: Create a bug report for Clippy
4+
labels: L-bug
5+
---
6+
<!--
7+
Thank you for filing a bug report! 🐛 Please provide a short summary of the bug,
8+
along with any information you feel relevant to replicating the bug.
9+
-->
10+
11+
I tried this code:
12+
13+
```rust
14+
<code>
15+
```
16+
17+
I expected to see this happen: *explanation*
18+
19+
Instead, this happened: *explanation*
20+
21+
### Meta
22+
23+
- `cargo clippy -V`: e.g. clippy 0.0.212 (f455e46 2020-06-20)
24+
- `rustc -Vv`:
25+
```
26+
rustc 1.46.0-nightly (f455e46ea 2020-06-20)
27+
binary: rustc
28+
commit-hash: f455e46eae1a227d735091091144601b467e1565
29+
commit-date: 2020-06-20
30+
host: x86_64-unknown-linux-gnu
31+
release: 1.46.0-nightly
32+
LLVM version: 10.0
33+
```
34+
35+
<!--
36+
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
37+
environment. E.g. `RUST_BACKTRACE=1 cargo clippy`.
38+
-->
39+
<details><summary>Backtrace</summary>
40+
<p>
41+
42+
```
43+
<backtrace>
44+
```
45+
46+
</p>
47+
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
blank_issues_enabled: true
2+
contact_links:
3+
- name: Rust Programming Language Forum
4+
url: https://users.rust-lang.org
5+
about: Please ask and answer questions about Rust here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
name: Internal Compiler Error
3+
about: Create a report for an internal compiler error in Clippy.
4+
labels: L-bug, L-crash
5+
---
6+
<!--
7+
Thank you for finding an Internal Compiler Error! 🧊 If possible, try to provide
8+
a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for
9+
how to create smaller examples.
10+
11+
http://blog.pnkfx.org/blog/2019/11/18/rust-bug-minimization-patterns/
12+
13+
-->
14+
15+
### Code
16+
17+
```rust
18+
<code>
19+
```
20+
21+
### Meta
22+
23+
- `cargo clippy -V`: e.g. clippy 0.0.212 (f455e46 2020-06-20)
24+
- `rustc -Vv`:
25+
```
26+
rustc 1.46.0-nightly (f455e46ea 2020-06-20)
27+
binary: rustc
28+
commit-hash: f455e46eae1a227d735091091144601b467e1565
29+
commit-date: 2020-06-20
30+
host: x86_64-unknown-linux-gnu
31+
release: 1.46.0-nightly
32+
LLVM version: 10.0
33+
```
34+
35+
### Error output
36+
37+
```
38+
<output>
39+
```
40+
41+
<!--
42+
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
43+
environment. E.g. `RUST_BACKTRACE=1 cargo clippy`.
44+
-->
45+
<details><summary>Backtrace</summary>
46+
<p>
47+
48+
```
49+
<backtrace>
50+
```
51+
52+
</p>
53+
</details>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
name: New lint suggestion
3+
about: Suggest a new Clippy lint.
4+
labels: L-lint
5+
---
6+
7+
### What it does
8+
9+
*What does this lint do?*
10+
11+
### Categories (optional)
12+
13+
- Kind: *See <https://github.com/rust-lang/rust-clippy/blob/master/README.md#clippy> for list of lint kinds*
14+
15+
*What benefit of this lint over old code?*
16+
17+
For example:
18+
- Remove bounce checking inserted by ...
19+
- Remove the need to duplicating/storing/typo ...
20+
21+
### Drawbacks
22+
23+
None.
24+
25+
### Example
26+
27+
```rust
28+
<code>
29+
```
30+
31+
Could be written as:
32+
33+
```rust
34+
<code>
35+
```

src/tools/clippy/.github/PULL_REQUEST_TEMPLATE.md

+1
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ Delete this line and everything above before opening your PR.
2828

2929
---
3030

31+
*Please keep the line below*
3132
changelog: none

src/tools/clippy/.github/driver.sh

+12
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,16 @@ unset CARGO_MANIFEST_DIR
2626
sed -e "s,tests/ui,\$DIR," -e "/= help/d" cstring.stderr > normalized.stderr
2727
diff normalized.stderr tests/ui/cstring.stderr
2828

29+
30+
# make sure "clippy-driver --rustc --arg" and "rustc --arg" behave the same
31+
SYSROOT=`rustc --print sysroot`
32+
diff <(LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver --rustc --version --verbose) <(rustc --version --verbose)
33+
34+
35+
echo "fn main() {}" > target/driver_test.rs
36+
# we can't run 2 rustcs on the same file at the same time
37+
CLIPPY=`LD_LIBRARY_PATH=${SYSROOT}/lib ./target/debug/clippy-driver ./target/driver_test.rs --rustc`
38+
RUSTC=`rustc ./target/driver_test.rs`
39+
diff <($CLIPPY) <($RUSTC)
40+
2941
# TODO: CLIPPY_CONF_DIR / CARGO_MANIFEST_DIR

src/tools/clippy/clippy_lints/src/consts.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
396396
let l = self.expr(left)?;
397397
let r = self.expr(right);
398398
match (l, r) {
399-
(Constant::Int(l), Some(Constant::Int(r))) => match self.tables.expr_ty(left).kind {
399+
(Constant::Int(l), Some(Constant::Int(r))) => match self.tables.expr_ty_opt(left)?.kind {
400400
ty::Int(ity) => {
401401
let l = sext(self.lcx.tcx, l, ity);
402402
let r = sext(self.lcx.tcx, r, ity);

src/tools/clippy/clippy_lints/src/escape.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use rustc_middle::ty::{self, Ty};
66
use rustc_session::{declare_tool_lint, impl_lint_pass};
77
use rustc_span::source_map::Span;
88
use rustc_target::abi::LayoutOf;
9-
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceWithHirId, PlaceBase};
9+
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, PlaceBase, PlaceWithHirId};
1010

1111
use crate::utils::span_lint;
1212

src/tools/clippy/clippy_lints/src/len_zero.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ fn check_impl_items(cx: &LateContext<'_, '_>, item: &Item<'_>, impl_items: &[Imp
211211
}
212212

213213
fn check_cmp(cx: &LateContext<'_, '_>, span: Span, method: &Expr<'_>, lit: &Expr<'_>, op: &str, compare_to: u32) {
214-
if let (&ExprKind::MethodCall(ref method_path, _, ref args, _), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind) {
214+
if let (&ExprKind::MethodCall(ref method_path, _, ref args, _), &ExprKind::Lit(ref lit)) = (&method.kind, &lit.kind)
215+
{
215216
// check if we are in an is_empty() method
216217
if let Some(name) = get_item_name(cx, method) {
217218
if name.as_str() == "is_empty" {

src/tools/clippy/clippy_lints/src/let_underscore.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ declare_clippy_lint! {
3535
/// **What it does:** Checks for `let _ = sync_lock`
3636
///
3737
/// **Why is this bad?** This statement immediately drops the lock instead of
38-
/// extending it's lifetime to the end of the scope, which is often not intended.
38+
/// extending its lifetime to the end of the scope, which is often not intended.
3939
/// To extend lock lifetime to the end of the scope, use an underscore-prefixed
4040
/// name instead (i.e. _lock). If you want to explicitly drop the lock,
4141
/// `std::mem::drop` conveys your intention better and is less error-prone.

src/tools/clippy/clippy_lints/src/lib.rs

+15-39
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,44 @@
11
// error-pattern:cargo-clippy
22

33
#![feature(bindings_after_at)]
4-
#![feature(box_syntax)]
54
#![feature(box_patterns)]
5+
#![feature(box_syntax)]
6+
#![feature(concat_idents)]
7+
#![feature(crate_visibility_modifier)]
8+
#![feature(drain_filter)]
69
#![feature(or_patterns)]
710
#![feature(rustc_private)]
811
#![feature(stmt_expr_attributes)]
9-
#![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)]
1012
#![recursion_limit = "512"]
11-
#![warn(rust_2018_idioms, trivial_casts, trivial_numeric_casts)]
12-
#![deny(rustc::internal)]
1313
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
14-
#![feature(crate_visibility_modifier)]
15-
#![feature(concat_idents)]
16-
#![feature(drain_filter)]
14+
#![allow(clippy::missing_docs_in_private_items, clippy::must_use_candidate)]
15+
#![warn(trivial_casts, trivial_numeric_casts)]
16+
// warn on lints, that are included in `rust-lang/rust`s bootstrap
17+
#![warn(rust_2018_idioms, unused_lifetimes)]
18+
// warn on rustc internal lints
19+
#![deny(rustc::internal)]
1720

1821
// FIXME: switch to something more ergonomic here, once available.
1922
// (Currently there is no way to opt into sysroot crates without `extern crate`.)
20-
#[allow(unused_extern_crates)]
2123
extern crate rustc_ast;
22-
#[allow(unused_extern_crates)]
2324
extern crate rustc_ast_pretty;
24-
#[allow(unused_extern_crates)]
2525
extern crate rustc_attr;
26-
#[allow(unused_extern_crates)]
2726
extern crate rustc_data_structures;
28-
#[allow(unused_extern_crates)]
29-
extern crate rustc_driver;
30-
#[allow(unused_extern_crates)]
3127
extern crate rustc_errors;
32-
#[allow(unused_extern_crates)]
3328
extern crate rustc_hir;
34-
#[allow(unused_extern_crates)]
3529
extern crate rustc_hir_pretty;
36-
#[allow(unused_extern_crates)]
3730
extern crate rustc_index;
38-
#[allow(unused_extern_crates)]
3931
extern crate rustc_infer;
40-
#[allow(unused_extern_crates)]
4132
extern crate rustc_lexer;
42-
#[allow(unused_extern_crates)]
4333
extern crate rustc_lint;
44-
#[allow(unused_extern_crates)]
4534
extern crate rustc_middle;
46-
#[allow(unused_extern_crates)]
4735
extern crate rustc_mir;
48-
#[allow(unused_extern_crates)]
4936
extern crate rustc_parse;
50-
#[allow(unused_extern_crates)]
5137
extern crate rustc_parse_format;
52-
#[allow(unused_extern_crates)]
5338
extern crate rustc_session;
54-
#[allow(unused_extern_crates)]
5539
extern crate rustc_span;
56-
#[allow(unused_extern_crates)]
5740
extern crate rustc_target;
58-
#[allow(unused_extern_crates)]
5941
extern crate rustc_trait_selection;
60-
#[allow(unused_extern_crates)]
6142
extern crate rustc_typeck;
6243

6344
use rustc_data_structures::fx::FxHashSet;
@@ -82,14 +63,10 @@ use rustc_session::Session;
8263
/// # Example
8364
///
8465
/// ```
85-
/// # #![feature(rustc_private)]
86-
/// # #[allow(unused_extern_crates)]
87-
/// # extern crate rustc_middle;
88-
/// # #[allow(unused_extern_crates)]
89-
/// # extern crate rustc_session;
90-
/// # #[macro_use]
91-
/// # use clippy_lints::declare_clippy_lint;
66+
/// #![feature(rustc_private)]
67+
/// extern crate rustc_session;
9268
/// use rustc_session::declare_tool_lint;
69+
/// use clippy_lints::declare_clippy_lint;
9370
///
9471
/// declare_clippy_lint! {
9572
/// /// **What it does:** Checks for ... (describe what the lint matches).
@@ -1062,7 +1039,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10621039
store.register_early_pass(|| box option_env_unwrap::OptionEnvUnwrap);
10631040
let warn_on_all_wildcard_imports = conf.warn_on_all_wildcard_imports;
10641041
store.register_late_pass(move || box wildcard_imports::WildcardImports::new(warn_on_all_wildcard_imports));
1065-
store.register_early_pass(|| box macro_use::MacroUseImports);
10661042
store.register_late_pass(|| box verbose_file_reads::VerboseFileReads);
10671043
store.register_late_pass(|| box redundant_pub_crate::RedundantPubCrate::default());
10681044
store.register_late_pass(|| box unnamed_address::UnnamedAddress);
@@ -1080,6 +1056,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
10801056
single_char_binding_names_threshold,
10811057
});
10821058
store.register_early_pass(|| box unnested_or_patterns::UnnestedOrPatterns);
1059+
store.register_late_pass(|| box macro_use::MacroUseImports::default());
10831060

10841061
store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
10851062
LintId::of(&arithmetic::FLOAT_ARITHMETIC),
@@ -1187,6 +1164,7 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
11871164
LintId::of(&types::OPTION_OPTION),
11881165
LintId::of(&unicode::NON_ASCII_LITERAL),
11891166
LintId::of(&unicode::UNICODE_NOT_NFC),
1167+
LintId::of(&unnested_or_patterns::UNNESTED_OR_PATTERNS),
11901168
LintId::of(&unused_self::UNUSED_SELF),
11911169
LintId::of(&wildcard_imports::ENUM_GLOB_USE),
11921170
LintId::of(&wildcard_imports::WILDCARD_IMPORTS),
@@ -1440,7 +1418,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
14401418
LintId::of(&unnamed_address::FN_ADDRESS_COMPARISONS),
14411419
LintId::of(&unnamed_address::VTABLE_ADDRESS_COMPARISONS),
14421420
LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY),
1443-
LintId::of(&unnested_or_patterns::UNNESTED_OR_PATTERNS),
14441421
LintId::of(&unsafe_removed_from_name::UNSAFE_REMOVED_FROM_NAME),
14451422
LintId::of(&unused_io_amount::UNUSED_IO_AMOUNT),
14461423
LintId::of(&unwrap::PANICKING_UNWRAP),
@@ -1624,7 +1601,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
16241601
LintId::of(&types::UNNECESSARY_CAST),
16251602
LintId::of(&types::VEC_BOX),
16261603
LintId::of(&unnecessary_sort_by::UNNECESSARY_SORT_BY),
1627-
LintId::of(&unnested_or_patterns::UNNESTED_OR_PATTERNS),
16281604
LintId::of(&unwrap::UNNECESSARY_UNWRAP),
16291605
LintId::of(&useless_conversion::USELESS_CONVERSION),
16301606
LintId::of(&zero_div_zero::ZERO_DIVIDED_BY_ZERO),

0 commit comments

Comments
 (0)