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

Clippy subtree update #138761

Merged
merged 149 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
149 commits
Select commit Hold shift + click to select a range
c012693
needless_collect: avoid warning if non-iterator methods are used
notriddle Feb 4, 2025
287a942
`comparison_chain`: `style` → `pedantic`
samueltardieu Feb 15, 2025
6321ac7
needless_collect: look through assignments, not just declarations
notriddle Feb 17, 2025
e297c84
Remove Known problems section for vec_box
alex-semenyuk Feb 19, 2025
af40c23
fix suggestion for assignments wrapped in parentheses under `needless…
lapla-cogito Feb 7, 2025
8f001ea
In `AssocOp::AssignOp`, use `BinOpKind` instead of `BinOpToken`
nnethercote Dec 19, 2024
c79a7ed
Introduce `AssocOp::Binary`.
nnethercote Dec 19, 2024
6db6a4f
Replace `AssocOp::DotDot{,Eq}` with `AssocOp::Range`.
nnethercote Dec 19, 2024
537577f
Rename `AssocOp::As` as `AssocOp::Cast`.
nnethercote Dec 19, 2024
3a39629
Refactor function after adding a new diagnostic item
samueltardieu Feb 26, 2025
de25d0d
Clean up TypeckResults::extract_binding_mode
meithecatte Feb 27, 2025
222aaba
Rollup merge of #137712 - meithecatte:extract-binding-mode, r=oli-obk
jieyouxu Feb 28, 2025
18616dc
fix: `map_entry` suggest wrongly when key is not `Copy`
profetia Feb 27, 2025
4f0e507
`incompatible_msrv`: lint function calls with any argument count
samueltardieu Feb 13, 2025
fe01c44
Merge commit '9f9a822509e5ad3e560cbbe830d1013f936fca28' into clippy-s…
flip1995 Feb 28, 2025
a6a78e1
Clippy: skip check_host_compiler check in rustc testsuite
flip1995 Feb 20, 2025
870f395
Fix link to ty::Ty in clippy_utils
flip1995 Feb 21, 2025
60e1d7e
Extend `{implicit,inverted}_saturating_sub` to expressions
samueltardieu Feb 27, 2025
029a6db
Apply `implicit_saturating_sub` to Clippy sources
samueltardieu Feb 27, 2025
8178530
Extend `{implicit,inverted}_saturating_sub` to expressions (#14310)
llogiq Mar 1, 2025
e15b9a0
Suggest using `#[expect]` to check lint positioning
samueltardieu Mar 1, 2025
1419ac2
Suggest using `#[expect]` to check lint positioning (#14327)
xFrednet Mar 1, 2025
f94f64f
new lint: `doc_comment_double_space_linebreak`
Jacherr Jun 1, 2024
2fd51b8
`doc_comment_double_space_linebreaks`: lint per line instead of by block
Jacherr Feb 13, 2025
60191cf
`doc_comment_double_space_linebreak`: Use multi spans and suggestions
xFrednet Mar 1, 2025
7fe160a
Rename `doc_comment_double_space_linebreak` -> `doc_comment_double_sp…
xFrednet Mar 1, 2025
45e4487
`doc_comment_double_space_linebreaks`: Fix tests
xFrednet Mar 1, 2025
d395646
fix [`undocumented_unsafe_blocks`] FP with trait/impl items
J-ZhengLi Jul 10, 2024
91d20cb
Use inner span in `undocumented_unsafe_blocks`
profetia Dec 28, 2024
3899488
fix `undocumented_unsafe_blocks` FP in long assignment
profetia Feb 17, 2025
d027ca9
Add regression test for #11709
profetia Feb 17, 2025
6537f93
rename the MSRV alias `MANUAL_DIV_CEIL` to `DIV_CEIL`
lapla-cogito Mar 1, 2025
35746de
`comparison_chain`: `style` → `pedantic` (#14219)
llogiq Mar 1, 2025
cac9e0a
Implment `#[cfg]` and `#[cfg_attr]` in `where` clauses
frank-king Feb 5, 2025
62f34f2
fix: `undocumented_unsafe_blocks` FP on trait/impl items (#13888)
xFrednet Mar 1, 2025
d7d0abd
Lint more cases of `ptr::eq()`
samueltardieu Mar 2, 2025
336d344
Apply `ptr_eq` lint only if `cmp_null` is not applicable
samueltardieu Mar 2, 2025
aa2180f
fix: `map_entry` suggest wrongly when key is not `Copy` (#14314)
blyxyas Mar 2, 2025
a9c61ec
needless_collect: avoid warning if non-iterator methods are used (#14…
blyxyas Mar 2, 2025
68679f2
fix: `manual_let_else` missing binding mode
profetia Feb 12, 2025
ddc9f45
Remove some unnecessary aliases from `rustc_data_structures::sync`
Zalathar Mar 3, 2025
c94576e
Rollup merge of #132388 - frank-king:feature/where-cfg, r=petrochenkov
matthiaskrgr Mar 3, 2025
d63d56a
add `macos-latest` as a CI target
lapla-cogito Mar 3, 2025
1f0d057
Auto merge of #137959 - matthiaskrgr:rollup-62vjvwr, r=matthiaskrgr
bors Mar 4, 2025
4141362
Use the latest nightly rust to run linkcheck
samueltardieu Mar 4, 2025
b4b7c7b
Use the latest nightly rust to run linkcheck (#14348)
flip1995 Mar 4, 2025
cdc1d9d
Lint more cases with `ptr_eq` (#14339)
flip1995 Mar 4, 2025
e587a5d
better help for `mixed_case_hex_literals`
lapla-cogito Feb 16, 2025
e6a4cf6
don't trigger `unnecessary_debug_formatting` in tests
lapla-cogito Mar 4, 2025
9f0d819
Create helper function to suggest a candidate in case of a typo
decryphe Mar 3, 2025
5df6887
Make alphabetic ordering in module item groups configurable (new defa…
decryphe Nov 21, 2024
9275ae9
Walk back to the root context to compute the span
samueltardieu Mar 4, 2025
dd8cf05
better help for `mixed_case_hex_literals` (#14235)
Alexendoo Mar 4, 2025
2440f51
don't trigger `unnecessary_debug_formatting` in tests (#14347)
Centri3 Mar 4, 2025
2067375
Make `struct_field_names` lint on private fields of public structs.
kpreid Jan 25, 2025
8c73b76
Move `check_variant()` code into a method of `ItemNameRepetitions` too.
kpreid Feb 16, 2025
9538e5b
Walk back to the root context to compute the span (#14349)
llogiq Mar 5, 2025
e8cd3d4
Use size_of from the prelude instead of imported
thaliaarchi Mar 5, 2025
8108bd8
Remove Known problems section for `vec_box` (#14252)
Alexendoo Mar 5, 2025
1cd7022
fix incorrect suggestions related to parentheses in `needless_return`
lapla-cogito Jan 29, 2025
ad633be
Use `size_of` from the prelude instead of imported (#14355)
Centri3 Mar 5, 2025
06e7590
Refactor function after adding a new diagnostic item (#14306)
Centri3 Mar 5, 2025
231bf45
Make `struct_field_names` check private fields of public structs. (#1…
Centri3 Mar 5, 2025
2fda4f6
add `is_expr_temporary_value` helper function
lapla-cogito Feb 24, 2025
27e69a8
apply `is_expr_temporary_value` to Clippy source
lapla-cogito Feb 24, 2025
06f797d
don't call `iter()` on a temporary object in `unnecessary_to_owned`
lapla-cogito Feb 17, 2025
81643e2
`unnecessary_to_owned`: don't call `iter()` on a temporary object (#1…
Centri3 Mar 5, 2025
a028651
fix: `missing_const_for_fn` FP on unstable const traits
profetia Feb 25, 2025
e5c1d1c
Remove the `Option` part of range ends in the HIR
oli-obk Feb 5, 2025
cc6127b
docs: update rationale for excessive-bools
therewillbecode Mar 4, 2025
cee9abf
docs: update rationale for excessive-bools (#14351)
blyxyas Mar 6, 2025
d52ac1b
Fix clippy
spastorino Dec 26, 2024
cf07525
Make synthetic RPITIT assoc ty name handling more rigorous.
nnethercote Mar 4, 2025
c919de7
Rollup merge of #134797 - spastorino:ergonomic-ref-counting-1, r=niko…
matthiaskrgr Mar 7, 2025
eac092f
Rollup merge of #137977 - nnethercote:less-kw-Empty-1, r=spastorino
matthiaskrgr Mar 7, 2025
19930f9
rename the MSRV alias `MANUAL_DIV_CEIL` to `DIV_CEIL` (#14329)
dswij Mar 8, 2025
f83c94c
fix: `manual_let_else` missing binding mode (#14204)
dswij Mar 8, 2025
243e0ee
don't trigger `blocks_in_conditions` when the condition contains a `r…
lapla-cogito Mar 2, 2025
79013f8
Improve `needless_pass_by_value` suggestion
GuillaumeGomez Dec 26, 2024
c8e47f9
Update `needless_pass_by_value` stderr
GuillaumeGomez Mar 8, 2025
1b62885
don't trigger `blocks_in_conditions` when the condition contains a `r…
Manishearth Mar 9, 2025
ab21f71
fix broken CSS links
lapla-cogito Mar 9, 2025
8dd65e4
Add documentation to json.rs module
Turtel216 Mar 9, 2025
184feee
Fix key function description
Turtel216 Mar 9, 2025
7bae269
fix broken theme CSS links in the website (#14379)
Alexendoo Mar 9, 2025
3d775b3
docs: Add documentation to json.rs module (#14383)
Manishearth Mar 9, 2025
819f3c7
`arbitrary_source_item_ordering`: Make alphabetic ordering in module …
y21 Mar 9, 2025
97275d5
fix: `unnecessary_safety_comment` FP on desugared assign
profetia Mar 7, 2025
90dbc5b
make `never_loop` applicability more flexible
lapla-cogito Feb 12, 2025
a25cbd5
Improve `needless_pass_by_value` suggestion (#13880)
flip1995 Mar 10, 2025
cb044d4
Implement `#[define_opaque]` attribute for functions.
oli-obk Jul 26, 2024
a5bc316
add `macos-latest` as a CI target (#14342)
flip1995 Mar 11, 2025
cb9682b
Add missing tests annotations for `ui-internal`
GuillaumeGomez Mar 11, 2025
8f280ff
Add missing tests annotations for `ui-internal` (#14388)
flip1995 Mar 11, 2025
650b7d9
Move methods from `Map` to `TyCtxt`, part 4.
nnethercote Feb 21, 2025
714c64c
fix: `unnecessary_safety_comment` FP on desugared assign (#14371)
Alexendoo Mar 12, 2025
35e6057
`needless_pass_by_value`: reference the innermost `Option` content
samueltardieu Mar 11, 2025
cfc7432
Update `ui_test` version to `0.29.2`
GuillaumeGomez Mar 12, 2025
e4d3b0a
Update `produce_ice` so its error can be checked in ui tests
GuillaumeGomez Mar 12, 2025
ec8c0b3
Make annotations mandatory for internal ui tests
GuillaumeGomez Mar 12, 2025
092a20e
Update `lint_message_convention` test to allow clippy "help" message
GuillaumeGomez Mar 12, 2025
0730678
Make annotations mandatory for internal ui tests (#14393)
flip1995 Mar 12, 2025
417d4e6
`needless_pass_by_value`: make verbose suggestion
samueltardieu Mar 12, 2025
7254072
`needless_pass_by_value`: reference the innermost `Option` content (#…
flip1995 Mar 12, 2025
44094e5
explain `is_from_proc_macro` in the book
y21 Mar 12, 2025
21601fd
Improve `string_to_string` lint in case it is in a `map` call
GuillaumeGomez Mar 12, 2025
0ffc6cf
Add ui test for `string_to_string` in map calls
GuillaumeGomez Mar 12, 2025
559f23e
Update copyright year
alex-semenyuk Mar 12, 2025
18061e2
`incompatible_msrv`: lint function calls with any argument count (#14…
Centri3 Mar 13, 2025
0e4b6c8
Make `string_to_string` emit a suggestion when `cloned` can be used
GuillaumeGomez Mar 13, 2025
c07fd48
Update copyright year (#14399)
Alexendoo Mar 13, 2025
f85331f
Explain `is_from_proc_macro` and `proc_macros` auxiliary crate in the…
flip1995 Mar 13, 2025
915e442
Do not suggest using `-Zmacro-backtrace` for builtin macros
estebank Mar 11, 2025
da910b1
Add failing from_over_into test case
KonaeAkira Mar 14, 2025
4a324c9
Fix from_over_into lint suggesting invalid code
KonaeAkira Mar 14, 2025
9c897a2
Simplify implementation
KonaeAkira Mar 14, 2025
5c031d1
Fix `from_over_into` lint suggesting invalid code (#14409)
Alexendoo Mar 15, 2025
f96eb61
Fold visit into ty
compiler-errors Mar 13, 2025
f357993
Auto merge of #138464 - compiler-errors:less-type-ir, r=lcnr
bors Mar 15, 2025
4e9caa3
question_mark: suggest `as_ref`/`as_mut` if ref binding is used
notriddle Mar 15, 2025
9845b10
Remove `@xFrednet` from docs :wave:
xFrednet Mar 16, 2025
3c7dfac
new lint: `doc_comment_double_space_linebreaks` (#12876)
xFrednet Mar 16, 2025
1617a2e
Remove `@xFrednet` from docs :wave: (#14415)
xFrednet Mar 16, 2025
775a5c2
fix incorrect suggestions related to parentheses in `needless_return`…
Alexendoo Mar 16, 2025
9eab078
Suppress must_use in compiler and tools
compiler-errors Feb 22, 2025
b23fcb0
fix: bad indent in doc comments
tkr-sh Mar 16, 2025
2b431f7
Fix `is_relevant_impl`.
nnethercote Mar 12, 2025
4800557
question_mark: avoid incorrect suggestion when `ref` binding used (#1…
blyxyas Mar 16, 2025
a3865b1
fix: `option_if_let_else` FP when value partially moved
profetia Feb 13, 2025
a1bdc19
Reinstate `single_match`/`single_match_else` lints with comments
samueltardieu Mar 16, 2025
6222a73
Move `hir::Item::ident` into `hir::ItemKind`.
nnethercote Mar 6, 2025
b057ba4
Leave assignments for now
Centri3 Mar 18, 2025
9932e5e
Auto merge of #138630 - matthiaskrgr:rollup-kk1gogr, r=matthiaskrgr
bors Mar 18, 2025
269b913
Better handle blocks with just one expression
GuillaumeGomez Mar 17, 2025
a07e887
Improve `string_to_string` lint in case it is in a map call (#14396)
flip1995 Mar 18, 2025
ea30a09
Leave assignments for now (#14428)
blyxyas Mar 18, 2025
d443f38
Reinstate `single_match`/`single_match_else` lints with comments (#14…
Alexendoo Mar 18, 2025
a422d9e
fix: bad indent in doc comments (#14419)
Alexendoo Mar 18, 2025
d793c0a
Add MSRV check for `question_mark`
blyxxyz Mar 19, 2025
31497d6
fix: `option_if_let_else` FP when value partially moved (#14209)
blyxyas Mar 19, 2025
48ce25e
Add MSRV check for `question_mark` (#14436)
Manishearth Mar 19, 2025
221ae5f
fix suggestion for assignments have enclosing parentheses under `need…
y21 Mar 19, 2025
f2feb0f
make `never_loop` applicability more flexible (#14203)
y21 Mar 20, 2025
dc4c776
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Mar 20, 2025
a086879
Bump nightly version -> 2025-03-20
flip1995 Mar 20, 2025
d1d0fee
Rustup (#14445)
flip1995 Mar 20, 2025
1e5237f
fix: `missing_const_for_fn` FP on unstable const traits (#14294)
y21 Mar 20, 2025
ae31f7a
Merge commit '1e5237f4a56ae958af7e5824343eacf737b67083' into clippy-s…
flip1995 Mar 20, 2025
58142e9
Update Cargo.lock
flip1995 Mar 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ dependencies = [
"termize",
"tokio",
"toml 0.7.8",
"ui_test 0.26.5",
"ui_test 0.29.2",
"walkdir",
]

Expand Down Expand Up @@ -2021,7 +2021,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc2f4eb4bc735547cfed7c0a4922cbd04a4655978c09b54f1f7b228750664c34"
dependencies = [
"cfg-if",
"windows-targets 0.48.5",
"windows-targets 0.52.6",
]

[[package]]
Expand Down Expand Up @@ -5488,9 +5488,9 @@ dependencies = [

[[package]]
name = "ui_test"
version = "0.26.5"
version = "0.28.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32ee4c40e5a5f9fa6864ff976473e5d6a6e9884b6ce68b40690d9f87e1994c83"
checksum = "7484683d60d50ca1d1b6433c3dbf6c5ad71d20387acdcfb16fe79573f3fba576"
dependencies = [
"annotate-snippets 0.11.5",
"anyhow",
Expand All @@ -5514,9 +5514,9 @@ dependencies = [

[[package]]
name = "ui_test"
version = "0.28.0"
version = "0.29.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7484683d60d50ca1d1b6433c3dbf6c5ad71d20387acdcfb16fe79573f3fba576"
checksum = "1211b1111c752c73b33073d2958072be08825fd97c9ab4d83444da361a06634b"
dependencies = [
"annotate-snippets 0.11.5",
"anyhow",
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/.github/workflows/clippy_mq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ jobs:
host: x86_64-pc-windows-msvc
- os: macos-13
host: x86_64-apple-darwin
- os: macos-latest
host: aarch64-apple-darwin

runs-on: ${{ matrix.os }}

Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/.github/workflows/remark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ jobs:
- name: Linkcheck book
run: |
rustup toolchain install nightly --component rust-docs
rustup override set nightly
curl https://raw.githubusercontent.com/rust-lang/rust/master/src/tools/linkchecker/linkcheck.sh -o linkcheck.sh
sh linkcheck.sh clippy --path ./book
Expand Down
2 changes: 2 additions & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5570,6 +5570,7 @@ Released 2018-09-13
[`disallowed_type`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_type
[`disallowed_types`]: https://rust-lang.github.io/rust-clippy/master/index.html#disallowed_types
[`diverging_sub_expression`]: https://rust-lang.github.io/rust-clippy/master/index.html#diverging_sub_expression
[`doc_comment_double_space_linebreaks`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_comment_double_space_linebreaks
[`doc_include_without_cfg`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_include_without_cfg
[`doc_lazy_continuation`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_lazy_continuation
[`doc_link_code`]: https://rust-lang.github.io/rust-clippy/master/index.html#doc_link_code
Expand Down Expand Up @@ -6372,6 +6373,7 @@ Released 2018-09-13
[`min-ident-chars-threshold`]: https://doc.rust-lang.org/clippy/lint_configuration.html#min-ident-chars-threshold
[`missing-docs-in-crate-items`]: https://doc.rust-lang.org/clippy/lint_configuration.html#missing-docs-in-crate-items
[`module-item-order-groupings`]: https://doc.rust-lang.org/clippy/lint_configuration.html#module-item-order-groupings
[`module-items-ordered-within-groupings`]: https://doc.rust-lang.org/clippy/lint_configuration.html#module-items-ordered-within-groupings
[`msrv`]: https://doc.rust-lang.org/clippy/lint_configuration.html#msrv
[`pass-by-value-size-limit`]: https://doc.rust-lang.org/clippy/lint_configuration.html#pass-by-value-size-limit
[`pub-underscore-fields-behavior`]: https://doc.rust-lang.org/clippy/lint_configuration.html#pub-underscore-fields-behavior
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/COPYRIGHT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// REUSE-IgnoreStart

Copyright 2014-2024 The Rust Project Developers
Copyright 2014-2025 The Rust Project Developers

Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ anstream = "0.6.18"

[dev-dependencies]
cargo_metadata = "0.18.1"
ui_test = "0.26.4"
ui_test = "0.29.2"
regex = "1.5.5"
serde = { version = "1.0.145", features = ["derive"] }
serde_json = "1.0.122"
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/LICENSE-APACHE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ APPENDIX: How to apply the Apache License to your work.
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2014-2024 The Rust Project Developers
Copyright 2014-2025 The Rust Project Developers

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2014-2024 The Rust Project Developers
Copyright (c) 2014-2025 The Rust Project Developers

Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ If you want to contribute to Clippy, you can find more information in [CONTRIBUT

<!-- REUSE-IgnoreStart -->

Copyright 2014-2024 The Rust Project Developers
Copyright 2014-2025 The Rust Project Developers

Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
[https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)> or the MIT license
Expand Down
76 changes: 76 additions & 0 deletions src/tools/clippy/book/src/development/macro_expansions.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,85 @@ if foo_span.in_external_macro(cx.sess().source_map()) {
}
```

### The `is_from_proc_macro` function
A common point of confusion is the existence of [`is_from_proc_macro`]
and how it differs from the other [`in_external_macro`]/[`from_expansion`] functions.

While [`in_external_macro`] and [`from_expansion`] both work perfectly fine for detecting expanded code
from *declarative* macros (i.e. `macro_rules!` and macros 2.0),
detecting *proc macro*-generated code is a bit more tricky, as proc macros can (and often do)
freely manipulate the span of returned tokens.

In practice, this often happens through the use of [`quote::quote_spanned!`] with a span from the input tokens.

In those cases, there is no *reliable* way for the compiler (and tools like Clippy)
to distinguish code that comes from such a proc macro from code that the user wrote directly,
and [`in_external_macro`] will return `false`.

This is usually not an issue for the compiler and actually helps proc macro authors create better error messages,
as it allows associating parts of the expansion with parts of the macro input and lets the compiler
point the user to the relevant code in case of a compile error.

However, for Clippy this is inconvenient, because most of the time *we don't* want
to lint proc macro-generated code and this makes it impossible to tell what is and isn't proc macro code.

> NOTE: this is specifically only an issue when a proc macro explicitly sets the span to that of an **input span**.
>
> For example, other common ways of creating `TokenStream`s, such as `"fn foo() {...}".parse::<TokenStream>()`,
> sets each token's span to `Span::call_site()`, which already marks the span as coming from a proc macro
> and the usual span methods have no problem detecting that as a macro span.
As such, Clippy has its own `is_from_proc_macro` function which tries to *approximate*
whether a span comes from a proc macro, by checking whether the source text at the given span
lines up with the given AST node.

This function is typically used in combination with the other mentioned macro span functions,
but is usually called much later into the condition chain as it's a bit heavier than most other conditions,
so that the other cheaper conditions can fail faster. For example, the `borrow_deref_ref` lint:
```rs
impl<'tcx> LateLintPass<'tcx> for BorrowDerefRef {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &rustc_hir::Expr<'tcx>) {
if let ... = ...
&& ...
&& !e.span.from_expansion()
&& ...
&& ...
&& !is_from_proc_macro(cx, e)
&& ...
{
...
}
}
}
```

### Testing lints with macro expansions
To test that all of these cases are handled correctly in your lint,
we have a helper auxiliary crate that exposes various macros, used by tests like so:
```rust
//@aux-build:proc_macros.rs

extern crate proc_macros;

fn main() {
proc_macros::external!{ code_that_should_trigger_your_lint }
proc_macros::with_span!{ span code_that_should_trigger_your_lint }
}
```
This exercises two cases:
- `proc_macros::external!` is a simple proc macro that echos the input tokens back but with a macro span:
this represents the usual, common case where an external macro expands to code that your lint would trigger,
and is correctly handled by `in_external_macro` and `Span::from_expansion`.

- `proc_macros::with_span!` echos back the input tokens starting from the second token
with the span of the first token: this is where the other functions will fail and `is_from_proc_macro` is needed


[`ctxt`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.ctxt
[expansion]: https://rustc-dev-guide.rust-lang.org/macro-expansion.html#expansion-and-ast-integration
[`from_expansion`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.from_expansion
[`in_external_macro`]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html#method.in_external_macro
[Span]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/struct.Span.html
[SyntaxContext]: https://doc.rust-lang.org/stable/nightly-rustc/rustc_span/hygiene/struct.SyntaxContext.html
[`is_from_proc_macro`]: https://doc.rust-lang.org/nightly/nightly-rustc/clippy_utils/fn.is_from_proc_macro.html
[`quote::quote_spanned!`]: https://docs.rs/quote/latest/quote/macro.quote_spanned.html
3 changes: 1 addition & 2 deletions src/tools/clippy/book/src/development/the_team.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ is responsible for maintaining Clippy.

5. **Update the changelog**

This needs to be done for every release, every six weeks. This is usually
done by @xFrednet.
This needs to be done for every release, every six weeks.

### Membership

Expand Down
14 changes: 14 additions & 0 deletions src/tools/clippy/book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,19 @@ The named groupings of different source item kinds within modules.
* [`arbitrary_source_item_ordering`](https://rust-lang.github.io/rust-clippy/master/index.html#arbitrary_source_item_ordering)


## `module-items-ordered-within-groupings`
Whether the items within module groups should be ordered alphabetically or not.

This option can be configured to "all", "none", or a list of specific grouping names that should be checked
(e.g. only "enums").

**Default Value:** `"none"`

---
**Affected lints:**
* [`arbitrary_source_item_ordering`](https://rust-lang.github.io/rust-clippy/master/index.html#arbitrary_source_item_ordering)


## `msrv`
The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml`

Expand Down Expand Up @@ -806,6 +819,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
* [`option_as_ref_deref`](https://rust-lang.github.io/rust-clippy/master/index.html#option_as_ref_deref)
* [`option_map_unwrap_or`](https://rust-lang.github.io/rust-clippy/master/index.html#option_map_unwrap_or)
* [`ptr_as_ptr`](https://rust-lang.github.io/rust-clippy/master/index.html#ptr_as_ptr)
* [`question_mark`](https://rust-lang.github.io/rust-clippy/master/index.html#question_mark)
* [`redundant_field_names`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names)
* [`redundant_static_lifetimes`](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_static_lifetimes)
* [`repeat_vec_with_capacity`](https://rust-lang.github.io/rust-clippy/master/index.html#repeat_vec_with_capacity)
Expand Down
Loading
Loading