Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit fe68145

Browse files
committed
Auto merge of rust-lang#9174 - flip1995:rustup, r=Jarcho
Rustup r? `@ghost` changelog: none
2 parents c9f0d1a + 9178ba1 commit fe68145

File tree

83 files changed

+288
-231
lines changed

Some content is hidden

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

83 files changed

+288
-231
lines changed

book/src/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Clippy
22

33
[![Clippy Test](https://github.com/rust-lang/rust-clippy/workflows/Clippy%20Test/badge.svg?branch=auto&event=push)](https://github.com/rust-lang/rust-clippy/actions?query=workflow%3A%22Clippy+Test%22+event%3Apush+branch%3Aauto)
4-
[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](#license)
4+
[![License: MIT OR Apache-2.0](https://img.shields.io/crates/l/clippy.svg)](https://github.com/rust-lang/rust-clippy#license)
55

66
A collection of lints to catch common mistakes and improve your
77
[Rust](https://github.com/rust-lang/rust) code.

book/src/development/adding_lints.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ because that's clearly a non-descriptive name.
1313
- [Testing](#testing)
1414
- [Cargo lints](#cargo-lints)
1515
- [Rustfix tests](#rustfix-tests)
16-
- [Edition 2018 tests](#edition-2018-tests)
1716
- [Testing manually](#testing-manually)
1817
- [Lint declaration](#lint-declaration)
1918
- [Lint registration](#lint-registration)
@@ -402,9 +401,8 @@ need to ensure that the MSRV configured for the project is >= the MSRV of the
402401
required Rust feature. If multiple features are required, just use the one with
403402
a lower MSRV.
404403

405-
First, add an MSRV alias for the required feature in
406-
[`clippy_utils::msrvs`](/clippy_utils/src/msrvs.rs). This can be accessed later
407-
as `msrvs::STR_STRIP_PREFIX`, for example.
404+
First, add an MSRV alias for the required feature in [`clippy_utils::msrvs`].
405+
This can be accessed later as `msrvs::STR_STRIP_PREFIX`, for example.
408406

409407
```rust
410408
msrv_aliases! {
@@ -468,6 +466,8 @@ define_Conf! {
468466
}
469467
```
470468

469+
[`clippy_utils::msrvs`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/msrvs/index.html
470+
471471
## Author lint
472472

473473
If you have trouble implementing your lint, there is also the internal `author`
@@ -583,8 +583,7 @@ the workspace directory. Adding a configuration to a lint can be useful for
583583
thresholds or to constrain some behavior that can be seen as a false positive
584584
for some users. Adding a configuration is done in the following steps:
585585

586-
1. Adding a new configuration entry to
587-
[clippy_lints::utils::conf](/clippy_lints/src/utils/conf.rs) like this:
586+
1. Adding a new configuration entry to [`clippy_lints::utils::conf`] like this:
588587

589588
```rust
590589
/// Lint: LINT_NAME.
@@ -635,9 +634,9 @@ for some users. Adding a configuration is done in the following steps:
635634
```
636635
3. Passing the configuration value to the lint impl struct:
637636

638-
First find the struct construction in the [clippy_lints lib
639-
file](/clippy_lints/src/lib.rs). The configuration value is now cloned or
640-
copied into a local value that is then passed to the impl struct like this:
637+
First find the struct construction in the [`clippy_lints` lib file]. The
638+
configuration value is now cloned or copied into a local value that is then
639+
passed to the impl struct like this:
641640

642641
```rust
643642
// Default generated registration:
@@ -653,12 +652,16 @@ for some users. Adding a configuration is done in the following steps:
653652

654653
4. Adding tests:
655654
1. The default configured value can be tested like any normal lint in
656-
[`tests/ui`](/tests/ui).
657-
2. The configuration itself will be tested separately in
658-
[`tests/ui-toml`](/tests/ui-toml). Simply add a new subfolder with a
659-
fitting name. This folder contains a `clippy.toml` file with the
660-
configuration value and a rust file that should be linted by Clippy. The
661-
test can otherwise be written as usual.
655+
[`tests/ui`].
656+
2. The configuration itself will be tested separately in [`tests/ui-toml`].
657+
Simply add a new subfolder with a fitting name. This folder contains a
658+
`clippy.toml` file with the configuration value and a rust file that
659+
should be linted by Clippy. The test can otherwise be written as usual.
660+
661+
[`clippy_lints::utils::conf`]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/utils/conf.rs
662+
[`clippy_lints` lib file]: https://github.com/rust-lang/rust-clippy/blob/master/clippy_lints/src/lib.rs
663+
[`tests/ui`]: https://github.com/rust-lang/rust-clippy/blob/master/tests/ui
664+
[`tests/ui-toml`]: https://github.com/rust-lang/rust-clippy/blob/master/tests/ui-toml
662665

663666
## Cheat Sheet
664667

book/src/development/basics.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ cargo dev dogfood
102102
```
103103

104104
More about intellij command usage and reasons
105-
[here](../CONTRIBUTING.md#intellij-rust)
105+
[here](https://github.com/rust-lang/rust-clippy/blob/master/CONTRIBUTING.md#intellij-rust)
106106

107107
## lintcheck
108108

book/src/development/common_tools_writing_lints.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,4 @@ functions to deal with macros:
276276
[LateContext]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_lint/struct.LateContext.html
277277
[TyCtxt]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TyCtxt.html
278278
[pat_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/context/struct.TypeckResults.html#method.pat_ty
279-
[paths]: ../clippy_utils/src/paths.rs
279+
[paths]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/paths/index.html

book/src/usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,4 +148,4 @@ clippy-driver --edition 2018 -Cpanic=abort foo.rs
148148
> that are not optimized as expected, for example.
149149
150150
[Installation]: installation.md
151-
[CI]: continuous_integration
151+
[CI]: continuous_integration/index.md

clippy_lints/src/blocks_in_if_conditions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use clippy_utils::ty::implements_trait;
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
88
use rustc_hir::intravisit::{walk_expr, Visitor};
9-
use rustc_hir::{BlockCheckMode, Expr, ExprKind};
9+
use rustc_hir::{BlockCheckMode, Closure, Expr, ExprKind};
1010
use rustc_lint::{LateContext, LateLintPass, LintContext};
1111
use rustc_middle::lint::in_external_macro;
1212
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -51,7 +51,7 @@ struct ExVisitor<'a, 'tcx> {
5151

5252
impl<'a, 'tcx> Visitor<'tcx> for ExVisitor<'a, 'tcx> {
5353
fn visit_expr(&mut self, expr: &'tcx Expr<'tcx>) {
54-
if let ExprKind::Closure { body, .. } = expr.kind {
54+
if let ExprKind::Closure(&Closure { body, .. }) = expr.kind {
5555
// do not lint if the closure is called using an iterator (see #1141)
5656
if_chain! {
5757
if let Some(parent) = get_parent_expr(self.cx, expr);

clippy_lints/src/bytecount.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use clippy_utils::visitors::is_local_used;
55
use clippy_utils::{path_to_local_id, paths, peel_blocks, peel_ref_operators, strip_pat_refs};
66
use if_chain::if_chain;
77
use rustc_errors::Applicability;
8-
use rustc_hir::{BinOpKind, Expr, ExprKind, PatKind};
8+
use rustc_hir::{BinOpKind, Closure, Expr, ExprKind, PatKind};
99
use rustc_lint::{LateContext, LateLintPass};
1010
use rustc_middle::ty::{self, UintTy};
1111
use rustc_session::{declare_lint_pass, declare_tool_lint};
@@ -51,7 +51,7 @@ impl<'tcx> LateLintPass<'tcx> for ByteCount {
5151
if count.ident.name == sym::count;
5252
if let ExprKind::MethodCall(filter, [filter_recv, filter_arg], _) = count_recv.kind;
5353
if filter.ident.name == sym!(filter);
54-
if let ExprKind::Closure { body, .. } = filter_arg.kind;
54+
if let ExprKind::Closure(&Closure { body, .. }) = filter_arg.kind;
5555
let body = cx.tcx.hir().body(body);
5656
if let [param] = body.params;
5757
if let PatKind::Binding(_, arg_id, _, _) = strip_pat_refs(param.pat).kind;

clippy_lints/src/dereference.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ use rustc_data_structures::fx::FxIndexMap;
88
use rustc_errors::Applicability;
99
use rustc_hir::intravisit::{walk_ty, Visitor};
1010
use rustc_hir::{
11-
self as hir, BindingAnnotation, Body, BodyId, BorrowKind, Expr, ExprKind, FnRetTy, GenericArg, HirId, ImplItem,
12-
ImplItemKind, Item, ItemKind, Local, MatchSource, Mutability, Node, Pat, PatKind, Path, QPath, TraitItem,
11+
self as hir, BindingAnnotation, Body, BodyId, BorrowKind, Closure, Expr, ExprKind, FnRetTy, GenericArg, HirId,
12+
ImplItem, ImplItemKind, Item, ItemKind, Local, MatchSource, Mutability, Node, Pat, PatKind, Path, QPath, TraitItem,
1313
TraitItemKind, TyKind, UnOp,
1414
};
1515
use rustc_infer::infer::TyCtxtInferExt;
1616
use rustc_lint::{LateContext, LateLintPass};
1717
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
18-
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeckResults};
18+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitable, TypeckResults};
1919
use rustc_session::{declare_tool_lint, impl_lint_pass};
2020
use rustc_span::{symbol::sym, Span, Symbol};
2121
use rustc_trait_selection::infer::InferCtxtExt;
@@ -720,7 +720,7 @@ fn walk_parents<'tcx>(cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) -> (Position, &
720720
let owner_id = cx.tcx.hir().body_owner(cx.enclosing_body.unwrap());
721721
Some(
722722
if let Node::Expr(Expr {
723-
kind: ExprKind::Closure { fn_decl, .. },
723+
kind: ExprKind::Closure(&Closure { fn_decl, .. }),
724724
..
725725
}) = cx.tcx.hir().get(owner_id)
726726
{

clippy_lints/src/duplicate_mod.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_and_help;
22
use rustc_ast::ast::{Crate, Inline, Item, ItemKind, ModKind};
33
use rustc_errors::MultiSpan;
4-
use rustc_lint::{EarlyContext, EarlyLintPass, LintContext};
4+
use rustc_lint::{EarlyContext, EarlyLintPass, Level, LintContext};
55
use rustc_session::{declare_tool_lint, impl_lint_pass};
66
use rustc_span::{FileName, Span};
77
use std::collections::BTreeMap;
@@ -49,6 +49,7 @@ declare_clippy_lint! {
4949
struct Modules {
5050
local_path: PathBuf,
5151
spans: Vec<Span>,
52+
lint_levels: Vec<Level>,
5253
}
5354

5455
#[derive(Default)]
@@ -70,13 +71,38 @@ impl EarlyLintPass for DuplicateMod {
7071
let modules = self.modules.entry(absolute_path).or_insert(Modules {
7172
local_path,
7273
spans: Vec::new(),
74+
lint_levels: Vec::new(),
7375
});
7476
modules.spans.push(item.span_with_attributes());
77+
modules.lint_levels.push(cx.get_lint_level(DUPLICATE_MOD));
7578
}
7679
}
7780

7881
fn check_crate_post(&mut self, cx: &EarlyContext<'_>, _: &Crate) {
79-
for Modules { local_path, spans } in self.modules.values() {
82+
for Modules {
83+
local_path,
84+
spans,
85+
lint_levels,
86+
} in self.modules.values()
87+
{
88+
if spans.len() < 2 {
89+
continue;
90+
}
91+
92+
// At this point the lint would be emitted
93+
assert_eq!(spans.len(), lint_levels.len());
94+
let spans: Vec<_> = spans
95+
.iter()
96+
.zip(lint_levels)
97+
.filter_map(|(span, lvl)| {
98+
if let Some(id) = lvl.get_expectation_id() {
99+
cx.fulfill_expectation(id);
100+
}
101+
102+
(!matches!(lvl, Level::Allow | Level::Expect(_))).then_some(*span)
103+
})
104+
.collect();
105+
80106
if spans.len() < 2 {
81107
continue;
82108
}

clippy_lints/src/escape.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clippy_utils::diagnostics::span_lint_hir;
22
use clippy_utils::ty::contains_ty;
33
use rustc_hir::intravisit;
4-
use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node};
4+
use rustc_hir::{self, AssocItemKind, Body, FnDecl, HirId, HirIdSet, Impl, ItemKind, Node, Pat, PatKind};
55
use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_middle::mir::FakeReadCause;
@@ -132,7 +132,10 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
132132
// TODO: Replace with Map::is_argument(..) when it's fixed
133133
fn is_argument(map: rustc_middle::hir::map::Map<'_>, id: HirId) -> bool {
134134
match map.find(id) {
135-
Some(Node::Binding(_)) => (),
135+
Some(Node::Pat(Pat {
136+
kind: PatKind::Binding(..),
137+
..
138+
})) => (),
136139
_ => return false,
137140
}
138141

@@ -144,15 +147,6 @@ impl<'a, 'tcx> Delegate<'tcx> for EscapeDelegate<'a, 'tcx> {
144147
if cmt.place.projections.is_empty() {
145148
if let PlaceBase::Local(lid) = cmt.place.base {
146149
self.set.remove(&lid);
147-
let map = &self.cx.tcx.hir();
148-
if let Some(Node::Binding(_)) = map.find(cmt.hir_id) {
149-
if self.set.contains(&lid) {
150-
// let y = x where x is known
151-
// remove x, insert y
152-
self.set.insert(cmt.hir_id);
153-
self.set.remove(&lid);
154-
}
155-
}
156150
}
157151
}
158152
}

0 commit comments

Comments
 (0)