Skip to content

Commit f1656e6

Browse files
authored
Merge branch 'rust-lang:master' into master
2 parents f76fc63 + b27a2bb commit f1656e6

Some content is hidden

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

50 files changed

+1012
-241
lines changed

.github/workflows/deploy.yml

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ on:
88
tags:
99
- rust-1.**
1010

11+
concurrency:
12+
group: ${{ github.workflow }}
13+
cancel-in-progress: false
14+
1115
env:
1216
TARGET_BRANCH: 'gh-pages'
1317
SHA: '${{ github.sha }}'

.github/workflows/lintcheck.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666

6767
- name: Run lintcheck
6868
if: steps.cache-json.outputs.cache-hit != 'true'
69-
run: ./target/debug/lintcheck --format json --all-lints --crates-toml ./lintcheck/ci_crates.toml
69+
run: env CLIPPY_CONF_DIR="$PWD/lintcheck/ci-config" ./target/debug/lintcheck --format json --all-lints --crates-toml ./lintcheck/ci_crates.toml
7070

7171
- name: Upload base JSON
7272
uses: actions/upload-artifact@v4
@@ -97,7 +97,7 @@ jobs:
9797
run: cargo build --manifest-path=lintcheck/Cargo.toml
9898

9999
- name: Run lintcheck
100-
run: ./target/debug/lintcheck --format json --all-lints --crates-toml ./lintcheck/ci_crates.toml
100+
run: env CLIPPY_CONF_DIR="$PWD/lintcheck/ci-config" ./target/debug/lintcheck --format json --all-lints --crates-toml ./lintcheck/ci_crates.toml
101101

102102
- name: Upload head JSON
103103
uses: actions/upload-artifact@v4

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -5681,6 +5681,7 @@ Released 2018-09-13
56815681
[`if_same_then_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else
56825682
[`if_then_some_else_none`]: https://rust-lang.github.io/rust-clippy/master/index.html#if_then_some_else_none
56835683
[`ifs_same_cond`]: https://rust-lang.github.io/rust-clippy/master/index.html#ifs_same_cond
5684+
[`ignore_without_reason`]: https://rust-lang.github.io/rust-clippy/master/index.html#ignore_without_reason
56845685
[`ignored_unit_patterns`]: https://rust-lang.github.io/rust-clippy/master/index.html#ignored_unit_patterns
56855686
[`impl_hash_borrow_with_str_and_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#impl_hash_borrow_with_str_and_bytes
56865687
[`impl_trait_in_params`]: https://rust-lang.github.io/rust-clippy/master/index.html#impl_trait_in_params
@@ -6362,6 +6363,7 @@ Released 2018-09-13
63626363
[`future-size-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#future-size-threshold
63636364
[`ignore-interior-mutability`]: https://doc.rust-lang.org/clippy/lint_configuration.html#ignore-interior-mutability
63646365
[`large-error-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#large-error-threshold
6366+
[`lint-commented-code`]: https://doc.rust-lang.org/clippy/lint_configuration.html#lint-commented-code
63656367
[`lint-inconsistent-struct-field-initializers`]: https://doc.rust-lang.org/clippy/lint_configuration.html#lint-inconsistent-struct-field-initializers
63666368
[`literal-representation-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#literal-representation-threshold
63676369
[`matches-for-let-else`]: https://doc.rust-lang.org/clippy/lint_configuration.html#matches-for-let-else

book/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
- [Updating the Changelog](development/infrastructure/changelog_update.md)
3131
- [Release a New Version](development/infrastructure/release.md)
3232
- [The Clippy Book](development/infrastructure/book.md)
33+
- [Benchmarking Clippy](development/infrastructure/benchmarking.md)
3334
- [Proposals](development/proposals/README.md)
3435
- [Roadmap 2021](development/proposals/roadmap-2021.md)
3536
- [Syntax Tree Patterns](development/proposals/syntax-tree-patterns.md)

book/src/development/adding_lints.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,22 @@ struct A;
9999
impl A {
100100
pub fn fo(&self) {}
101101
pub fn foo(&self) {}
102+
//~^ foo_functions
102103
pub fn food(&self) {}
103104
}
104105

105106
// Default trait methods
106107
trait B {
107108
fn fo(&self) {}
108109
fn foo(&self) {}
110+
//~^ foo_functions
109111
fn food(&self) {}
110112
}
111113

112114
// Plain functions
113115
fn fo() {}
114116
fn foo() {}
117+
//~^ foo_functions
115118
fn food() {}
116119

117120
fn main() {
@@ -122,17 +125,20 @@ fn main() {
122125
}
123126
```
124127

125-
Now we can run the test with `TESTNAME=foo_functions cargo uibless`, currently
126-
this test is meaningless though.
128+
Note that we are adding comment annotations with the name of our lint to mark
129+
lines where we expect an error. Once we have implemented our lint we can run
130+
`TESTNAME=foo_functions cargo uibless` to generate the `.stderr` file. If our
131+
lint makes use of structured suggestions then this command will also generate
132+
the corresponding `.fixed` file.
127133

128134
While we are working on implementing our lint, we can keep running the UI test.
129135
That allows us to check if the output is turning into what we want by checking the
130136
`.stderr` file that gets updated on every test run.
131137

132-
Running `TESTNAME=foo_functions cargo uitest` should pass on its own. When we
133-
commit our lint, we need to commit the generated `.stderr` files, too. In
134-
general, you should only commit files changed by `cargo bless` for the
135-
specific lint you are creating/editing.
138+
Once we have implemented our lint running `TESTNAME=foo_functions cargo uitest`
139+
should pass on its own. When we commit our lint, we need to commit the generated
140+
`.stderr` and if applicable `.fixed` files, too. In general, you should only
141+
commit files changed by `cargo bless` for the specific lint you are creating/editing.
136142

137143
> _Note:_ you can run multiple test files by specifying a comma separated list:
138144
> `TESTNAME=foo_functions,test2,test3`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Benchmarking Clippy
2+
3+
Benchmarking Clippy is similar to using our Lintcheck tool, in fact, it even
4+
uses the same tool! Just by adding a `--perf` flag it will transform Lintcheck
5+
into a very simple but powerful benchmarking tool!
6+
7+
It requires having the [`perf` tool][perf] installed, as `perf` is what's actually
8+
profiling Clippy under the hood.
9+
10+
The lintcheck `--perf` tool generates a series of `perf.data` in the
11+
`target/lintcheck/sources/<package>-<version>` directories. Each `perf.data`
12+
corresponds to the package which is contained.
13+
14+
Lintcheck uses the `-g` flag, meaning that you can get stack traces for richer
15+
analysis, including with tools such as [flamegraph][flamegraph-perf]
16+
(or [`flamegraph-rs`][flamegraph-rs]).
17+
18+
Currently, we only measure instruction count, as it's the most reproducible metric
19+
and [rustc-perf][rustc-perf] also considers it the main number to focus on.
20+
21+
## Benchmarking a PR
22+
23+
Having a benchmarking tool directly implemented into lintcheck gives us the
24+
ability to benchmark any given PR just by making a before and after
25+
26+
Here's the way you can get into any PR, benchmark it, and then benchmark
27+
`master`.
28+
29+
The first `perf.data` will not have any numbers appended, but any subsequent
30+
benchmark will be written to `perf.data.number` with a number growing for 0.
31+
All benchmarks are compressed so that you can
32+
33+
```bash
34+
git fetch upstream pull/<PR_NUMBER>/head:<BRANCH_NAME>
35+
git switch BRANCHNAME
36+
37+
# Bench
38+
cargo lintcheck --perf
39+
40+
# Get last common commit, checkout that
41+
LAST_COMMIT=$(git log BRANCHNAME..master --oneline | tail -1 | cut -c 1-11)
42+
git switch -c temporary $LAST_COMMIT
43+
44+
# We're now on master
45+
46+
# Bench
47+
cargo lintcheck --perf
48+
perf diff ./target/lintcheck/sources/CRATE/perf.data ./target/lintcheck/sources/CRATE/perf.data.0
49+
```
50+
51+
52+
[perf]: https://perfwiki.github.io/main/
53+
[flamegraph-perf]: https://github.com/brendangregg/FlameGraph
54+
[flamegraph-rs]: https://github.com/flamegraph-rs/flamegraph
55+
[rustc-perf]: https://github.com/rust-lang/rustc-perf

book/src/development/infrastructure/release.md

-3
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,6 @@ git push upstream stable
8888
After updating the `stable` branch, tag the HEAD commit and push it to the
8989
Clippy repo.
9090

91-
> Note: Only push the tag once the Deploy GitHub action of the `beta` branch is
92-
> finished. Otherwise the deploy for the tag might fail.
93-
9491
```bash
9592
git tag rust-1.XX.0 # XX should be exchanged with the corresponding version
9693
git push upstream rust-1.XX.0 # `upstream` is the `rust-lang/rust-clippy` remote

book/src/development/writing_tests.md

+30-8
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,23 @@ Update the file with some examples to get started:
4141
struct A;
4242
impl A {
4343
pub fn fo(&self) {}
44-
pub fn foo(&self) {} //~ ERROR: function called "foo"
44+
pub fn foo(&self) {}
45+
//~^ foo_functions
4546
pub fn food(&self) {}
4647
}
4748

4849
// Default trait methods
4950
trait B {
5051
fn fo(&self) {}
51-
fn foo(&self) {} //~ ERROR: function called "foo"
52+
fn foo(&self) {}
53+
//~^ foo_functions
5254
fn food(&self) {}
5355
}
5456

5557
// Plain functions
5658
fn fo() {}
57-
fn foo() {} //~ ERROR: function called "foo"
59+
fn foo() {}
60+
//~^ foo_functions
5861
fn food() {}
5962

6063
fn main() {
@@ -66,19 +69,38 @@ fn main() {
6669
```
6770

6871
Without actual lint logic to emit the lint when we see a `foo` function name,
69-
this test will just pass, because no lint will be emitted. However, we can now
70-
run the test with the following command:
72+
this test will fail, because we expect errors at lines marked with
73+
`//~^ foo_functions`. However, we can now run the test with the following command:
7174

7275
```sh
7376
$ TESTNAME=foo_functions cargo uitest
7477
```
7578

76-
Clippy will compile and it will conclude with an `ok` for the tests:
79+
Clippy will compile and it will fail complaining it didn't receive any errors:
7780

7881
```
7982
...Clippy warnings and test outputs...
80-
test compile_test ... ok
81-
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.48s
83+
error: diagnostic code `clippy::foo_functions` not found on line 8
84+
--> tests/ui/foo_functions.rs:9:10
85+
|
86+
9 | //~^ foo_functions
87+
| ^^^^^^^^^^^^^ expected because of this pattern
88+
|
89+
90+
error: diagnostic code `clippy::foo_functions` not found on line 16
91+
--> tests/ui/foo_functions.rs:17:10
92+
|
93+
17 | //~^ foo_functions
94+
| ^^^^^^^^^^^^^ expected because of this pattern
95+
|
96+
97+
error: diagnostic code `clippy::foo_functions` not found on line 23
98+
--> tests/ui/foo_functions.rs:24:6
99+
|
100+
24 | //~^ foo_functions
101+
| ^^^^^^^^^^^^^ expected because of this pattern
102+
|
103+
82104
```
83105

84106
This is normal. After all, we wrote a bunch of Rust code but we haven't really

book/src/lint_configuration.md

+11
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,17 @@ The maximum size of the `Err`-variant in a `Result` returned from a function
613613
* [`result_large_err`](https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err)
614614

615615

616+
## `lint-commented-code`
617+
Whether collapsible `if` chains are linted if they contain comments inside the parts
618+
that would be collapsed.
619+
620+
**Default Value:** `false`
621+
622+
---
623+
**Affected lints:**
624+
* [`collapsible_if`](https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_if)
625+
626+
616627
## `lint-inconsistent-struct-field-initializers`
617628
Whether to suggest reordering constructor fields when initializers are present.
618629

clippy_config/src/conf.rs

+4
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ define_Conf! {
549549
/// The maximum size of the `Err`-variant in a `Result` returned from a function
550550
#[lints(result_large_err)]
551551
large_error_threshold: u64 = 128,
552+
/// Whether collapsible `if` chains are linted if they contain comments inside the parts
553+
/// that would be collapsed.
554+
#[lints(collapsible_if)]
555+
lint_commented_code: bool = false,
552556
/// Whether to suggest reordering constructor fields when initializers are present.
553557
///
554558
/// Warnings produced by this configuration aren't necessarily fixed by just reordering the fields. Even if the

clippy_lints/src/attrs/mod.rs

+44-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ mod useless_attribute;
1414
mod utils;
1515

1616
use clippy_config::Conf;
17+
use clippy_utils::diagnostics::span_lint_and_help;
1718
use clippy_utils::msrvs::{self, Msrv, MsrvStack};
18-
use rustc_ast::{self as ast, Attribute, MetaItemInner, MetaItemKind};
19+
use rustc_ast::{self as ast, AttrArgs, AttrKind, Attribute, MetaItemInner, MetaItemKind};
1920
use rustc_hir::{ImplItem, Item, ItemKind, TraitItem};
2021
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
2122
use rustc_session::impl_lint_pass;
@@ -448,6 +449,31 @@ declare_clippy_lint! {
448449
"duplicated attribute"
449450
}
450451

452+
declare_clippy_lint! {
453+
/// ### What it does
454+
/// Checks for ignored tests without messages.
455+
///
456+
/// ### Why is this bad?
457+
/// The reason for ignoring the test may not be obvious.
458+
///
459+
/// ### Example
460+
/// ```no_run
461+
/// #[test]
462+
/// #[ignore]
463+
/// fn test() {}
464+
/// ```
465+
/// Use instead:
466+
/// ```no_run
467+
/// #[test]
468+
/// #[ignore = "Some good reason"]
469+
/// fn test() {}
470+
/// ```
471+
#[clippy::version = "1.85.0"]
472+
pub IGNORE_WITHOUT_REASON,
473+
pedantic,
474+
"ignored tests without messages"
475+
}
476+
451477
pub struct Attributes {
452478
msrv: Msrv,
453479
}
@@ -532,6 +558,7 @@ impl_lint_pass!(PostExpansionEarlyAttributes => [
532558
ALLOW_ATTRIBUTES,
533559
ALLOW_ATTRIBUTES_WITHOUT_REASON,
534560
DEPRECATED_SEMVER,
561+
IGNORE_WITHOUT_REASON,
535562
USELESS_ATTRIBUTE,
536563
BLANKET_CLIPPY_RESTRICTION_LINTS,
537564
SHOULD_PANIC_WITHOUT_EXPECT,
@@ -575,6 +602,22 @@ impl EarlyLintPass for PostExpansionEarlyAttributes {
575602
if attr.has_name(sym::should_panic) {
576603
should_panic_without_expect::check(cx, attr);
577604
}
605+
606+
if attr.has_name(sym::ignore)
607+
&& match &attr.kind {
608+
AttrKind::Normal(normal_attr) => !matches!(normal_attr.item.args, AttrArgs::Eq { .. }),
609+
AttrKind::DocComment(..) => true,
610+
}
611+
{
612+
span_lint_and_help(
613+
cx,
614+
IGNORE_WITHOUT_REASON,
615+
attr.span,
616+
"`#[ignore]` without reason",
617+
None,
618+
"add a reason with `= \"..\"`",
619+
);
620+
}
578621
}
579622

580623
fn check_item(&mut self, cx: &EarlyContext<'_>, item: &'_ ast::Item) {

clippy_lints/src/booleans.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_hir::{BinOpKind, Body, Expr, ExprKind, FnDecl, UnOp};
1313
use rustc_lint::{LateContext, LateLintPass, Level};
1414
use rustc_session::impl_lint_pass;
1515
use rustc_span::def_id::LocalDefId;
16-
use rustc_span::{Span, sym};
16+
use rustc_span::{Span, SyntaxContext, sym};
1717

1818
declare_clippy_lint! {
1919
/// ### What it does
@@ -349,9 +349,13 @@ impl SuggestContext<'_, '_, '_> {
349349
if let Some(str) = simplify_not(self.cx, self.msrv, terminal) {
350350
self.output.push_str(&str);
351351
} else {
352-
self.output.push('!');
353-
self.output
354-
.push_str(&Sugg::hir_opt(self.cx, terminal)?.maybe_par().to_string());
352+
let mut app = Applicability::MachineApplicable;
353+
let snip = Sugg::hir_with_context(self.cx, terminal, SyntaxContext::root(), "", &mut app);
354+
// Ignore the case If the expression is inside a macro expansion, or the default snippet is used
355+
if app != Applicability::MachineApplicable {
356+
return None;
357+
}
358+
self.output.push_str(&(!snip).to_string());
355359
}
356360
},
357361
True | False | Not(_) => {

clippy_lints/src/borrow_deref_ref.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::reference::DEREF_ADDROF;
22
use clippy_utils::diagnostics::span_lint_and_then;
33
use clippy_utils::source::SpanRangeExt;
44
use clippy_utils::ty::implements_trait;
5-
use clippy_utils::{get_parent_expr, is_from_proc_macro, is_lint_allowed};
5+
use clippy_utils::{get_parent_expr, is_from_proc_macro, is_lint_allowed, is_mutable};
66
use rustc_errors::Applicability;
77
use rustc_hir::{BorrowKind, ExprKind, UnOp};
88
use rustc_lint::{LateContext, LateLintPass};
@@ -73,6 +73,9 @@ impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
7373
}
7474
})
7575
&& !is_from_proc_macro(cx, e)
76+
&& let e_ty = cx.typeck_results().expr_ty_adjusted(e)
77+
// check if the reference is coercing to a mutable reference
78+
&& (!matches!(e_ty.kind(), ty::Ref(_, _, Mutability::Mut)) || is_mutable(cx, deref_target))
7679
&& let Some(deref_text) = deref_target.span.get_source_text(cx)
7780
{
7881
span_lint_and_then(

0 commit comments

Comments
 (0)