Skip to content

Commit ee400af

Browse files
committed
Merge commit 'cdbbf3afda0b1bf51568b368f629b1d828507f98' into clippy-subtree-update
2 parents 78a6e13 + cdbbf3a commit ee400af

File tree

126 files changed

+2760
-476
lines changed

Some content is hidden

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

126 files changed

+2760
-476
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
name: Feature freeze check
22

33
on:
4-
pull_request:
4+
pull_request_target:
5+
types:
6+
- opened
7+
branches:
8+
- master
59
paths:
610
- 'clippy_lints/src/declared_lints.rs'
711

812
jobs:
913
auto-comment:
1014
runs-on: ubuntu-latest
1115

16+
permissions:
17+
pull-requests: write
18+
19+
# Do not in any case add code that runs anything coming from the the content
20+
# of the pull request, as malicious code would be able to access the private
21+
# GitHub token.
1222
steps:
1323
- name: Check PR Changes
1424
id: pr-changes
@@ -19,7 +29,7 @@ jobs:
1929
run: |
2030
# Use GitHub API to create a comment on the PR
2131
PR_NUMBER=${{ github.event.pull_request.number }}
22-
COMMENT="**Seems that you are trying to add a new lint!**\nWe are currently in a [feature freeze](https://doc.rust-lang.org/nightly/clippy/development/feature_freeze.html), so we are delaying all lint-adding PRs to August 1st and focusing on bugfixes.\nThanks a lot for your contribution, and sorry for the inconvenience.\nWith ❤ from the Clippy team"
32+
COMMENT="**Seems that you are trying to add a new lint!**\nWe are currently in a [feature freeze](https://doc.rust-lang.org/nightly/clippy/development/feature_freeze.html), so we are delaying all lint-adding PRs to September 18 and focusing on bugfixes.\nThanks a lot for your contribution, and sorry for the inconvenience.\nWith ❤ from the Clippy team\n\n@rustbot note Feature-freeze\n@rustbot blocked\n@rustbot label +A-lint\n"
2333
GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}
2434
COMMENT_URL="https://api.github.com/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments"
2535
curl -s -H "Authorization: token ${GITHUB_TOKEN}" -X POST $COMMENT_URL -d "{\"body\":\"$COMMENT\"}"

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,27 @@ jobs:
128128
- name: Download JSON
129129
uses: actions/download-artifact@v4
130130

131+
- name: Store PR number
132+
run: echo ${{ github.event.pull_request.number }} > pr.txt
133+
131134
- name: Diff results
132-
# GH's summery has a maximum size of 1024k:
133-
# https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#adding-a-markdown-summary
134-
# That's why we first log to file and then to the summary and logs
135+
# GH's summery has a maximum size of 1MiB:
136+
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#step-isolation-and-limits
137+
# We upload the full diff as an artifact in case it's truncated
135138
run: |
136-
./target/debug/lintcheck diff {base,head}/ci_crates_logs.json --truncate >> truncated_diff.md
137-
head -c 1024000 truncated_diff.md >> $GITHUB_STEP_SUMMARY
138-
cat truncated_diff.md
139-
./target/debug/lintcheck diff {base,head}/ci_crates_logs.json >> full_diff.md
139+
./target/debug/lintcheck diff {base,head}/ci_crates_logs.json --truncate | head -c 1M > $GITHUB_STEP_SUMMARY
140+
./target/debug/lintcheck diff {base,head}/ci_crates_logs.json --write-summary summary.json > full_diff.md
140141
141142
- name: Upload full diff
142143
uses: actions/upload-artifact@v4
143144
with:
144-
name: diff
145-
if-no-files-found: ignore
145+
name: full_diff
146+
path: full_diff.md
147+
148+
- name: Upload summary
149+
uses: actions/upload-artifact@v4
150+
with:
151+
name: summary
146152
path: |
147-
full_diff.md
148-
truncated_diff.md
153+
summary.json
154+
pr.txt
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Lintcheck summary
2+
3+
# The workflow_run event runs in the context of the Clippy repo giving it write
4+
# access, needed here to create a PR comment when the PR originates from a fork
5+
#
6+
# The summary artifact is a JSON file that we verify in this action to prevent
7+
# the creation of arbitrary comments
8+
#
9+
# This action must not checkout/run code from the originating workflow_run
10+
# or directly interpolate ${{}} untrusted fields into code
11+
#
12+
# https://docs.github.com/en/actions/writing-workflows/choosing-when-your-workflow-runs/events-that-trigger-workflows#workflow_run
13+
# https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions#understanding-the-risk-of-script-injections
14+
15+
on:
16+
workflow_run:
17+
workflows: [Lintcheck]
18+
types: [completed]
19+
20+
# Restrict the default permission scope https://docs.github.com/en/actions/writing-workflows/workflow-syntax-for-github-actions#defining-access-for-the-github_token-scopes
21+
permissions:
22+
pull-requests: write
23+
24+
jobs:
25+
download:
26+
runs-on: ubuntu-latest
27+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
28+
steps:
29+
- name: Download artifact
30+
uses: actions/download-artifact@v4
31+
with:
32+
name: summary
33+
path: untrusted
34+
run-id: ${{ github.event.workflow_run.id }}
35+
github-token: ${{ github.token }}
36+
37+
- name: Format comment
38+
uses: actions/github-script@v7
39+
with:
40+
script: |
41+
const fs = require("fs");
42+
const assert = require("assert/strict");
43+
44+
function validateName(s) {
45+
assert.match(s, /^[a-z0-9_:]+$/);
46+
return s;
47+
}
48+
49+
function validateInt(i) {
50+
assert.ok(Number.isInteger(i));
51+
return i;
52+
}
53+
54+
function tryReadSummary() {
55+
try {
56+
return JSON.parse(fs.readFileSync("untrusted/summary.json"));
57+
} catch {
58+
return null;
59+
}
60+
}
61+
62+
const prNumber = parseInt(fs.readFileSync("untrusted/pr.txt"), 10);
63+
core.exportVariable("PR", prNumber.toString());
64+
65+
const untrustedSummary = tryReadSummary();
66+
if (!Array.isArray(untrustedSummary)) {
67+
return;
68+
}
69+
70+
let summary = `Lintcheck changes for ${context.payload.workflow_run.head_sha}
71+
72+
| Lint | Added | Removed | Changed |
73+
| ---- | ----: | ------: | ------: |
74+
`;
75+
76+
for (const untrustedRow of untrustedSummary) {
77+
const name = validateName(untrustedRow.name);
78+
79+
const added = validateInt(untrustedRow.added);
80+
const removed = validateInt(untrustedRow.removed);
81+
const changed = validateInt(untrustedRow.changed);
82+
83+
const id = name.replace("clippy::", "user-content-").replaceAll("_", "-");
84+
const url = `https://github.com/${process.env.GITHUB_REPOSITORY}/actions/runs/${context.payload.workflow_run.id}#${id}`;
85+
86+
summary += `| [\`${name}\`](${url}) | ${added} | ${removed} | ${changed} |\n`;
87+
}
88+
89+
summary += "\nThis comment will be updated if you push new changes";
90+
91+
fs.writeFileSync("summary.md", summary);
92+
93+
- name: Create/update comment
94+
run: |
95+
if [[ -f summary.md ]]; then
96+
gh pr comment "$PR" --body-file summary.md --edit-last --create-if-none
97+
else
98+
# There were no changes detected by Lintcheck
99+
# - If a comment exists from a previous run that did detect changes, edit it (--edit-last)
100+
# - If no comment exists do not create one, the `gh` command exits with an error which
101+
# `|| true` ignores
102+
gh pr comment "$PR" --body "No changes for ${{ github.event.workflow_run.head_sha }}" --edit-last || true
103+
fi
104+
env:
105+
GH_TOKEN: ${{ github.token }}
106+
GH_REPO: ${{ github.repository }}

src/tools/clippy/Cargo.toml

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ declare_clippy_lint = { path = "declare_clippy_lint" }
2828
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
2929
clippy_lints_internal = { path = "clippy_lints_internal", optional = true }
3030
tempfile = { version = "3.20", optional = true }
31-
termize = "0.1"
31+
termize = "0.2"
3232
color-print = "0.3.4"
3333
anstream = "0.6.18"
3434

3535
[dev-dependencies]
3636
cargo_metadata = "0.18.1"
37-
ui_test = "0.29.2"
37+
ui_test = "0.30.2"
3838
regex = "1.5.5"
3939
serde = { version = "1.0.145", features = ["derive"] }
4040
serde_json = "1.0.122"
@@ -45,14 +45,6 @@ itertools = "0.12"
4545
pulldown-cmark = { version = "0.11", default-features = false, features = ["html"] }
4646
askama = { version = "0.14", default-features = false, features = ["alloc", "config", "derive"] }
4747

48-
# UI test dependencies
49-
if_chain = "1.0"
50-
quote = "1.0.25"
51-
syn = { version = "2.0", features = ["full"] }
52-
futures = "0.3"
53-
parking_lot = "0.12"
54-
tokio = { version = "1", features = ["io-util"] }
55-
5648
[build-dependencies]
5749
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
5850

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,4 +109,4 @@ worth backporting this.
109109
When a PR is backported to Rust `beta`, label the PR with `beta-accepted`. This
110110
will then get picked up when [writing the changelog].
111111

112-
[writing the changelog]: changelog_update.md#31-include-beta-accepted-prs
112+
[writing the changelog]: changelog_update.md#4-include-beta-accepted-prs

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

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Usually you want to write the changelog of the **upcoming stable release**. Make
3838
sure though, that `beta` was already branched in the Rust repository.
3939

4040
To find the commit hash, issue the following command when in a `rust-lang/rust`
41-
checkout:
41+
checkout (most of the time on the `upstream/beta` branch):
4242
```
4343
git log --oneline -- src/tools/clippy/ | grep -o "Merge commit '[a-f0-9]*' into .*" | head -1 | sed -e "s/Merge commit '\([a-f0-9]*\)' into .*/\1/g"
4444
```
@@ -48,16 +48,13 @@ git log --oneline -- src/tools/clippy/ | grep -o "Merge commit '[a-f0-9]*' into
4848
Once you've got the correct commit range, run
4949

5050
```
51-
util/fetch_prs_between.sh commit1 commit2 > changes.txt
51+
util/fetch_prs_between.sh start_commit end_commit > changes.txt
5252
```
5353

54-
where `commit2` is the commit hash from the previous command and `commit1`
55-
is the commit hash from the current CHANGELOG file.
54+
where `end_commit` is the commit hash from the previous command and `start_commit`
55+
is [the commit hash][beta_section] from the current CHANGELOG file.
5656
Open `changes.txt` file in your editor of choice.
5757

58-
When updating the changelog it's also a good idea to make sure that `commit1` is
59-
already correct in the current changelog.
60-
6158
### 3. Authoring the final changelog
6259

6360
The above script should have dumped all the relevant PRs to the file you
@@ -70,17 +67,7 @@ With the PRs filtered, you can start to take each PR and move the `changelog: `
7067
content to `CHANGELOG.md`. Adapt the wording as you see fit but try to keep it
7168
somewhat coherent.
7269

73-
The order should roughly be:
74-
75-
1. New lints
76-
2. Moves or deprecations of lints
77-
3. Changes that expand what code existing lints cover
78-
4. False positive fixes
79-
5. ICE fixes
80-
6. Documentation improvements
81-
7. Others
82-
83-
As section headers, we use:
70+
The sections order should roughly be:
8471

8572
```
8673
### New Lints
@@ -97,10 +84,10 @@ As section headers, we use:
9784
### Others
9885
```
9986

100-
Please also be sure to update the Beta/Unreleased sections at the top with the
101-
relevant commit ranges.
87+
Please also be sure to update [the `Unreleased/Beta/In Rust Nightly` section][beta_section] at the top with the
88+
relevant commits ranges and to add the `Rust <version>` section with release date and PR ranges.
10289

103-
#### 3.1 Include `beta-accepted` PRs
90+
### 4. Include `beta-accepted` PRs
10491

10592
Look for the [`beta-accepted`] label and make sure to also include the PRs with
10693
that label in the changelog. If you can, remove the `beta-accepted` labels
@@ -109,7 +96,7 @@ that label in the changelog. If you can, remove the `beta-accepted` labels
10996
> _Note:_ Some of those PRs might even get backported to the previous `beta`.
11097
> Those have to be included in the changelog of the _previous_ release.
11198
112-
### 4. Update `clippy::version` attributes
99+
### 5. Update `clippy::version` attributes
113100

114101
Next, make sure to check that the `#[clippy::version]` attributes for the added
115102
lints contain the correct version.
@@ -129,3 +116,4 @@ written for. If not, update the version to the changelog version.
129116
[rust_beta_tools]: https://github.com/rust-lang/rust/tree/beta/src/tools/clippy
130117
[rust_stable_tools]: https://github.com/rust-lang/rust/releases
131118
[`beta-accepted`]: https://github.com/rust-lang/rust-clippy/issues?q=label%3Abeta-accepted+
119+
[beta_section]: https://github.com/rust-lang/rust-clippy/blob/master/CHANGELOG.md#unreleased--beta--in-rust-nightly

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
892892
* [`unnested_or_patterns`](https://rust-lang.github.io/rust-clippy/master/index.html#unnested_or_patterns)
893893
* [`unused_trait_names`](https://rust-lang.github.io/rust-clippy/master/index.html#unused_trait_names)
894894
* [`use_self`](https://rust-lang.github.io/rust-clippy/master/index.html#use_self)
895+
* [`zero_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#zero_ptr)
895896

896897

897898
## `pass-by-value-size-limit`

src/tools/clippy/clippy_config/src/conf.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,7 @@ define_Conf! {
794794
unnested_or_patterns,
795795
unused_trait_names,
796796
use_self,
797+
zero_ptr,
797798
)]
798799
msrv: Msrv = Msrv::default(),
799800
/// The minimum size (in bytes) to consider a type for passing by reference instead of by value.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ fn fmt_conf(check: bool) -> Result<(), Error> {
223223
if check {
224224
return Err(Error::CheckFailed);
225225
}
226-
fs::write(path, new_text.as_bytes())?;
226+
fs::write(path, new_text)?;
227227
}
228228
Ok(())
229229
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
rustc_private,
33
exit_status_error,
44
if_let_guard,
5-
let_chains,
65
os_str_slice,
76
os_string_truncate,
87
slice_split_once

0 commit comments

Comments
 (0)