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

Commit c4f112a

Browse files
committed
Auto merge of rust-lang#124123 - flip1995:clippy-subtree-update, r=Manishearth
Clippy subtree update r? `@Manishearth`
2 parents 0ed85d0 + 9028e00 commit c4f112a

File tree

84 files changed

+1066
-426
lines changed

Some content is hidden

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

84 files changed

+1066
-426
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
node-version: '18.x'
2525

2626
- name: Install remark
27-
run: npm install remark-cli remark-lint remark-lint-maximum-line-length remark-preset-lint-recommended remark-gfm
27+
run: npm install remark-cli remark-lint remark-lint-maximum-line-length@^3.1.3 remark-preset-lint-recommended remark-gfm
2828

2929
- name: Install mdbook
3030
run: |

src/tools/clippy/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5894,6 +5894,7 @@ Released 2018-09-13
58945894
[`allowed-dotfiles`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-dotfiles
58955895
[`allowed-duplicate-crates`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-duplicate-crates
58965896
[`allowed-idents-below-min-chars`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-idents-below-min-chars
5897+
[`allowed-prefixes`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-prefixes
58975898
[`allowed-scripts`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-scripts
58985899
[`allowed-wildcard-imports`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allowed-wildcard-imports
58995900
[`arithmetic-side-effects-allowed`]: https://doc.rust-lang.org/clippy/lint_configuration.html#arithmetic-side-effects-allowed

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,27 @@ category.
1818
| `clippy::all` | all lints that are on by default (correctness, suspicious, style, complexity, perf) | **warn/deny** |
1919
| `clippy::correctness` | code that is outright wrong or useless | **deny** |
2020
| `clippy::suspicious` | code that is most likely wrong or useless | **warn** |
21+
| `clippy::style` | code that should be written in a more idiomatic way | **warn** |
2122
| `clippy::complexity` | code that does something simple but in a complex way | **warn** |
2223
| `clippy::perf` | code that can be written to run faster | **warn** |
23-
| `clippy::style` | code that should be written in a more idiomatic way | **warn** |
24-
| `clippy::pedantic` | lints which are rather strict or might have false positives | allow |
24+
| `clippy::pedantic` | lints which are rather strict or have occasional false positives | allow |
25+
| `clippy::restriction` | lints which prevent the use of language and library features[^restrict] | allow |
2526
| `clippy::nursery` | new lints that are still under development | allow |
26-
| `clippy::cargo` | lints for the cargo manifest | allow | | allow |
27+
| `clippy::cargo` | lints for the cargo manifest | allow |
28+
29+
More to come, please [file an issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas!
30+
31+
The `restriction` category should, *emphatically*, not be enabled as a whole. The contained
32+
lints may lint against perfectly reasonable code, may not have an alternative suggestion,
33+
and may contradict any other lints (including other categories). Lints should be considered
34+
on a case-by-case basis before enabling.
2735

28-
More to come, please [file an
29-
issue](https://github.com/rust-lang/rust-clippy/issues) if you have ideas!
36+
[^restrict]: Some use cases for `restriction` lints include:
37+
- Strict coding styles (e.g. [`clippy::else_if_without_else`]).
38+
- Additional restrictions on CI (e.g. [`clippy::todo`]).
39+
- Preventing panicking in certain functions (e.g. [`clippy::unwrap_used`]).
40+
- Running a lint only on a subset of code (e.g. `#[forbid(clippy::float_arithmetic)]` on a module).
3041

31-
The [lint list](https://rust-lang.github.io/rust-clippy/master/index.html) also
32-
contains "restriction lints", which are for things which are usually not
33-
considered "bad", but may be useful to turn on in specific cases. These should
34-
be used very selectively, if at all.
42+
[`clippy::else_if_without_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#else_if_without_else
43+
[`clippy::todo`]: https://rust-lang.github.io/rust-clippy/master/index.html#todo
44+
[`clippy::unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used

src/tools/clippy/book/src/development/adding_lints.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ because that's clearly a non-descriptive name.
1818
- [Cargo lints](#cargo-lints)
1919
- [Rustfix tests](#rustfix-tests)
2020
- [Testing manually](#testing-manually)
21-
- [Running directly](#running-directly)
2221
- [Lint declaration](#lint-declaration)
2322
- [Lint registration](#lint-registration)
2423
- [Lint passes](#lint-passes)
@@ -176,23 +175,26 @@ the tests.
176175

177176
Manually testing against an example file can be useful if you have added some
178177
`println!`s and the test suite output becomes unreadable. To try Clippy with
179-
your local modifications, run
178+
your local modifications, run the following from the Clippy directory:
180179

181-
```
180+
```bash
182181
cargo dev lint input.rs
183182
```
184183

185-
from the working copy root. With tests in place, let's have a look at
186-
implementing our lint now.
184+
To run Clippy on an existing project rather than a single file you can use
185+
186+
```bash
187+
cargo dev lint /path/to/project
188+
```
189+
190+
Or set up a rustup toolchain that points to the local Clippy binaries
187191

188-
## Running directly
192+
```bash
193+
cargo dev setup toolchain
189194

190-
While it's easier to just use `cargo dev lint`, it might be desirable to get
191-
`target/release/cargo-clippy` and `target/release/clippy-driver` to work as well in some cases.
192-
By default, they don't work because clippy dynamically links rustc. To help them find rustc,
193-
add the path printed by`rustc --print target-libdir` (ran inside this workspace so that the rustc version matches)
194-
to your library search path.
195-
On linux, this can be done by setting the `LD_LIBRARY_PATH` environment variable to that path.
195+
# Then in `/path/to/project` you can run
196+
cargo +clippy clippy
197+
```
196198

197199
## Lint declaration
198200

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,32 @@ configuration of Clippy. By default, any configuration will replace the default
164164
* [`min_ident_chars`](https://rust-lang.github.io/rust-clippy/master/index.html#min_ident_chars)
165165

166166

167+
## `allowed-prefixes`
168+
List of prefixes to allow when determining whether an item's name ends with the module's name.
169+
If the rest of an item's name is an allowed prefix (e.g. item `ToFoo` or `to_foo` in module `foo`),
170+
then don't emit a warning.
171+
172+
#### Example
173+
174+
```toml
175+
allowed-prefixes = [ "to", "from" ]
176+
```
177+
178+
#### Noteworthy
179+
180+
- By default, the following prefixes are allowed: `to`, `as`, `into`, `from`, `try_into` and `try_from`
181+
- PascalCase variant is included automatically for each snake_case variant (e.g. if `try_into` is included,
182+
`TryInto` will also be included)
183+
- Use `".."` as part of the list to indicate that the configured values should be appended to the
184+
default configuration of Clippy. By default, any configuration will replace the default value
185+
186+
**Default Value:** `["to", "as", "into", "from", "try_into", "try_from"]`
187+
188+
---
189+
**Affected lints:**
190+
* [`module_name_repetitions`](https://rust-lang.github.io/rust-clippy/master/index.html#module_name_repetitions)
191+
192+
167193
## `allowed-scripts`
168194
The list of unicode scripts allowed to be used in the scope.
169195

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
3939
];
4040
const DEFAULT_DISALLOWED_NAMES: &[&str] = &["foo", "baz", "quux"];
4141
const DEFAULT_ALLOWED_IDENTS_BELOW_MIN_CHARS: &[&str] = &["i", "j", "x", "y", "z", "w", "n"];
42+
const DEFAULT_ALLOWED_PREFIXES: &[&str] = &["to", "as", "into", "from", "try_into", "try_from"];
4243

4344
/// Conf with parse errors
4445
#[derive(Default)]
@@ -589,6 +590,26 @@ define_Conf! {
589590
/// 2. Paths with any segment that containing the word 'prelude'
590591
/// are already allowed by default.
591592
(allowed_wildcard_imports: FxHashSet<String> = FxHashSet::default()),
593+
/// Lint: MODULE_NAME_REPETITIONS.
594+
///
595+
/// List of prefixes to allow when determining whether an item's name ends with the module's name.
596+
/// If the rest of an item's name is an allowed prefix (e.g. item `ToFoo` or `to_foo` in module `foo`),
597+
/// then don't emit a warning.
598+
///
599+
/// #### Example
600+
///
601+
/// ```toml
602+
/// allowed-prefixes = [ "to", "from" ]
603+
/// ```
604+
///
605+
/// #### Noteworthy
606+
///
607+
/// - By default, the following prefixes are allowed: `to`, `as`, `into`, `from`, `try_into` and `try_from`
608+
/// - PascalCase variant is included automatically for each snake_case variant (e.g. if `try_into` is included,
609+
/// `TryInto` will also be included)
610+
/// - Use `".."` as part of the list to indicate that the configured values should be appended to the
611+
/// default configuration of Clippy. By default, any configuration will replace the default value
612+
(allowed_prefixes: Vec<String> = DEFAULT_ALLOWED_PREFIXES.iter().map(ToString::to_string).collect()),
592613
}
593614

594615
/// Search for the configuration file.
@@ -649,6 +670,7 @@ fn deserialize(file: &SourceFile) -> TryConf {
649670
Ok(mut conf) => {
650671
extend_vec_if_indicator_present(&mut conf.conf.doc_valid_idents, DEFAULT_DOC_VALID_IDENTS);
651672
extend_vec_if_indicator_present(&mut conf.conf.disallowed_names, DEFAULT_DISALLOWED_NAMES);
673+
extend_vec_if_indicator_present(&mut conf.conf.allowed_prefixes, DEFAULT_ALLOWED_PREFIXES);
652674
// TODO: THIS SHOULD BE TESTED, this comment will be gone soon
653675
if conf.conf.allowed_idents_below_min_chars.contains("..") {
654676
conf.conf

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ struct FmtContext {
3535
}
3636

3737
// the "main" function of cargo dev fmt
38-
#[allow(clippy::missing_panics_doc)]
3938
pub fn run(check: bool, verbose: bool) {
4039
fn try_run(context: &FmtContext) -> Result<bool, CliError> {
4140
let mut success = true;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
unused_lifetimes,
1010
unused_qualifications
1111
)]
12+
#![allow(clippy::missing_panics_doc)]
1213

1314
// The `rustc_driver` crate seems to be required in order to use the `rust_lexer` crate.
1415
#[allow(unused_extern_crates)]

src/tools/clippy/clippy_dev/src/main.rs

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@ fn main() {
4646
}
4747
},
4848
Some(("setup", sub_command)) => match sub_command.subcommand() {
49+
Some(("git-hook", matches)) => {
50+
if matches.get_flag("remove") {
51+
setup::git_hook::remove_hook();
52+
} else {
53+
setup::git_hook::install_hook(matches.get_flag("force-override"));
54+
}
55+
},
4956
Some(("intellij", matches)) => {
5057
if matches.get_flag("remove") {
5158
setup::intellij::remove_rustc_src();
@@ -57,12 +64,12 @@ fn main() {
5764
);
5865
}
5966
},
60-
Some(("git-hook", matches)) => {
61-
if matches.get_flag("remove") {
62-
setup::git_hook::remove_hook();
63-
} else {
64-
setup::git_hook::install_hook(matches.get_flag("force-override"));
65-
}
67+
Some(("toolchain", matches)) => {
68+
setup::toolchain::create(
69+
matches.get_flag("force"),
70+
matches.get_flag("release"),
71+
matches.get_one::<String>("name").unwrap(),
72+
);
6673
},
6774
Some(("vscode-tasks", matches)) => {
6875
if matches.get_flag("remove") {
@@ -210,6 +217,19 @@ fn get_clap_config() -> ArgMatches {
210217
.about("Support for setting up your personal development environment")
211218
.arg_required_else_help(true)
212219
.subcommands([
220+
Command::new("git-hook")
221+
.about("Add a pre-commit git hook that formats your code to make it look pretty")
222+
.args([
223+
Arg::new("remove")
224+
.long("remove")
225+
.action(ArgAction::SetTrue)
226+
.help("Remove the pre-commit hook added with 'cargo dev setup git-hook'"),
227+
Arg::new("force-override")
228+
.long("force-override")
229+
.short('f')
230+
.action(ArgAction::SetTrue)
231+
.help("Forces the override of an existing git pre-commit hook"),
232+
]),
213233
Command::new("intellij")
214234
.about("Alter dependencies so Intellij Rust can find rustc internals")
215235
.args([
@@ -225,18 +245,23 @@ fn get_clap_config() -> ArgMatches {
225245
.conflicts_with("remove")
226246
.required(true),
227247
]),
228-
Command::new("git-hook")
229-
.about("Add a pre-commit git hook that formats your code to make it look pretty")
248+
Command::new("toolchain")
249+
.about("Install a rustup toolchain pointing to the local clippy build")
230250
.args([
231-
Arg::new("remove")
232-
.long("remove")
233-
.action(ArgAction::SetTrue)
234-
.help("Remove the pre-commit hook added with 'cargo dev setup git-hook'"),
235-
Arg::new("force-override")
236-
.long("force-override")
251+
Arg::new("force")
252+
.long("force")
237253
.short('f')
238254
.action(ArgAction::SetTrue)
239-
.help("Forces the override of an existing git pre-commit hook"),
255+
.help("Override an existing toolchain"),
256+
Arg::new("release")
257+
.long("release")
258+
.short('r')
259+
.action(ArgAction::SetTrue)
260+
.help("Point to --release clippy binaries"),
261+
Arg::new("name")
262+
.long("name")
263+
.default_value("clippy")
264+
.help("The name of the created toolchain"),
240265
]),
241266
Command::new("vscode-tasks")
242267
.about("Add several tasks to vscode for formatting, validation and testing")

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ impl<T> Context for io::Result<T> {
3636
/// # Errors
3737
///
3838
/// This function errors out if the files couldn't be created or written to.
39-
#[allow(clippy::missing_panics_doc)]
4039
pub fn create(
4140
pass: &String,
4241
lint_name: Option<&String>,

0 commit comments

Comments
 (0)