Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Clippy #115183

Merged
merged 107 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
107 commits
Select commit Hold shift + click to select a range
36a5000
rustc: Move `crate_types` from `Session` to `GlobalCtxt`
petrochenkov Aug 8, 2023
42186af
Correctly handle async blocks for NEEDLESS_PASS_BY_REF_MUT
GuillaumeGomez Aug 10, 2023
1d01f1b
Update UI test for async blocks for NEEDLESS_PASS_BY_REF_MUT
GuillaumeGomez Aug 10, 2023
1ec0501
Revert "New lint [`filter_map_bool_then`]"
Centri3 Aug 10, 2023
a1ab2d7
Auto merge of #114719 - compiler-errors:rollup-bf1vr51, r=compiler-er…
bors Aug 11, 2023
f730a26
Merge commit '1e8fdf492808a25d78a97e1242b835ace9924e4d' into clippyup
flip1995 Aug 11, 2023
4c779da
Remove some leftover cruft from compiletest-rs
oli-obk Aug 3, 2023
0afd38b
Make a panic message more informative if binary files are accidentall…
oli-obk Aug 7, 2023
3d88fae
Update ui test crate
oli-obk Jul 27, 2023
00919a4
Update ui test crate to auto-detect aux build crate kind
oli-obk Jul 27, 2023
1088507
Canonicalize paths in a single location
oli-obk Aug 7, 2023
43f04e1
Bump ui_test crate
oli-obk Aug 8, 2023
665a619
Bump ui_test
oli-obk Aug 10, 2023
739faf3
Auto merge of #11239 - oli-obk:ui_test, r=Alexendoo,flip1995
bors Aug 11, 2023
a7af8bc
Fix SPEEDTEST instructions
oli-obk Aug 11, 2023
cd8f12d
Show correct measurements in SPEEDTEST
oli-obk Aug 11, 2023
75370e0
Auto merge of #11325 - oli-obk:SPEEDTEST, r=flip1995
bors Aug 11, 2023
7a06d7e
[new_without_default]: lifetimes are included in output
samueltardieu Aug 1, 2023
621e76d
[new_without_default]: include `where` clauses in suggestion
samueltardieu Jul 31, 2023
f9b22e7
[new_without_default]: make the suggestion machine-applicable
samueltardieu Aug 1, 2023
d5dbee4
feat: update manual_retain to lint binary_heap_retain
unvalley Aug 12, 2023
3ac06a1
Do not bless by default in ui tests
Alexendoo Aug 13, 2023
1eff39d
fix: change msrv to 1.69 for binary heap
unvalley Aug 13, 2023
83afad4
Auto merge of #11333 - Alexendoo:uitest-default-check, r=flip1995
bors Aug 13, 2023
344ae11
Auto merge of #11329 - unvalley:lint-binary-heap-retain, r=Alexendoo
bors Aug 13, 2023
fc06189
[`iter_overeager_cloned`]: detect .cloned().filter() and .cloned().fi…
lengyijun Aug 3, 2023
b8b3e07
Remove constness from `ImplSource::Param`
fee1-dead Aug 13, 2023
7c87e5c
Use `{Local}ModDefId` in many queries
Noratrieb Apr 26, 2023
b5bfd11
Auto merge of #11289 - lengyijun:filter_find, r=blyxyas
bors Aug 14, 2023
34348f7
[`useless_conversion`]: make sure path points to fn-like item
y21 Jul 2, 2023
2820d98
[`useless_conversion`]: fix FP in macro and add test
y21 Jul 2, 2023
f47165c
find expansions more efficiently
y21 Jul 9, 2023
77d10ac
Use ui_test's Windows path backslash heuristic
Alexendoo Aug 14, 2023
89fdc3e
Move scrutinee `HirId` into `MatchSource::TryDesugar`
estebank Aug 14, 2023
d0a26f1
bless clippy test
estebank Aug 14, 2023
aa8995e
allow calling `to_owned` with borrowed value for [`implicit_clone`]
J-ZhengLi Aug 15, 2023
11efa01
Auto merge of #11321 - J-ZhengLi:issue11281, r=giraffate
bors Aug 15, 2023
9e33b69
Rollup merge of #114772 - fee1-dead-contrib:typed-did, r=b-naber
GuillaumeGomez Aug 15, 2023
710db18
Auto merge of #11336 - Alexendoo:uitest-backslash, r=flip1995
bors Aug 15, 2023
39219a6
Rollup merge of #114819 - estebank:issue-78124, r=compiler-errors
matthiaskrgr Aug 15, 2023
97d31c8
New chapter: Defining Lints
blyxyas Apr 3, 2023
c22906b
Fix CI formatting issues
blyxyas Apr 4, 2023
735380b
Try to clear up confusion between `type` and `category`.
blyxyas Apr 10, 2023
7465436
Improve briefness
blyxyas Apr 17, 2023
b91d676
Move "Lint types to the top"
blyxyas Apr 17, 2023
6076cda
Fix CI
blyxyas Apr 18, 2023
783c119
Address review comments and formatting
flip1995 Aug 16, 2023
87d1487
Auto merge of #10595 - blyxyas:book-define_lints, r=flip1995
bors Aug 16, 2023
111f022
Add "Method Checking"
blyxyas Apr 13, 2023
9e4a2d7
Fixes based on reviews
blyxyas Apr 17, 2023
e8d79b8
Formatting
flip1995 Aug 16, 2023
1dbc8dd
Fix define_lints->defining_lints typo in link
flip1995 Aug 16, 2023
d43486d
Auto merge of #10644 - blyxyas:book-method_checking, r=flip1995
bors Aug 16, 2023
7e46217
Add new regression test for `needless_pass_by_ref_mut`
GuillaumeGomez Aug 17, 2023
701e77c
Auto merge of #11070 - y21:issue11065, r=flip1995
bors Aug 17, 2023
5875bd2
Use `HirId` from `PlaceWithHirId` rather than using the one provided …
GuillaumeGomez Aug 17, 2023
d5298be
Auto merge of #11314 - GuillaumeGomez:needless_ref_mut_async_block, r…
bors Aug 17, 2023
d068043
Auto merge of #11070 - y21:issue11065, r=flip1995
bors Aug 17, 2023
5638860
Auto merge of #11314 - GuillaumeGomez:needless_ref_mut_async_block, r…
bors Aug 17, 2023
ede4306
Remove use of `box_syntax` CONTRIBUTING.md` example
eopb Aug 17, 2023
40872cb
Auto merge of #11348 - eopb:eopb-patch-1, r=flip1995
bors Aug 18, 2023
1698ce0
Auto merge of #11280 - samueltardieu:issue-11267, r=Centri3
bors Aug 18, 2023
41570c1
Update version attribute for 1.72 lints
xFrednet Aug 18, 2023
8f06b19
Changelog for Rust 1.72 :beach_umbrella:
xFrednet Aug 18, 2023
d9e6aac
Auto merge of #11351 - xFrednet:changelog-1-72, r=Centri3
bors Aug 18, 2023
e52bd6f
new lint: `should_panic_without_expect`
y21 Jul 21, 2023
b4ab67f
remove useless path
y21 Aug 19, 2023
b7cad50
Auto merge of #11204 - y21:issue10956, r=Alexendoo
bors Aug 19, 2023
e440065
[`iter_overeager_cloned`]: detect .cloned().map() and .cloned().for_e…
lengyijun Aug 5, 2023
7408f1d
Auto merge of #11319 - lengyijun:map_foreach, r=blyxyas
bors Aug 19, 2023
8f2d47e
Check that the suggested method exists in unwrap_or_default
Alexendoo Aug 19, 2023
50f7f8e
give some unwind-related terminators a more clear name
RalfJung Aug 19, 2023
fc1152a
Auto merge of #11359 - Alexendoo:unwrap-or-default-check-suggestion, …
bors Aug 20, 2023
7fbf808
Added new lint: `reserve_after_initialization`
Red-Rapious Aug 21, 2023
e33a17e
Changed Box
Red-Rapious Aug 21, 2023
073149a
Changed documentation example and removed comments
Red-Rapious Aug 21, 2023
a1bf23f
Added more use cases
Red-Rapious Aug 21, 2023
b0bd621
Simplified code and added tests
Red-Rapious Aug 21, 2023
e35eb91
Fix tuple_array_conversions lint on nightly
popzxc Aug 22, 2023
9c96605
Manually add annotations for ui tests
GuillaumeGomez Jul 28, 2023
3a31c05
Remove/move comments to prevent weird rustfmt wrapping
GuillaumeGomez Jul 28, 2023
a05d3a4
Automatic generation of error annotations for ui tests
GuillaumeGomez Jul 28, 2023
f467012
Move code comments to prevent having weird clippy fmt issues
GuillaumeGomez Aug 11, 2023
4be90d0
Auto merge of #11249 - GuillaumeGomez:ui-tests-annotations, r=Centri3…
bors Aug 22, 2023
df8bb47
Improved snippets and added tests
Red-Rapious Aug 22, 2023
7977d20
Do not lint inside macros
Red-Rapious Aug 22, 2023
e9a222b
Minor changes
Red-Rapious Aug 22, 2023
32eecd4
Fix clippy lint for identical `if`/`else` contraining `?` expressions
estebank Aug 23, 2023
f0eaa66
Add a test for tuple_array_conversion
popzxc Aug 23, 2023
edfee16
Auto merge of #11379 - popzxc:fix-tuple-array-conversions, r=xFrednet
bors Aug 23, 2023
f3c5877
Put `is_from_proc_macro` last
Red-Rapious Aug 23, 2023
4932d05
Auto merge of #11373 - Red-Rapious:master, r=blyxyas,y21
bors Aug 23, 2023
42bd6d7
new lint: `implied_bounds_in_impl`
y21 Aug 19, 2023
2ebff58
make generics work
y21 Aug 20, 2023
09506f4
rename lint, docs, improve diagnostics
y21 Aug 23, 2023
1227571
support inherent impls and trait impls
y21 Aug 23, 2023
df68b71
Auto merge of #11362 - y21:superfluous_impl, r=xFrednet
bors Aug 24, 2023
fe38aaa
Update changelog stable note
xFrednet Aug 24, 2023
202c846
Auto merge of #11397 - xFrednet:changelog-bump-rust-1-72, r=Centri3
bors Aug 24, 2023
ef4d64f
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Aug 24, 2023
e1ec41b
Fix dogfood issues
flip1995 Aug 24, 2023
da06825
Bump Clippy version -> 0.1.74
flip1995 Aug 24, 2023
9334e5d
Bump nightly version -> 2023-08-24
flip1995 Aug 24, 2023
080b587
Auto merge of #11398 - flip1995:rustup, r=flip1995
bors Aug 24, 2023
7137a09
Merge commit '080b587854a73f2a8cbaecff1884860a78e2ff37' into clippyup
flip1995 Aug 24, 2023
ac25a73
Update Cargo.lock (ui_test update)
flip1995 Aug 24, 2023
4fdb4ed
Bump ui_test
oli-obk Aug 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
239 changes: 208 additions & 31 deletions Cargo.lock

Large diffs are not rendered by default.

107 changes: 99 additions & 8 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,105 @@ document.

## Unreleased / Beta / In Rust Nightly

[435a8ad8...master](https://github.com/rust-lang/rust-clippy/compare/435a8ad8...master)
[37f4c172...master](https://github.com/rust-lang/rust-clippy/compare/37f4c172...master)

## Rust 1.71
## Rust 1.72

Current stable, released 2023-08-24

[View all 131 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-05-22T14%3A53%3A59Z..2023-07-01T22%3A57%3A20Z+base%3Amaster)

### New Lints

* [`manual_try_fold`]
[#11012](https://github.com/rust-lang/rust-clippy/pull/11012)
* [`tuple_array_conversions`]
[#11020](https://github.com/rust-lang/rust-clippy/pull/11020)
* [`redundant_at_rest_pattern`]
[#11013](https://github.com/rust-lang/rust-clippy/pull/11013)
* [`needless_pub_self`]
[#10967](https://github.com/rust-lang/rust-clippy/pull/10967)
* [`pub_with_shorthand`]
[#10967](https://github.com/rust-lang/rust-clippy/pull/10967)
* [`pub_without_shorthand`]
[#10967](https://github.com/rust-lang/rust-clippy/pull/10967)
* [`manual_range_patterns`]
[#10968](https://github.com/rust-lang/rust-clippy/pull/10968)
* [`needless_raw_string_hashes`]
[#10884](https://github.com/rust-lang/rust-clippy/pull/10884)
* [`needless_raw_strings`]
[#10884](https://github.com/rust-lang/rust-clippy/pull/10884)
* [`incorrect_clone_impl_on_copy_type`]
[#10925](https://github.com/rust-lang/rust-clippy/pull/10925)
* [`drain_collect`]
[#10835](https://github.com/rust-lang/rust-clippy/pull/10835)
* [`single_range_in_vec_init`]
[#10934](https://github.com/rust-lang/rust-clippy/pull/10934)
* [`unnecessary_literal_unwrap`]
[#10358](https://github.com/rust-lang/rust-clippy/pull/10358)
* [`large_stack_frames`]
[#10827](https://github.com/rust-lang/rust-clippy/pull/10827)
* [`min_ident_chars`]
[#10916](https://github.com/rust-lang/rust-clippy/pull/10916)
* [`needless_if`]
[#10921](https://github.com/rust-lang/rust-clippy/pull/10921)
* [`excessive_nesting`]
[#10672](https://github.com/rust-lang/rust-clippy/pull/10672)
* [`arc_with_non_send_sync`]
[#10898](https://github.com/rust-lang/rust-clippy/pull/10898)
* [`redundant_type_annotations`]
[#10570](https://github.com/rust-lang/rust-clippy/pull/10570)
* [`host_endian_bytes`]
[#10826](https://github.com/rust-lang/rust-clippy/pull/10826)
* [`little_endian_bytes`]
[#10826](https://github.com/rust-lang/rust-clippy/pull/10826)
* [`big_endian_bytes`]
[#10826](https://github.com/rust-lang/rust-clippy/pull/10826)
* [`ptr_cast_constness`]
[#10779](https://github.com/rust-lang/rust-clippy/pull/10779)
* [`needless_else`]
[#10810](https://github.com/rust-lang/rust-clippy/pull/10810)

### Moves and Deprecations

* Moved [`redundant_clone`] to `nursery` (Now allow-by-default)
[#10873](https://github.com/rust-lang/rust-clippy/pull/10873)

### Enhancements

* [`undocumented_unsafe_blocks`]: Added [`accept-comment-above-attributes`] configuration
[#10986](https://github.com/rust-lang/rust-clippy/pull/10986)
* [`undocumented_unsafe_blocks`]: Added [`accept-comment-above-statement`] configuration.
[#10886](https://github.com/rust-lang/rust-clippy/pull/10886)
* [`missing_panics_doc`]: No longer lints on `todo!()`
[#10976](https://github.com/rust-lang/rust-clippy/pull/10976)
* [`module_inception`]: Added `allow-private-module-inception` configuration.
[#10917](https://github.com/rust-lang/rust-clippy/pull/10917)
* Errors and warnings generated while parsing `clippy.toml` now point to the location in the TOML
file the error/warning occurred in.
[#10607](https://github.com/rust-lang/rust-clippy/pull/10607)

### False Positive Fixes

* [`excessive_precision`]: No longer lints overflowing literals
[#10952](https://github.com/rust-lang/rust-clippy/pull/10952)

### Suggestion Fixes/Improvements

* [`option_map_unwrap_or`]: The suggestion now considers the set [`msrv`] config value
[#11030](https://github.com/rust-lang/rust-clippy/pull/11030)

### Documentation Improvements

* [Clippy's lint list] now stores filter parameters in the URL, to allow easy sharing
[#10834](https://github.com/rust-lang/rust-clippy/pull/10834)

Current stable, released 2023-07-13
## Rust 1.71

<!-- FIXME: Remove the request for feedback, with the next changelog -->
Released 2023-07-13

We're trying out a new shorter changelog format, that only contains significant changes.
You can check out the list of merged pull requests for a list of all changes.
If you have any feedback related to the new format, please share it in
[#10847](https://github.com/rust-lang/rust-clippy/issues/10847)
Note: Clippy will use a shorter changelog format from now on, if you want a detailed list of
all changes, please check out the list of merged pull requests.

[View all 78 merged pull requests](https://github.com/rust-lang/rust-clippy/pulls?q=merged%3A2023-04-11T20%3A05%3A26Z..2023-05-20T13%3A48%3A17Z+base%3Amaster)

Expand Down Expand Up @@ -4677,6 +4764,7 @@ Released 2018-09-13
[pull3665]: https://github.com/rust-lang/rust-clippy/pull/3665
[adding_lints]: https://github.com/rust-lang/rust-clippy/blob/master/book/src/development/adding_lints.md
[`README.md`]: https://github.com/rust-lang/rust-clippy/blob/master/README.md
[Clippy's lint list]: https://rust-lang.github.io/rust-clippy/master/index.html

<!-- lint disable no-unused-definitions -->
<!-- begin autogenerated links to lint list -->
Expand Down Expand Up @@ -4897,6 +4985,7 @@ Released 2018-09-13
[`implicit_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_return
[`implicit_saturating_add`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_add
[`implicit_saturating_sub`]: https://rust-lang.github.io/rust-clippy/master/index.html#implicit_saturating_sub
[`implied_bounds_in_impls`]: https://rust-lang.github.io/rust-clippy/master/index.html#implied_bounds_in_impls
[`impossible_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#impossible_comparisons
[`imprecise_flops`]: https://rust-lang.github.io/rust-clippy/master/index.html#imprecise_flops
[`inconsistent_digit_grouping`]: https://rust-lang.github.io/rust-clippy/master/index.html#inconsistent_digit_grouping
Expand Down Expand Up @@ -5211,6 +5300,7 @@ Released 2018-09-13
[`regex_macro`]: https://rust-lang.github.io/rust-clippy/master/index.html#regex_macro
[`repeat_once`]: https://rust-lang.github.io/rust-clippy/master/index.html#repeat_once
[`replace_consts`]: https://rust-lang.github.io/rust-clippy/master/index.html#replace_consts
[`reserve_after_initialization`]: https://rust-lang.github.io/rust-clippy/master/index.html#reserve_after_initialization
[`rest_pat_in_fully_bound_structs`]: https://rust-lang.github.io/rust-clippy/master/index.html#rest_pat_in_fully_bound_structs
[`result_expect_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_expect_used
[`result_large_err`]: https://rust-lang.github.io/rust-clippy/master/index.html#result_large_err
Expand Down Expand Up @@ -5241,6 +5331,7 @@ Released 2018-09-13
[`short_circuit_statement`]: https://rust-lang.github.io/rust-clippy/master/index.html#short_circuit_statement
[`should_assert_eq`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_assert_eq
[`should_implement_trait`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_implement_trait
[`should_panic_without_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#should_panic_without_expect
[`significant_drop_in_scrutinee`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_in_scrutinee
[`significant_drop_tightening`]: https://rust-lang.github.io/rust-clippy/master/index.html#significant_drop_tightening
[`similar_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#similar_names
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ pub mod else_if_without_else;

pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf: &Conf) {
// ...
store.register_early_pass(|| box else_if_without_else::ElseIfWithoutElse);
store.register_early_pass(|| Box::new(else_if_without_else::ElseIfWithoutElse));
// ...

store.register_group(true, "clippy::restriction", Some("clippy_restriction"), vec![
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "clippy"
version = "0.1.73"
version = "0.1.74"
description = "A bunch of helpful lints to avoid common pitfalls in Rust"
repository = "https://github.com/rust-lang/rust-clippy"
readme = "README.md"
Expand All @@ -27,7 +27,7 @@ tempfile = { version = "3.2", optional = true }
termize = "0.1"

[dev-dependencies]
ui_test = "0.11.5"
ui_test = "0.18.1"
tester = "0.9"
regex = "1.5"
toml = "0.7.3"
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@
- [Development](development/README.md)
- [Basics](development/basics.md)
- [Adding Lints](development/adding_lints.md)
- [Defining Lints](development/defining_lints.md)
- [Lint Passes](development/lint_passes.md)
- [Type Checking](development/type_checking.md)
- [Method Checking](development/method_checking.md)
- [Macro Expansions](development/macro_expansions.md)
- [Common Tools](development/common_tools_writing_lints.md)
- [Infrastructure](development/infrastructure/README.md)
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/book/src/development/adding_lints.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ The process of generating the `.stderr` file is the same, and prepending the
## Rustfix tests

If the lint you are working on is making use of structured suggestions, the test
file should include a `//@run-rustfix` comment at the top. This will
additionally run [rustfix] for that test. Rustfix will apply the suggestions
will create a `.fixed` file by running [rustfix] for that test.
Rustfix will apply the suggestions
from the lint to the code of the test file and compare that to the contents of a
`.fixed` file.

Expand Down
205 changes: 205 additions & 0 deletions src/tools/clippy/book/src/development/defining_lints.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
# Define New Lints

The first step in the journey of a new lint is the definition
and registration of the lint in Clippy's codebase.
We can use the Clippy dev tools to handle this step since setting up the
lint involves some boilerplate code.

#### Lint types

A lint type is the category of items and expressions in which your lint focuses on.

As of the writing of this documentation update, there are 12 _types_ of lints
besides the numerous standalone lints living under `clippy_lints/src/`:

- `cargo`
- `casts`
- `functions`
- `loops`
- `matches`
- `methods`
- `misc_early`
- `operators`
- `transmute`
- `types`
- `unit_types`
- `utils / internal` (Clippy internal lints)

These types group together lints that share some common behaviors. For instance,
`functions` groups together lints that deal with some aspects of functions in
Rust, like definitions, signatures and attributes.

For more information, feel free to compare the lint files under any category
with [All Clippy lints][all_lints] or ask one of the maintainers.

## Lint name

A good lint name is important, make sure to check the [lint naming
guidelines][lint_naming]. Don't worry, if the lint name doesn't fit, a Clippy
team member will alert you in the PR process.

---

We'll name our example lint that detects functions named "foo" `foo_functions`.
Check the [lint naming guidelines][lint_naming] to see why this name makes
sense.

## Add and Register the Lint

Now that a name is chosen, we shall register `foo_functions` as a lint to the
codebase. There are two ways to register a lint.

### Standalone

If you believe that this new lint is a standalone lint (that doesn't belong to
any specific [type](#lint-types) like `functions` or `loops`), you can run the
following command in your Clippy project:

```sh
$ cargo dev new_lint --name=lint_name --pass=late --category=pedantic
```

There are two things to note here:

1. `--pass`: We set `--pass=late` in this command to do a late lint pass. The
alternative is an `early` lint pass. We will discuss this difference in a
later chapter.
<!-- FIXME: Link that "later chapter" when lint_passes.md is merged -->
2. `--category`: If not provided, the `category` of this new lint will default
to `nursery`.

The `cargo dev new_lint` command will create a new file:
`clippy_lints/src/foo_functions.rs` as well as [register the
lint](#lint-registration).

Overall, you should notice that the following files are modified or created:

```sh
$ git status
On branch foo_functions
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: CHANGELOG.md
modified: clippy_lints/src/lib.register_lints.rs
modified: clippy_lints/src/lib.register_pedantic.rs
modified: clippy_lints/src/lib.rs

Untracked files:
(use "git add <file>..." to include in what will be committed)
clippy_lints/src/foo_functions.rs
tests/ui/foo_functions.rs
```


### Specific Type

> **Note**: Lint types are listed in the ["Lint types"](#lint-types) section
If you believe that this new lint belongs to a specific type of lints,
you can run `cargo dev new_lint` with a `--type` option.

Since our `foo_functions` lint is related to function calls, one could
argue that we should put it into a group of lints that detect some behaviors
of functions, we can put it in the `functions` group.

Let's run the following command in your Clippy project:

```sh
$ cargo dev new_lint --name=foo_functions --type=functions --category=pedantic
```

This command will create, among other things, a new file:
`clippy_lints/src/{type}/foo_functions.rs`.
In our case, the path will be `clippy_lints/src/functions/foo_functions.rs`.

Notice how this command has a `--type` flag instead of `--pass`. Unlike a standalone
definition, this lint won't be registered in the traditional sense. Instead, you will
call your lint from within the type's lint pass, found in `clippy_lints/src/{type}/mod.rs`.

A _type_ is just the name of a directory in `clippy_lints/src`, like `functions` in
the example command. Clippy groups together some lints that share common behaviors,
so if your lint falls into one, it would be best to add it to that type.

Overall, you should notice that the following files are modified or created:

```sh
$ git status
On branch foo_functions
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: CHANGELOG.md
modified: clippy_lints/src/declared_lints.rs
modified: clippy_lints/src/functions/mod.rs

Untracked files:
(use "git add <file>..." to include in what will be committed)
clippy_lints/src/functions/foo_functions.rs
tests/ui/foo_functions.rs
```


## The `define_clippy_lints` macro

After `cargo dev new_lint`, you should see a macro with the name
`define_clippy_lints`. It will be in the same file if you defined a standalone
lint, and it will be in `mod.rs` if you defined a type-specific lint.

The macro looks something like this:

```rust
declare_clippy_lint! {
/// ### What it does
///
/// // Describe here what does the lint do.
///
/// Triggers when detects...
///
/// ### Why is this bad?
///
/// // Describe why this pattern would be bad
///
/// It can lead to...
///
/// ### Example
/// ```rust
/// // example code where clippy issues a warning
/// ```
/// Use instead:
/// ```rust
/// // example code which does not raise clippy warning
/// ```
#[clippy::version = "1.70.0"] // <- In which version was this implemented, keep it up to date!
pub LINT_NAME, // <- The lint name IN_ALL_CAPS
pedantic, // <- The lint group
"default lint description" // <- A lint description, e.g. "A function has an unit return type."
}
```

## Lint registration

If we run the `cargo dev new_lint` command for a new lint, the lint will be
automatically registered and there is nothing more to do.

However, sometimes we might want to declare a new lint by hand. In this case,
we'd use `cargo dev update_lints` command afterwards.

When a lint is manually declared, we might need to register the lint pass
manually in the `register_plugins` function in `clippy_lints/src/lib.rs`:

```rust
store.register_late_pass(|_| Box::new(foo_functions::FooFunctions));
```

As you might have guessed, where there's something late, there is something
early: in Clippy there is a `register_early_pass` method as well. More on early
vs. late passes in a later chapter.
<!-- FIXME: Link that "later chapter" when lint_passes.md is merged -->

Without a call to one of `register_early_pass` or `register_late_pass`, the lint
pass in question will not be run.


[all_lints]: https://rust-lang.github.io/rust-clippy/master/
[lint_naming]: https://rust-lang.github.io/rfcs/0344-conventions-galore.html#lints
Loading
Loading