Skip to content

Clippy subtree update #127049

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

Merged
merged 88 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
0b43e03
Add applicability visually
SpencerAWill Apr 5, 2024
e4ce248
Complete filter functionality. Formatted upper filters to take more v…
SpencerAWill Apr 9, 2024
c8a7e6e
Remove debug helper.
SpencerAWill Apr 11, 2024
dff9164
consider `copy_deref` a possible borrower
y21 May 2, 2024
20d1bb1
[`assigning_clones`]: bail out when the source borrows from target
y21 May 2, 2024
60508f5
deal with non-`Drop` types and add a test case for projections
y21 May 2, 2024
5e60afb
[ arc_with_non_send_sync ]: fix doc nits
bitfield Jun 3, 2024
7ab4af3
[ needless_for_each ]: fix doc nits
bitfield Jun 3, 2024
35d284f
[ allow_attributes ]: fix doc nits
bitfield Jun 3, 2024
8da5d64
[ allow_attributes_without_reason ]: fix doc nits
bitfield Jun 3, 2024
7c86db4
[ mut_range_bound ]: fix doc nits
bitfield Jun 3, 2024
059eaf1
Fix ICE in `upper_case_acronyms` and remove most of the string alloc…
Jarcho Jun 8, 2024
70ca9a1
Lint `manual_unwrap_or` for it let cases
lochetti Jun 8, 2024
c3d4633
Fixup clippy tests
WaffleLapkin May 23, 2024
3bff119
Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into clippy-s…
flip1995 Jun 13, 2024
ba347f9
Auto merge of #126398 - flip1995:clippy-subtree-update, r=Manishearth
bors Jun 13, 2024
fa9274c
Tweak output of import suggestions
estebank Jun 12, 2024
82f0dc9
[`missing_const_for_fn`]: add machine-applicable suggestion
DaniPopes Jun 14, 2024
73c1bfb
Auto merge of #12880 - bitfield:fix_doc_nits_b, r=Alexendoo
bors Jun 15, 2024
477b0c6
lintcheck: Add JSON output, diff subcommand
Alexendoo Nov 1, 2022
feb0671
Add lintcheck diff github action
Alexendoo Feb 24, 2023
0dc265f
Auto merge of #12756 - y21:assigning_clones_lifetimes, r=Alexendoo
bors Jun 15, 2024
63388cb
add MSRV for manual_pattern_char_comparison
AurelienFT Jun 15, 2024
51c6630
Change MSRV check for manual_pattern_char_comparison only for pattern…
AurelienFT Jun 15, 2024
bcc7b0e
Fix minor typo
elijah-potter Jun 15, 2024
82345c3
Auto merge of #12937 - AurelienFT:add_msrv_manual_patter_char_compari…
bors Jun 15, 2024
a2c9782
Auto merge of #10398 - Alexendoo:auto-lintcheck, r=xFrednet
bors Jun 16, 2024
3a983c3
Merge lintcheck popular-crates bin as a subcommand
Alexendoo Jun 16, 2024
8065e0f
Auto merge of #12939 - Alexendoo:lintcheck-popular-crates, r=xFrednet
bors Jun 16, 2024
3405ce3
Add field_scoped_visibility_modifiers lint
kyleoneill Jun 16, 2024
9f5d60f
Auto merge of #12893 - kyleoneill:field_scoped_visibility_modifiers, …
bors Jun 16, 2024
a002f93
`expr_use_ctxt` changes:
Jarcho Feb 12, 2024
22710f3
Add lint `manual_inspect`
Jarcho Feb 12, 2024
16efa56
Auto merge of #12287 - Jarcho:issue_12250, r=llogiq
bors Jun 16, 2024
e18b310
Add more types to `is_from_proc_macro`
Jarcho Jun 17, 2024
f09650b
Use symbols when raising range expressions.
Jarcho Jun 16, 2024
4b16e26
Rework `octal_escapes`.
Jarcho Jun 15, 2024
6172178
Auto merge of #12938 - elijah-potter:patch-1, r=flip1995
bors Jun 17, 2024
2ad53f4
Auto merge of #12943 - Jarcho:range_sym, r=llogiq
bors Jun 17, 2024
198bbf8
Pause assignments to @xFrednet for summer break :beach_umbrella:
xFrednet Jun 17, 2024
9550481
Auto merge of #12947 - xFrednet:00000-summer-assignments, r=xFrednet
bors Jun 17, 2024
0625183
Auto merge of #12903 - Jarcho:issue_12284, r=y21
bors Jun 17, 2024
51c5eee
Auto merge of #12945 - Jarcho:octal_escape, r=Alexendoo
bors Jun 17, 2024
9e54ff2
Auto merge of #12906 - lochetti:manual_unwrap_or_if_let, r=y21
bors Jun 17, 2024
61fc1ae
Rework precise capturing syntax
compiler-errors Jun 5, 2024
7218fdd
Fix other tools
compiler-errors Jun 6, 2024
e28b998
Add myself back to reviewer rotation
Centri3 Jun 18, 2024
7e1ed1a
Auto merge of #12953 - Centri3:back, r=Centri3
bors Jun 18, 2024
bd75e44
Auto merge of #12655 - SpencerAWill:Add-applicability-filter, r=xFrednet
bors Jun 18, 2024
4b7ae63
Use a dedicated type instead of a reference for the diagnostic context
oli-obk Jun 18, 2024
29cc5c6
Auto merge of #12942 - Jarcho:ex_proc_macro, r=Manishearth
bors Jun 18, 2024
8cde354
Resolve Clippy `f16` and `f128` `unimplemented!`/`FIXME`s
tgross35 Jun 18, 2024
c693f31
Update float tests to include `f16` and `f128`
tgross35 Jun 18, 2024
b147b6d
Don't lint implicit_return on proc macros
lochetti Jun 19, 2024
4aee08f
Auto merge of #12963 - lochetti:fix_12874, r=Centri3
bors Jun 19, 2024
9749d99
resolve `clippy::invalid_paths` on `bool::then`
KisaragiEffective Jun 20, 2024
3baafd2
Fix `...` in multline code-skips in suggestions
estebank Jun 20, 2024
2f9f204
feat: unnecessary_min_max lint
vohoanglong0107 Feb 28, 2024
3e84ca8
Auto merge of #12368 - vohoanglong0107:unnecessary-min, r=Alexendoo
bors Jun 20, 2024
f6661f5
StaticForeignItem and StaticItem are the same
compiler-errors Jun 20, 2024
4baae5d
Add new `Span` utils to avoid both allocating and
Jarcho Jun 20, 2024
fe2fe7f
Auto merge of #12972 - Jarcho:span_ex, r=Manishearth
bors Jun 21, 2024
54b45f7
Fix incorrect suggestion for `manual_unwrap_or_default`
GuillaumeGomez Jun 19, 2024
0ce07f6
Auto merge of #12961 - GuillaumeGomez:fix-manual_unwrap_or_default, r…
bors Jun 21, 2024
58fc27f
Rollup merge of #126723 - estebank:dot-dot-dot, r=Nadrieril
GuillaumeGomez Jun 22, 2024
26c556d
Auto merge of #12965 - KisaragiEffective:resolve-invalid-paths-on-boo…
bors Jun 22, 2024
51ccad6
use short message format in integration test
llogiq Jun 23, 2024
9628130
Auto merge of #12985 - llogiq:fix-integration-test, r=Alexendoo
bors Jun 23, 2024
2194304
Cache lintcheck binary in ci
Alexendoo Jun 22, 2024
32374a1
Auto merge of #12930 - DaniPopes:missing-const-for-fn-suggestion, r=J…
bors Jun 23, 2024
35ec4eb
Rename the 2 unambiguous precedence levels to PREC_UNAMBIGUOUS
dtolnay Jun 24, 2024
8c718e5
ast: Standardize visiting order for attributes and node IDs
petrochenkov May 29, 2024
8631790
Auto merge of #12986 - Alexendoo:cache-lintcheck-bin, r=flip1995
bors Jun 24, 2024
606ada1
bump strip-ansi-escapes
klensy Jun 24, 2024
a155c38
Split out IntoIterator and non-Iterator constructors for AliasTy/Alia…
compiler-errors Jun 21, 2024
8998ce2
Replace Deref bounds on Interner in favor of a SliceLike trait
compiler-errors Jun 21, 2024
dfaa53f
Auto merge of #125741 - petrochenkov:atvisord, r=davidtwco
bors Jun 25, 2024
1b4c281
RFC 2383: Stabilize `lint_reasons` in Clippy :paperclips:
xFrednet Feb 10, 2024
01b3c24
Rollup merge of #126893 - dtolnay:prec, r=compiler-errors
matthiaskrgr Jun 25, 2024
3bbec6a
`sudo CI=green` && Review changes <3
xFrednet Jun 4, 2024
f90d702
Auto merge of #120924 - xFrednet:rfc-2383-stabilization-party, r=Urga…
bors Jun 26, 2024
80b25b4
Fix doc_markdown DevOps false positive
reillysiemens Jun 25, 2024
aaaa926
Auto merge of #12995 - reillysiemens:fix-doc-markdown-devops-false-po…
bors Jun 27, 2024
4ddc8a2
Auto merge of #12992 - klensy:lintcheck-bump, r=Alexendoo
bors Jun 27, 2024
e9e7a81
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jun 27, 2024
585170e
Bump nightly version -> 2024-06-27
flip1995 Jun 27, 2024
68a799a
Auto merge of #12999 - flip1995:rustup, r=flip1995
bors Jun 27, 2024
3ce7f9e
Merge commit '68a799aea9b65e2444fbecfe32217ce7d5a3604f' into clippy-s…
flip1995 Jun 27, 2024
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
118 changes: 118 additions & 0 deletions src/tools/clippy/.github/workflows/lintcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: Lintcheck

on: pull_request

env:
RUST_BACKTRACE: 1
CARGO_INCREMENTAL: 0

concurrency:
# For a given workflow, if we push to the same PR, cancel all previous builds on that PR.
group: "${{ github.workflow }}-${{ github.event.pull_request.number}}"
cancel-in-progress: true

jobs:
# Runs lintcheck on the PR's target branch and stores the results as an artifact
base:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2

# HEAD is the generated merge commit `refs/pull/N/merge` between the PR and `master`, `HEAD^`
# being the commit from `master` that is the base of the merge
- name: Checkout base
run: git checkout HEAD^

# Use the lintcheck from the PR to generate the JSON in case the PR modifies lintcheck in some
# way
- name: Checkout current lintcheck
run: |
rm -rf lintcheck
git checkout ${{ github.sha }} -- lintcheck

- name: Cache lintcheck bin
id: cache-lintcheck-bin
uses: actions/cache@v4
with:
path: target/debug/lintcheck
key: lintcheck-bin-${{ hashfiles('lintcheck/**') }}

- name: Build lintcheck
if: steps.cache-lintcheck-bin.outputs.cache-hit != 'true'
run: cargo build --manifest-path=lintcheck/Cargo.toml

- name: Create cache key
id: key
run: echo "key=lintcheck-base-${{ hashfiles('lintcheck/**') }}-$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"

- name: Cache results JSON
id: cache-json
uses: actions/cache@v4
with:
path: lintcheck-logs/lintcheck_crates_logs.json
key: ${{ steps.key.outputs.key }}

- name: Run lintcheck
if: steps.cache-json.outputs.cache-hit != 'true'
run: ./target/debug/lintcheck --format json

- name: Upload base JSON
uses: actions/upload-artifact@v4
with:
name: base
path: lintcheck-logs/lintcheck_crates_logs.json

# Runs lintcheck on the PR and stores the results as an artifact
head:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Cache lintcheck bin
id: cache-lintcheck-bin
uses: actions/cache@v4
with:
path: target/debug/lintcheck
key: lintcheck-bin-${{ hashfiles('lintcheck/**') }}

- name: Build lintcheck
if: steps.cache-lintcheck-bin.outputs.cache-hit != 'true'
run: cargo build --manifest-path=lintcheck/Cargo.toml

- name: Run lintcheck
run: ./target/debug/lintcheck --format json

- name: Upload head JSON
uses: actions/upload-artifact@v4
with:
name: head
path: lintcheck-logs/lintcheck_crates_logs.json

# Retrieves the head and base JSON results and prints the diff to the GH actions step summary
diff:
runs-on: ubuntu-latest

needs: [base, head]

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Restore lintcheck bin
uses: actions/cache/restore@v4
with:
path: target/debug/lintcheck
key: lintcheck-bin-${{ hashfiles('lintcheck/**') }}
fail-on-cache-miss: true

- name: Download JSON
uses: actions/download-artifact@v4

- name: Diff results
run: ./target/debug/lintcheck diff {base,head}/lintcheck_crates_logs.json >> $GITHUB_STEP_SUMMARY
3 changes: 3 additions & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5362,6 +5362,7 @@ Released 2018-09-13
[`extra_unused_type_parameters`]: https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_type_parameters
[`fallible_impl_from`]: https://rust-lang.github.io/rust-clippy/master/index.html#fallible_impl_from
[`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
[`field_scoped_visibility_modifiers`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_scoped_visibility_modifiers
[`filetype_is_file`]: https://rust-lang.github.io/rust-clippy/master/index.html#filetype_is_file
[`filter_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map
[`filter_map_bool_then`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_bool_then
Expand Down Expand Up @@ -5520,6 +5521,7 @@ Released 2018-09-13
[`manual_find_map`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_find_map
[`manual_flatten`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_flatten
[`manual_hash_one`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_hash_one
[`manual_inspect`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_inspect
[`manual_instant_elapsed`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_instant_elapsed
[`manual_is_ascii_check`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_ascii_check
[`manual_is_finite`]: https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_finite
Expand Down Expand Up @@ -5915,6 +5917,7 @@ Released 2018-09-13
[`unnecessary_lazy_evaluations`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_lazy_evaluations
[`unnecessary_literal_unwrap`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_literal_unwrap
[`unnecessary_map_on_constructor`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_on_constructor
[`unnecessary_min_or_max`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_min_or_max
[`unnecessary_mut_passed`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
[`unnecessary_operation`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_operation
[`unnecessary_owned_empty_strings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_owned_empty_strings
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ default configuration of Clippy. By default, any configuration will replace the
* `doc-valid-idents = ["ClipPy"]` would replace the default list with `["ClipPy"]`.
* `doc-valid-idents = ["ClipPy", ".."]` would append `ClipPy` to the default list.

**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "WebGL", "WebGL2", "WebGPU", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`
**Default Value:** `["KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "DevOps", "DirectX", "ECMAScript", "GPLv2", "GPLv3", "GitHub", "GitLab", "IPv4", "IPv6", "ClojureScript", "CoffeeScript", "JavaScript", "PureScript", "TypeScript", "WebAssembly", "NaN", "NaNs", "OAuth", "GraphQL", "OCaml", "OpenDNS", "OpenGL", "OpenMP", "OpenSSH", "OpenSSL", "OpenStreetMap", "OpenTelemetry", "WebGL", "WebGL2", "WebGPU", "TensorFlow", "TrueType", "iOS", "macOS", "FreeBSD", "TeX", "LaTeX", "BibTeX", "BibLaTeX", "MinGW", "CamelCase"]`

---
**Affected lints:**
Expand Down Expand Up @@ -695,6 +695,7 @@ The minimum rust version that the project supports. Defaults to the `rust-versio
* [`manual_is_ascii_check`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_is_ascii_check)
* [`manual_let_else`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else)
* [`manual_non_exhaustive`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_non_exhaustive)
* [`manual_pattern_char_comparison`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_pattern_char_comparison)
* [`manual_range_contains`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_range_contains)
* [`manual_rem_euclid`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_rem_euclid)
* [`manual_retain`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_retain)
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/book/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ You can configure lint levels on the command line by adding
cargo clippy -- -Aclippy::style -Wclippy::double_neg -Dclippy::perf
```

For [CI] all warnings can be elevated to errors which will inturn fail
For [CI] all warnings can be elevated to errors which will in turn fail
the build and cause Clippy to exit with a code other than `0`.

```
Expand Down
3 changes: 2 additions & 1 deletion src/tools/clippy/clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use std::{cmp, env, fmt, fs, io};
#[rustfmt::skip]
const DEFAULT_DOC_VALID_IDENTS: &[&str] = &[
"KiB", "MiB", "GiB", "TiB", "PiB", "EiB",
"DevOps",
"DirectX",
"ECMAScript",
"GPLv2", "GPLv3",
Expand Down Expand Up @@ -265,7 +266,7 @@ define_Conf! {
///
/// Suppress lints whenever the suggested change would cause breakage for other crates.
(avoid_breaking_exported_api: bool = true),
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE, ITER_KV_MAP, MANUAL_C_STR_LITERALS, ASSIGNING_CLONES, LEGACY_NUMERIC_CONSTANTS, ALLOW_ATTRIBUTES, ALLOW_ATTRIBUTES_WITHOUT_REASON.
/// Lint: MANUAL_SPLIT_ONCE, MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, OPTION_MAP_UNWRAP_OR, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE, APPROX_CONSTANT, DEPRECATED_CFG_ATTR, INDEX_REFUTABLE_SLICE, MAP_CLONE, BORROW_AS_PTR, MANUAL_BITS, ERR_EXPECT, CAST_ABS_TO_UNSIGNED, UNINLINED_FORMAT_ARGS, MANUAL_CLAMP, MANUAL_LET_ELSE, UNCHECKED_DURATION_SUBTRACTION, COLLAPSIBLE_STR_REPLACE, SEEK_FROM_CURRENT, SEEK_REWIND, UNNECESSARY_LAZY_EVALUATIONS, TRANSMUTE_PTR_TO_REF, ALMOST_COMPLETE_RANGE, NEEDLESS_BORROW, DERIVABLE_IMPLS, MANUAL_IS_ASCII_CHECK, MANUAL_REM_EUCLID, MANUAL_RETAIN, TYPE_REPETITION_IN_BOUNDS, TUPLE_ARRAY_CONVERSIONS, MANUAL_TRY_FOLD, MANUAL_HASH_ONE, ITER_KV_MAP, MANUAL_C_STR_LITERALS, ASSIGNING_CLONES, LEGACY_NUMERIC_CONSTANTS, MANUAL_PATTERN_CHAR_COMPARISON, ALLOW_ATTRIBUTES, ALLOW_ATTRIBUTES_WITHOUT_REASON.
///
/// The minimum rust version that the project supports. Defaults to the `rust-version` field in `Cargo.toml`
#[default_text = ""]
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_config/src/msrvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ macro_rules! msrv_aliases {
msrv_aliases! {
1,81,0 { LINT_REASONS_STABILIZATION }
1,77,0 { C_STR_LITERALS }
1,76,0 { PTR_FROM_REF }
1,76,0 { PTR_FROM_REF, OPTION_RESULT_INSPECT }
1,71,0 { TUPLE_ARRAY_CONVERSIONS, BUILD_HASHER_HASH_ONE }
1,70,0 { OPTION_RESULT_IS_VARIANT_AND, BINARY_HEAP_RETAIN }
1,68,0 { PATH_MAIN_SEPARATOR_STR }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ declare_clippy_lint! {
/// `Arc<T>` is a thread-safe `Rc<T>` and guarantees that updates to the reference counter
/// use atomic operations. To send an `Arc<T>` across thread boundaries and
/// share ownership between multiple threads, `T` must be [both `Send` and `Sync`](https://doc.rust-lang.org/std/sync/struct.Arc.html#thread-safety),
/// so either `T` should be made `Send + Sync` or an `Rc` should be used instead of an `Arc`
/// so either `T` should be made `Send + Sync` or an `Rc` should be used instead of an `Arc`.
///
/// ### Example
/// ```no_run
Expand Down
78 changes: 77 additions & 1 deletion src/tools/clippy/clippy_lints/src/assigning_clones.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use clippy_config::msrvs::{self, Msrv};
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::macros::HirNode;
use clippy_utils::mir::{enclosing_mir, PossibleBorrowerMap};
use clippy_utils::sugg::Sugg;
use clippy_utils::{is_trait_method, local_is_initialized, path_to_local};
use rustc_errors::Applicability;
use rustc_hir::{self as hir, Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir;
use rustc_middle::ty::{self, Instance, Mutability};
use rustc_session::impl_lint_pass;
use rustc_span::def_id::DefId;
use rustc_span::symbol::sym;
use rustc_span::{ExpnKind, SyntaxContext};
use rustc_span::{ExpnKind, Span, SyntaxContext};

declare_clippy_lint! {
/// ### What it does
Expand Down Expand Up @@ -144,6 +146,7 @@ fn extract_call<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> Option<
};

Some(CallCandidate {
span: expr.span,
target,
kind,
method_def_id: resolved_method.def_id(),
Expand Down Expand Up @@ -215,13 +218,85 @@ fn is_ok_to_suggest<'tcx>(cx: &LateContext<'tcx>, lhs: &Expr<'tcx>, call: &CallC
return false;
};

if clone_source_borrows_from_dest(cx, lhs, call.span) {
return false;
}

// Now take a look if the impl block defines an implementation for the method that we're interested
// in. If not, then we're using a default implementation, which is not interesting, so we will
// not suggest the lint.
let implemented_fns = cx.tcx.impl_item_implementor_ids(impl_block);
implemented_fns.contains_key(&provided_fn.def_id)
}

/// Checks if the data being cloned borrows from the place that is being assigned to:
///
/// ```
/// let mut s = String::new();
/// let s2 = &s;
/// s = s2.to_owned();
/// ```
///
/// This cannot be written `s2.clone_into(&mut s)` because it has conflicting borrows.
fn clone_source_borrows_from_dest(cx: &LateContext<'_>, lhs: &Expr<'_>, call_span: Span) -> bool {
/// If this basic block only exists to drop a local as part of an assignment, returns its
/// successor. Otherwise returns the basic block that was passed in.
fn skip_drop_block(mir: &mir::Body<'_>, bb: mir::BasicBlock) -> mir::BasicBlock {
if let mir::TerminatorKind::Drop { target, .. } = mir.basic_blocks[bb].terminator().kind {
target
} else {
bb
}
}

let Some(mir) = enclosing_mir(cx.tcx, lhs.hir_id) else {
return false;
};
let PossibleBorrowerMap { map: borrow_map, .. } = PossibleBorrowerMap::new(cx, mir);

// The operation `dest = src.to_owned()` in MIR is split up across 3 blocks *if* the type has `Drop`
// code. For types that don't, the second basic block is simply skipped.
// For the doc example above that would be roughly:
//
// bb0:
// s2 = &s
// s_temp = ToOwned::to_owned(move s2) -> bb1
//
// bb1:
// drop(s) -> bb2 // drop the old string
//
// bb2:
// s = s_temp
for bb in mir.basic_blocks.iter() {
let terminator = bb.terminator();

// Look for the to_owned/clone call.
if terminator.source_info.span != call_span {
continue;
}

if let mir::TerminatorKind::Call { ref args, target: Some(assign_bb), .. } = terminator.kind
&& let [source] = &**args
&& let mir::Operand::Move(source) = &source.node
&& let assign_bb = skip_drop_block(mir, assign_bb)
// Skip any storage statements as they are just noise
&& let Some(assignment) = mir.basic_blocks[assign_bb].statements
.iter()
.find(|stmt| {
!matches!(stmt.kind, mir::StatementKind::StorageDead(_) | mir::StatementKind::StorageLive(_))
})
&& let mir::StatementKind::Assign(box (borrowed, _)) = &assignment.kind
&& let Some(borrowers) = borrow_map.get(&borrowed.local)
&& borrowers.contains(source.local)
{
return true;
}

return false;
}
false
}

fn suggest<'tcx>(
cx: &LateContext<'tcx>,
ctxt: SyntaxContext,
Expand Down Expand Up @@ -255,6 +330,7 @@ enum TargetTrait {

#[derive(Debug)]
struct CallCandidate<'tcx> {
span: Span,
target: TargetTrait,
kind: CallKind<'tcx>,
// DefId of the called method from an impl block that implements the target trait
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_lints/src/attrs/allow_attributes.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use super::ALLOW_ATTRIBUTES;
use clippy_utils::diagnostics::span_lint_and_sugg;
use clippy_utils::is_from_proc_macro;
use rustc_ast::{AttrStyle, Attribute};
use rustc_errors::Applicability;
use rustc_lint::{LateContext, LintContext};
use rustc_middle::lint::in_external_macro;
use super::ALLOW_ATTRIBUTES;

// Separate each crate's features.
pub fn check<'cx>(cx: &LateContext<'cx>, attr: &'cx Attribute) {
if !in_external_macro(cx.sess(), attr.span)
&& let AttrStyle::Outer = attr.style
&& let Some(ident) = attr.ident()
&& !is_from_proc_macro(cx, &attr)
&& !is_from_proc_macro(cx, attr)
{
span_lint_and_sugg(
cx,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub(super) fn check<'cx>(cx: &LateContext<'cx>, name: Symbol, items: &[NestedMet
}

// Check if the attribute is in an external macro and therefore out of the developer's control
if in_external_macro(cx.sess(), attr.span) || is_from_proc_macro(cx, &attr) {
if in_external_macro(cx.sess(), attr.span) || is_from_proc_macro(cx, attr) {
return;
}

Expand Down
16 changes: 7 additions & 9 deletions src/tools/clippy/clippy_lints/src/attrs/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! checks for attributes

mod allow_attributes_without_reason;
mod allow_attributes;
mod allow_attributes_without_reason;
mod blanket_clippy_restriction_lints;
mod deprecated_cfg_attr;
mod deprecated_semver;
Expand Down Expand Up @@ -505,6 +505,7 @@ pub struct Attributes {
}

impl_lint_pass!(Attributes => [
ALLOW_ATTRIBUTES,
ALLOW_ATTRIBUTES_WITHOUT_REASON,
INLINE_ALWAYS,
DEPRECATED_SEMVER,
Expand Down Expand Up @@ -534,15 +535,12 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
if is_lint_level(ident.name, attr.id) {
blanket_clippy_restriction_lints::check(cx, ident.name, items);
}
if matches!(ident.name, sym::allow) {
if self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) {
allow_attributes::check(cx, attr);
}
if matches!(ident.name, sym::allow) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) {
allow_attributes::check(cx, attr);
}
if matches!(ident.name, sym::allow | sym::expect) {
if self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION) {
allow_attributes_without_reason::check(cx, ident.name, items, attr);
}
if matches!(ident.name, sym::allow | sym::expect) && self.msrv.meets(msrvs::LINT_REASONS_STABILIZATION)
{
allow_attributes_without_reason::check(cx, ident.name, items, attr);
}
if items.is_empty() || !attr.has_name(sym::deprecated) {
return;
Expand Down
Loading
Loading