Skip to content

Commit 561303d

Browse files
committed
Merge commit 'd9c24d1b1ee61f276e550b967409c9f155eac4e3' into clippyup
2 parents 6f65ef5 + d9c24d1 commit 561303d

File tree

516 files changed

+5241
-2537
lines changed

Some content is hidden

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

516 files changed

+5241
-2537
lines changed

src/tools/clippy/.github/workflows/clippy.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
echo "LD_LIBRARY_PATH=${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}" >> $GITHUB_ENV
5151
5252
- name: Build
53-
run: cargo build --features deny-warnings,internal
53+
run: cargo build --tests --features deny-warnings,internal
5454

5555
- name: Test
5656
run: cargo test --features deny-warnings,internal

src/tools/clippy/.github/workflows/clippy_bors.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ jobs:
106106
echo "$SYSROOT/bin" >> $GITHUB_PATH
107107
108108
- name: Build
109-
run: cargo build --features deny-warnings,internal
109+
run: cargo build --tests --features deny-warnings,internal
110110

111111
- name: Test
112112
if: runner.os == 'Linux'

src/tools/clippy/CHANGELOG.md

+110-70
Large diffs are not rendered by default.

src/tools/clippy/Cargo.toml

+12-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy"
3-
version = "0.1.72"
3+
version = "0.1.73"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"
@@ -36,6 +36,17 @@ walkdir = "2.3"
3636
filetime = "0.2"
3737
itertools = "0.10.1"
3838

39+
# UI test dependencies
40+
clippy_utils = { path = "clippy_utils" }
41+
derive-new = "0.5"
42+
if_chain = "1.0"
43+
quote = "1.0"
44+
serde = { version = "1.0.125", features = ["derive"] }
45+
syn = { version = "2.0", features = ["full"] }
46+
futures = "0.3"
47+
parking_lot = "0.12"
48+
tokio = { version = "1", features = ["io-util"] }
49+
3950
[build-dependencies]
4051
rustc_tools_util = "0.3.0"
4152

src/tools/clippy/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

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

8-
[There are over 600 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
8+
[There are over 650 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
99

1010
Lints are divided into categories, each with a default [lint level](https://doc.rust-lang.org/rustc/lints/levels.html).
1111
You can choose how much Clippy is supposed to ~~annoy~~ help you by changing the lint level by category.

src/tools/clippy/book/src/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
A collection of lints to catch common mistakes and improve your
77
[Rust](https://github.com/rust-lang/rust) code.
88

9-
[There are over 600 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
9+
[There are over 650 lints included in this crate!](https://rust-lang.github.io/rust-clippy/master/index.html)
1010

1111
Lints are divided into categories, each with a default [lint
1212
level](https://doc.rust-lang.org/rustc/lints/levels.html). You can choose how

src/tools/clippy/book/src/development/infrastructure/changelog_update.md

-22
Original file line numberDiff line numberDiff line change
@@ -56,28 +56,6 @@ and open that file in your editor of choice.
5656
When updating the changelog it's also a good idea to make sure that `commit1` is
5757
already correct in the current changelog.
5858

59-
#### PR ranges
60-
61-
We developed the concept of PR ranges to help the user understand the size of a new update. To create a PR range,
62-
get the current release date and the date that the last version was released (YYYY-MM-DD) and use the following link:
63-
64-
```
65-
[**View <NUMBER OF PRs> PRs merged since 1.<LAST VERSION NUM>**](https://github.com/rust-lang/rust-clippy/pulls?q=is%3Apr+is%3Aclosed+merged%3A<LAST VERSION DATE>..<CURRENT VERSION DATE>+base%3Amaster+sort%3Amerged-desc+)
66-
```
67-
68-
> Note: Be sure to check click the link and check how many PRs got merged between
69-
70-
Example:
71-
72-
```
73-
[**View 85 PRs merged since 1.69**](https://github.com/rust-lang/rust-clippy/pulls?q=is%3Apr+is%3Aclosed+merged%3A2023-04-20..2023-06-01+base%3Amaster+sort%3Amerged-desc+)
74-
```
75-
76-
Which renders to:
77-
[**View 85 PRs merged since 1.69**](https://github.com/rust-lang/rust-clippy/pulls?q=is%3Apr+is%3Aclosed+merged%3A2023-04-20..2023-06-01+base%3Amaster+sort%3Amerged-desc+)
78-
79-
Note that **commit ranges should not be included**, only PR ranges.
80-
8159
### 3. Authoring the final changelog
8260

8361
The above script should have dumped all the relevant PRs to the file you
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Speedtest
2+
`SPEEDTEST` is the tool we use to measure lint's performance, it works by executing the same test several times.
3+
4+
It's useful for measuring changes to current lints and deciding if the performance changes too much. `SPEEDTEST` is
5+
accessed by the `SPEEDTEST` (and `SPEEDTEST_*`) environment variables.
6+
7+
## Checking Speedtest
8+
9+
To do a simple speed test of a lint (e.g. `allow_attributes`), use this command.
10+
11+
```sh
12+
$ SPEEDTEST=ui TESTNAME="allow_attributes" cargo uitest -- --nocapture
13+
```
14+
15+
This will test all `ui` tests (`SPEEDTEST=ui`) whose names start with `allow_attributes`. By default, `SPEEDTEST` will
16+
iterate your test 1000 times. But you can change this with `SPEEDTEST_ITERATIONS`.
17+
18+
```sh
19+
$ SPEEDTEST=toml SPEEDTEST_ITERATIONS=100 TESTNAME="semicolon_block" cargo uitest -- --nocapture
20+
```
21+
22+
> **WARNING**: Be sure to use `-- --nocapture` at the end of the command to see the average test time. If you don't
23+
> use `-- --nocapture` (e.g. `SPEEDTEST=ui` `TESTNAME="let_underscore_untyped" cargo uitest -- --nocapture`), this
24+
> will not show up.

src/tools/clippy/book/src/lint_configuration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ The maximum amount of nesting a block can reside in
175175

176176
## `disallowed-names`
177177
The list of disallowed names to lint about. NB: `bar` is not here since it has legitimate uses. The value
178-
`".."` can be used as part of the list to indicate, that the configured values should be appended to the
178+
`".."` can be used as part of the list to indicate that the configured values should be appended to the
179179
default configuration of Clippy. By default, any configuration will replace the default value.
180180

181181
**Default Value:** `["foo", "baz", "quux"]` (`Vec<String>`)

src/tools/clippy/clippy_dev/src/new_lint.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
358358

359359
let mod_file_path = ty_dir.join("mod.rs");
360360
let context_import = setup_mod_file(&mod_file_path, lint)?;
361+
let pass_lifetimes = match context_import {
362+
"LateContext" => "<'_>",
363+
_ => "",
364+
};
361365

362366
let name_upper = lint.name.to_uppercase();
363367
let mut lint_file_contents = String::new();
@@ -372,7 +376,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
372376
use super::{name_upper};
373377
374378
// TODO: Adjust the parameters as necessary
375-
pub(super) fn check(cx: &{context_import}, msrv: &Msrv) {{
379+
pub(super) fn check(cx: &{context_import}{pass_lifetimes}, msrv: &Msrv) {{
376380
if !msrv.meets(todo!("Add a new entry in `clippy_utils/src/msrvs`")) {{
377381
return;
378382
}}
@@ -389,7 +393,7 @@ fn create_lint_for_ty(lint: &LintData<'_>, enable_msrv: bool, ty: &str) -> io::R
389393
use super::{name_upper};
390394
391395
// TODO: Adjust the parameters as necessary
392-
pub(super) fn check(cx: &{context_import}) {{
396+
pub(super) fn check(cx: &{context_import}{pass_lifetimes}) {{
393397
todo!();
394398
}}
395399
"#

src/tools/clippy/clippy_dev/src/setup/intellij.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl ClippyProjectInfo {
3737

3838
pub fn setup_rustc_src(rustc_path: &str) {
3939
let Ok(rustc_source_dir) = check_and_get_rustc_dir(rustc_path) else {
40-
return
40+
return;
4141
};
4242

4343
for project in CLIPPY_PROJECTS {

src/tools/clippy/clippy_dev/src/update_lints.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,10 @@ pub fn deprecate(name: &str, reason: Option<&String>) {
340340
let name_upper = name.to_uppercase();
341341

342342
let (mut lints, deprecated_lints, renamed_lints) = gather_all();
343-
let Some(lint) = lints.iter().find(|l| l.name == name_lower) else { eprintln!("error: failed to find lint `{name}`"); return; };
343+
let Some(lint) = lints.iter().find(|l| l.name == name_lower) else {
344+
eprintln!("error: failed to find lint `{name}`");
345+
return;
346+
};
344347

345348
let mod_path = {
346349
let mut mod_path = PathBuf::from(format!("clippy_lints/src/{}", lint.module));

src/tools/clippy/clippy_lints/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "clippy_lints"
3-
version = "0.1.72"
3+
version = "0.1.73"
44
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
55
repository = "https://github.com/rust-lang/rust-clippy"
66
readme = "README.md"

src/tools/clippy/clippy_lints/src/allow_attributes.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use ast::{AttrStyle, Attribute};
2-
use clippy_utils::{diagnostics::span_lint_and_sugg, is_from_proc_macro};
2+
use clippy_utils::diagnostics::span_lint_and_sugg;
3+
use clippy_utils::is_from_proc_macro;
34
use rustc_ast as ast;
45
use rustc_errors::Applicability;
56
use rustc_lint::{LateContext, LateLintPass, LintContext};
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
use clippy_utils::diagnostics::span_lint_and_help;
1+
use clippy_utils::diagnostics::span_lint_and_then;
22
use clippy_utils::last_path_segment;
33
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
4-
use if_chain::if_chain;
5-
64
use rustc_hir::{Expr, ExprKind};
7-
use rustc_lint::LateContext;
8-
use rustc_lint::LateLintPass;
5+
use rustc_lint::{LateContext, LateLintPass};
96
use rustc_middle::ty;
7+
use rustc_middle::ty::print::with_forced_trimmed_paths;
8+
use rustc_middle::ty::GenericArgKind;
109
use rustc_session::{declare_lint_pass, declare_tool_lint};
1110
use rustc_span::symbol::sym;
1211

@@ -15,58 +14,65 @@ declare_clippy_lint! {
1514
/// This lint warns when you use `Arc` with a type that does not implement `Send` or `Sync`.
1615
///
1716
/// ### Why is this bad?
18-
/// Wrapping a type in Arc doesn't add thread safety to the underlying data, so data races
19-
/// could occur when touching the underlying data.
17+
/// `Arc<T>` is only `Send`/`Sync` when `T` is [both `Send` and `Sync`](https://doc.rust-lang.org/std/sync/struct.Arc.html#impl-Send-for-Arc%3CT%3E),
18+
/// either `T` should be made `Send + Sync` or an `Rc` should be used instead of an `Arc`
2019
///
2120
/// ### Example
2221
/// ```rust
2322
/// # use std::cell::RefCell;
2423
/// # use std::sync::Arc;
2524
///
2625
/// fn main() {
27-
/// // This is safe, as `i32` implements `Send` and `Sync`.
26+
/// // This is fine, as `i32` implements `Send` and `Sync`.
2827
/// let a = Arc::new(42);
2928
///
30-
/// // This is not safe, as `RefCell` does not implement `Sync`.
29+
/// // `RefCell` is `!Sync`, so either the `Arc` should be replaced with an `Rc`
30+
/// // or the `RefCell` replaced with something like a `RwLock`
3131
/// let b = Arc::new(RefCell::new(42));
3232
/// }
3333
/// ```
3434
#[clippy::version = "1.72.0"]
3535
pub ARC_WITH_NON_SEND_SYNC,
36-
correctness,
36+
suspicious,
3737
"using `Arc` with a type that does not implement `Send` or `Sync`"
3838
}
3939
declare_lint_pass!(ArcWithNonSendSync => [ARC_WITH_NON_SEND_SYNC]);
4040

4141
impl LateLintPass<'_> for ArcWithNonSendSync {
4242
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
4343
let ty = cx.typeck_results().expr_ty(expr);
44-
if_chain! {
45-
if is_type_diagnostic_item(cx, ty, sym::Arc);
46-
if let ExprKind::Call(func, [arg]) = expr.kind;
47-
if let ExprKind::Path(func_path) = func.kind;
48-
if last_path_segment(&func_path).ident.name == sym::new;
49-
if let arg_ty = cx.typeck_results().expr_ty(arg);
50-
if !matches!(arg_ty.kind(), ty::Param(_));
51-
if !cx.tcx
52-
.lang_items()
53-
.sync_trait()
54-
.map_or(false, |id| implements_trait(cx, arg_ty, id, &[])) ||
55-
!cx.tcx
56-
.get_diagnostic_item(sym::Send)
57-
.map_or(false, |id| implements_trait(cx, arg_ty, id, &[]));
44+
if is_type_diagnostic_item(cx, ty, sym::Arc)
45+
&& let ExprKind::Call(func, [arg]) = expr.kind
46+
&& let ExprKind::Path(func_path) = func.kind
47+
&& last_path_segment(&func_path).ident.name == sym::new
48+
&& let arg_ty = cx.typeck_results().expr_ty(arg)
49+
// make sure that the type is not and does not contain any type parameters
50+
&& arg_ty.walk().all(|arg| {
51+
!matches!(arg.unpack(), GenericArgKind::Type(ty) if matches!(ty.kind(), ty::Param(_)))
52+
})
53+
&& let Some(send) = cx.tcx.get_diagnostic_item(sym::Send)
54+
&& let Some(sync) = cx.tcx.lang_items().sync_trait()
55+
&& let [is_send, is_sync] = [send, sync].map(|id| implements_trait(cx, arg_ty, id, &[]))
56+
&& !(is_send && is_sync)
57+
{
58+
span_lint_and_then(
59+
cx,
60+
ARC_WITH_NON_SEND_SYNC,
61+
expr.span,
62+
"usage of an `Arc` that is not `Send` or `Sync`",
63+
|diag| with_forced_trimmed_paths!({
64+
if !is_send {
65+
diag.note(format!("the trait `Send` is not implemented for `{arg_ty}`"));
66+
}
67+
if !is_sync {
68+
diag.note(format!("the trait `Sync` is not implemented for `{arg_ty}`"));
69+
}
70+
71+
diag.note(format!("required for `{ty}` to implement `Send` and `Sync`"));
5872

59-
then {
60-
span_lint_and_help(
61-
cx,
62-
ARC_WITH_NON_SEND_SYNC,
63-
expr.span,
64-
"usage of `Arc<T>` where `T` is not `Send` or `Sync`",
65-
None,
66-
"consider using `Rc<T>` instead or wrapping `T` in a std::sync type like \
67-
`Mutex<T>`",
68-
);
69-
}
73+
diag.help("consider using an `Rc` instead or wrapping the inner type with a `Mutex`");
74+
}
75+
));
7076
}
7177
}
7278
}

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

+9-3
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,20 @@ declare_lint_pass!(AssertionsOnConstants => [ASSERTIONS_ON_CONSTANTS]);
3131

3232
impl<'tcx> LateLintPass<'tcx> for AssertionsOnConstants {
3333
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
34-
let Some(macro_call) = root_macro_call_first_node(cx, e) else { return };
34+
let Some(macro_call) = root_macro_call_first_node(cx, e) else {
35+
return;
36+
};
3537
let is_debug = match cx.tcx.get_diagnostic_name(macro_call.def_id) {
3638
Some(sym::debug_assert_macro) => true,
3739
Some(sym::assert_macro) => false,
3840
_ => return,
3941
};
40-
let Some((condition, panic_expn)) = find_assert_args(cx, e, macro_call.expn) else { return };
41-
let Some(Constant::Bool(val)) = constant(cx, cx.typeck_results(), condition) else { return };
42+
let Some((condition, panic_expn)) = find_assert_args(cx, e, macro_call.expn) else {
43+
return;
44+
};
45+
let Some(Constant::Bool(val)) = constant(cx, cx.typeck_results(), condition) else {
46+
return;
47+
};
4248
if val {
4349
span_lint_and_help(
4450
cx,

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
//! checks for attributes
22
3+
use clippy_utils::diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then};
4+
use clippy_utils::is_from_proc_macro;
35
use clippy_utils::macros::{is_panic, macro_backtrace};
46
use clippy_utils::msrvs::{self, Msrv};
57
use clippy_utils::source::{first_line_of_span, is_present_in_source, snippet_opt, without_block_comments};
6-
use clippy_utils::{
7-
diagnostics::{span_lint, span_lint_and_help, span_lint_and_sugg, span_lint_and_then},
8-
is_from_proc_macro,
9-
};
108
use if_chain::if_chain;
119
use rustc_ast::{AttrKind, AttrStyle, Attribute, LitKind, MetaItemKind, MetaItemLit, NestedMetaItem};
1210
use rustc_errors::Applicability;

src/tools/clippy/clippy_lints/src/blocks_in_if_conditions.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use clippy_utils::diagnostics::{span_lint, span_lint_and_sugg};
2-
use clippy_utils::get_parent_expr;
3-
use clippy_utils::higher;
42
use clippy_utils::source::snippet_block_with_applicability;
53
use clippy_utils::ty::implements_trait;
64
use clippy_utils::visitors::{for_each_expr, Descend};
5+
use clippy_utils::{get_parent_expr, higher};
76
use core::ops::ControlFlow;
87
use if_chain::if_chain;
98
use rustc_errors::Applicability;
@@ -85,8 +84,7 @@ impl<'tcx> LateLintPass<'tcx> for BlocksInIfConditions {
8584
);
8685
}
8786
} else {
88-
let span =
89-
block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
87+
let span = block.expr.as_ref().map_or_else(|| block.stmts[0].span, |e| e.span);
9088
if span.from_expansion() || expr.span.from_expansion() {
9189
return;
9290
}

0 commit comments

Comments
 (0)