Skip to content

Update Clippy #114310

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 148 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
148 commits
Select commit Hold shift + click to select a range
648d1ae
lint on matches and pattern matching
y21 Jun 14, 2023
885ce61
New lint [`four_forward_slashes`]
Centri3 Jul 12, 2023
2e43d0c
Improve suggestion and add more tests
Centri3 Jul 13, 2023
c2aaa62
Fix ICE on None.unwrap_or_default()
syvb Jul 6, 2023
8d258c1
Add handling for None.unwrap_or(_else)
syvb Jul 6, 2023
fdb2e36
refactor(rustc_middle): Substs -> GenericArg
mdibaiee Jul 11, 2023
1f82f6d
[significant_drop_tightening] Fix #11160
c410-f3r Jul 14, 2023
f928d78
clippy-driver: Update bug URL to use the ice template
xFrednet Jul 16, 2023
eaccc6d
[`semicolon_if_nothing_returned`]: enable the autofix
sylvestre Jul 3, 2023
8ebdd62
[`semicolon_if_nothing_returned`]: Update the tests with the autofix
sylvestre Jul 4, 2023
9109533
Auto merge of #11168 - xFrednet:00000-free-ice-cream, r=flip1995
bors Jul 17, 2023
568ccf3
Auto merge of #11083 - sylvestre:autofix, r=dswij
bors Jul 17, 2023
d6d530f
Merge commit 'd9c24d1b1ee61f276e550b967409c9f155eac4e3' into clippyup
flip1995 Jul 17, 2023
2feb9a5
Another fix for incorrect_impls
flip1995 Jul 17, 2023
c388156
new lint: `format_collect`
y21 Jul 6, 2023
c83d58f
document that `write!`ing into a string never fails
y21 Jul 7, 2023
74a7704
Rewrite [`tuple_array_conversions`]
Centri3 Jul 17, 2023
36f84a6
Move tuple_array_conversions to nursery
Alexendoo Jul 17, 2023
54fa922
Auto merge of #11172 - Alexendoo:tuple-array-conversions-nursery, r=x…
bors Jul 17, 2023
d24f0d0
Don't lint `needless_return` in fns across a macro boundary
Alexendoo Jul 17, 2023
410456d
Auto merge of #11116 - y21:format_collect, r=Manishearth
bors Jul 17, 2023
3e0170b
Auto merge of #11173 - Alexendoo:needless-return-fn-macro, r=Manishearth
bors Jul 17, 2023
c26801e
[`redundant_pattern_matching`]: don't lint if if guards are present
y21 Jul 17, 2023
e7fd44f
add guard to suggestion instead of not linting
y21 Jul 17, 2023
d1e1dcb
Rename arg_iter to iter_instantiated
compiler-errors Jul 17, 2023
c13cb54
New lint `needless_return_with_try`
Centri3 Jun 26, 2023
747df85
Auto merge of #11171 - Centri3:tuple_array_conversions, r=llogiq
bors Jul 18, 2023
0d59d1d
Rename to `needless_return_with_question_mark`
Centri3 Jul 13, 2023
9f0cbfd
Auto merge of #11140 - Centri3:four_forward_slashes, r=blyxyas
bors Jul 18, 2023
75e1329
New lint [`error_impl_error`]
Centri3 Jul 4, 2023
f4b3bb1
Add `allow_private_error` config option
Centri3 Jul 7, 2023
9c6b17e
Remove `#![allow(unused)]` and `--crate-name` from new_lint tests
Alexendoo Jul 18, 2023
f539e1a
Remove unused flags from ui-cargo tests
Alexendoo Jul 18, 2023
8b0540b
Fix async functions handling for `needless_pass_by_ref_mut` lint
GuillaumeGomez Jul 18, 2023
5e9e462
Update `needless_pass_by_ref_mut` ui test
GuillaumeGomez Jul 18, 2023
d4a6634
Auto merge of #11175 - y21:issue11174, r=Manishearth
bors Jul 18, 2023
9d08502
New lint [`string_lit_chars_any`]
Centri3 Jun 30, 2023
ec57155
Auto merge of #11052 - Centri3:string_lit_chars_any, r=Jarcho
bors Jul 19, 2023
19b0e84
Remove the configuration option
Centri3 Jul 18, 2023
4c79d8a
new lint `iter_skip_zero`
Centri3 Jun 29, 2023
3dd6af9
Auto merge of #11046 - Centri3:iter_skip_zero, r=blyxyas
bors Jul 19, 2023
dcfc6a2
check for fully qualified paths in `unnecessary_cast`
Centri3 Jun 17, 2023
f583fd1
Fix `unwrap_or_else_default` false positive
smoelius Jul 9, 2023
0fa1fd3
Auto merge of #11183 - Alexendoo:new-lint-template, r=xFrednet
bors Jul 19, 2023
7a34143
Auto merge of #11135 - smoelius:unwrap_or_else_default-fp, r=Centri3
bors Jul 19, 2023
0b63e95
Auto merge of #10949 - y21:issue8010, r=Alexendoo
bors Jul 19, 2023
cbca8f9
On nightly, dump ICE backtraces to disk
estebank Mar 3, 2023
84c4112
Merge `unwrap_or_else_default.rs` into `or_fun_call.rs`
smoelius Jul 20, 2023
e27977b
Rename `unwrap_or_else_default` to `unwrap_or_default`
smoelius Jul 20, 2023
d71fbb9
Auto merge of #11107 - Centri3:error_impl_error, r=Jarcho
bors Jul 20, 2023
d764a0e
Auto merge of #11161 - c410-f3r:let-chain, r=dswij
bors Jul 20, 2023
579f1ec
Add Centri3 and blyxyas to the reviewer rotation
flip1995 Jul 20, 2023
15b68c2
Extract the logic for if a snippet equals a type
Centri3 Jun 29, 2023
0f31fff
Auto merge of #11194 - flip1995:new-reviewers, r=xFrednet
bors Jul 20, 2023
fbe292e
Auto merge of #10971 - Centri3:unnecessary_cast_fully_qual_fix, r=dswij
bors Jul 20, 2023
5a6c4d7
XSimplifiedType to SimplifiedType::X
lcnr Jul 18, 2023
f743fec
fix: false positive for `option_env!` in ifs
thvdveld Jul 20, 2023
fca1f9a
Auto merge of #11106 - syvb:literal_unwrap_ice, r=dswij
bors Jul 20, 2023
f0a16bb
[significant_drop_tightening] Fix #11189
c410-f3r Jul 20, 2023
7c5095c
Auto merge of #11195 - thvdveld:fix-option-env-ifs-equal-cond, r=Mani…
bors Jul 20, 2023
541d0c8
[`slow_vector_initialization`]: lint `Vec::new()`
y21 Jul 20, 2023
a4c367d
Allow `Self::cmp(self, other)` as a correct impl
Centri3 Jul 19, 2023
ee8a429
Auto merge of #11188 - Centri3:#11178, r=blyxyas
bors Jul 20, 2023
37b8366
[`unused_async`]: don't lint if paths reference async fn without call
y21 Jul 20, 2023
f3f7f63
[`inherent_to_string`]: Don't lint `unsafe` or `extern` fns
Centri3 Jul 21, 2023
d2c9047
Auto merge of #11205 - Centri3:#11201, r=Manishearth
bors Jul 21, 2023
9cf1509
New lint `absolute_paths`
Centri3 Jun 22, 2023
58df1e6
Auto merge of #11003 - Centri3:absolute_path, r=Alexendoo,blyxyas
bors Jul 21, 2023
008ba2b
new lint: redundant_local
max-niederman Jun 4, 2023
a44dcf8
Auto merge of #10885 - max-niederman:redundant_local, r=Centri3
bors Jul 22, 2023
da93ee8
Make `comparison_to_empty` work on `if let`/`let` chains
Centri3 Jun 26, 2023
ae5d391
Remove `LetChain`
Centri3 Jul 22, 2023
51b5772
new lint `redundant_guards`
Centri3 Jun 14, 2023
df3804a
Auto merge of #10955 - Centri3:redundant_matches_guard, r=Alexendoo,b…
bors Jul 22, 2023
482d5fa
replace HashMap with Vec, use span_lint_hir_and_then
y21 Jul 22, 2023
99202a0
Start addressing review comments
smoelius Jul 22, 2023
ea21ed7
Auto merge of #11196 - c410-f3r:let-chain, r=xFrednet
bors Jul 22, 2023
e8403a8
Auto merge of #11200 - y21:issue9695, r=Jarcho
bors Jul 22, 2023
356768b
Auto merge of #11029 - Centri3:empty_slice, r=Jarcho
bors Jul 23, 2023
55dd8a9
Refactor `dereference.rs`
Jarcho Jul 5, 2023
43577d5
Auto merge of #11184 - GuillaumeGomez:needless_pass_by_ref_mut-async,…
bors Jul 23, 2023
e975d05
check that the types are equal in `SpanlessEq::eq_expr`
y21 Jul 23, 2023
30d06a8
ptr_arg should ignore extern functions
mrnossiom Jul 23, 2023
a4e64ff
Auto merge of #11166 - Jarcho:expr_use, r=Centri3
bors Jul 23, 2023
5877504
Auto merge of #11214 - y21:issue11213, r=Jarcho
bors Jul 23, 2023
e4923c2
Auto merge of #10120 - smoelius:or_insert_with, r=blyxyas
bors Jul 23, 2023
7b8598d
ptr lint: check_mut_from_ref is checked independently of the function…
mrnossiom Jul 23, 2023
a447725
Auto merge of #11215 - MrNossiom:master, r=Jarcho
bors Jul 24, 2023
8298213
changelog: [`min_ident_chars`]: don't lint const generics
mrnossiom Jul 24, 2023
31f3769
Auto merge of #11031 - Centri3:needless_return, r=giraffate
bors Jul 24, 2023
5c26e82
Remove Gha status emitter in compile-test
Alexendoo Jul 23, 2023
867e0ec
Auto merge of #11218 - MrNossiom:master, r=Manishearth
bors Jul 24, 2023
ef482d1
Do not lint if used as a `fn`-like argument
Centri3 Jul 21, 2023
43b0e11
Auto merge of #11207 - Centri3:#11182, r=giraffate
bors Jul 25, 2023
d09c8a9
Auto merge of #11221 - Alexendoo:ui-test-text, r=flip1995
bors Jul 25, 2023
a147372
clippy: `env!` invocations can't be b"" literals
davidtwco Jul 25, 2023
2b16c37
bless more
RalfJung Jul 24, 2023
3fb714d
Use a builder instead of boolean/option arguments
oli-obk Jul 25, 2023
15de3dd
Add a note if the function is behind a cfg
GuillaumeGomez Jul 25, 2023
f20a174
Make everything builtin!
compiler-errors Jul 24, 2023
1fe2762
use a dedicated enum for vec initializer
y21 Jul 25, 2023
04b710b
Use libtest errors check to better enforce UI testing
GuillaumeGomez Jul 25, 2023
1c9772c
Move `inherits_cfg` function into clippy_utils
GuillaumeGomez Jul 25, 2023
c0484b7
simplify looking for `Vec::with_capacity` exprs
y21 Jul 25, 2023
2cc44cf
Auto merge of #113393 - compiler-errors:next-solver-unsize-rhs, r=lcnr
bors Jul 25, 2023
c3079a9
Fix integration tests
flip1995 Jun 17, 2023
0f3a149
Rollup merge of #114014 - davidtwco:issue-114010-env-rawstr, r=cjgillot
matthiaskrgr Jul 25, 2023
70c5798
Auto merge of #11198 - y21:issue10938, r=Centri3
bors Jul 25, 2023
12b63f5
ci: integration tests: print clippy run output and set LD_LIBRARY_PAT…
matthiaskrgr Jul 25, 2023
61e0aac
Auto merge of #114063 - matthiaskrgr:rollup-c90czu6, r=matthiaskrgr
bors Jul 25, 2023
2153c0f
Auto merge of #11226 - GuillaumeGomez:needless-ref-mut-cfg, r=llogiq
bors Jul 25, 2023
5976fda
Add *no merge policy* note via rustbot
xFrednet Jul 25, 2023
978b1da
New lint [`filter_map_bool_then`]
Centri3 Jul 6, 2023
3235d9d
Only lint `Copy` types
Centri3 Jul 16, 2023
90947e9
[`arc_with_non_send_sync`]: Check if it's macro-generated
Centri3 Jul 25, 2023
0404b6b
Add `sym::iter_mut` + `sym::as_mut_ptr`
blyxyas Jul 25, 2023
0fec99f
Auto merge of #11115 - Centri3:filter_map_bool_then, r=Jarcho
bors Jul 26, 2023
0d0dbae
Auto merge of #11233 - Centri3:#11232, r=Jarcho
bors Jul 26, 2023
80641c0
Auto merge of #11231 - xFrednet:00000-merge-no-merge, r=flip1995
bors Jul 26, 2023
fc13bf8
Auto merge of #11225 - matthiaskrgr:fix_integration_tests2, r=flip1995
bors Jul 26, 2023
ed2ec81
Auto merge of #114054 - oli-obk:cleanups, r=estebank
bors Jul 26, 2023
01b9f9d
ci: test that we fail CI if we don't find clippy panicking
matthiaskrgr Jul 25, 2023
d446378
Auto merge of #11228 - matthiaskrgr:fix_integration_tests2__with_test…
bors Jul 26, 2023
4e1db44
Now `option_env_unwrap` warns even if a variable isn't set at compile…
blyxyas May 6, 2023
8615595
Rollup merge of #114070 - blyxyas:iter_mut_symbol, r=oli-obk
matthiaskrgr Jul 26, 2023
6ca6be6
Unite bless environment variables under `RUSTC_BLESS`
tgross35 Jul 3, 2023
3bfccac
Add comments + Very minor Refactor
blyxyas Jul 26, 2023
42d3370
Auto merge of #113298 - tgross35:update-bless-envs, r=oli-obk
bors Jul 27, 2023
136339f
new lint: [`readonly_write_lock`]
y21 Jul 22, 2023
205a374
make lint description more consistent (writer/reader -> write/read)
y21 Jul 27, 2023
295bdc0
Auto merge of #10759 - blyxyas:unset_opt_env_unwrap, r=flip1995
bors Jul 27, 2023
5e88003
pattern match on local usage slice to avoid ICE
y21 Jul 28, 2023
d3c5b48
Auto merge of #11210 - y21:readonly_write_lock, r=giraffate
bors Jul 28, 2023
3d60241
Merge remote-tracking branch 'upstream/master' into rustup
flip1995 Jul 28, 2023
65c5afd
Bump nightly version -> 2023-07-28
flip1995 Jul 28, 2023
2973096
Auto merge of #11250 - flip1995:rustup, r=flip1995
bors Jul 28, 2023
71cc39e
Add debug assertions to `implements_trait`
Jarcho Jul 30, 2023
4d80a2e
Rework `redundant_closure`
Jarcho Jul 30, 2023
7423c27
Don't lint redundant closure for any function call inserted by the co…
Jarcho Jun 9, 2023
4c2f460
Auto merge of #8685 - Jarcho:redundant_closure_fixes, r=llogiq
bors Jul 30, 2023
caf6014
Resolve type aliases in `type_certainty`
Jarcho Jul 30, 2023
c0bdb3d
Auto merge of #11258 - Jarcho:ice_11256, r=Centri3
bors Jul 30, 2023
008746c
[`unnecessary_find_map`]: look for then_some
y21 Jul 30, 2023
be6a103
add more tests to unnecessary_find_map and unnecessary_filter_map
y21 Jul 30, 2023
35d434d
[arithmetic_side_effects] Fix #11262
c410-f3r Jul 30, 2023
2ab1241
Auto merge of #11261 - y21:issue11260, r=blyxyas
bors Jul 30, 2023
5436dba
Auto merge of #11263 - c410-f3r:let-chain, r=Centri3
bors Jul 30, 2023
53f09d9
Merge commit '5436dba826191964ac1d0dab534b7eb6d4c878f6' into clippyup
flip1995 Jul 31, 2023
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
29 changes: 15 additions & 14 deletions src/tools/clippy/.github/workflows/clippy_bors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,14 @@ jobs:
- name: Extract Binaries
run: |
DIR=$CARGO_TARGET_DIR/debug
rm $DIR/deps/integration-*.d
mv $DIR/deps/integration-* $DIR/integration
find $DIR/deps/integration-* -executable ! -type d | xargs -I {} mv {} $DIR/integration
find $DIR ! -executable -o -type d ! -path $DIR | xargs rm -rf
rm -rf $CARGO_TARGET_DIR/release

- name: Upload Binaries
uses: actions/upload-artifact@v1
uses: actions/upload-artifact@v3
with:
name: target
path: target
name: binaries
path: target/debug

integration:
needs: integration_build
Expand All @@ -206,22 +204,20 @@ jobs:
matrix:
integration:
- 'rust-lang/cargo'
# FIXME: re-enable once fmt_macros is renamed in RLS
# - 'rust-lang/rls'
- 'rust-lang/chalk'
- 'rust-lang/rustfmt'
- 'Marwes/combine'
- 'Geal/nom'
- 'rust-lang/stdarch'
- 'serde-rs/serde'
# FIXME: chrono currently cannot be compiled with `--all-targets`
# - 'chronotope/chrono'
- 'chronotope/chrono'
- 'hyperium/hyper'
- 'rust-random/rand'
- 'rust-lang/futures-rs'
- 'rust-itertools/itertools'
- 'rust-lang-nursery/failure'
- 'rust-lang/log'
- 'matthiaskrgr/clippy_ci_panic_test'

runs-on: ubuntu-latest

Expand All @@ -237,12 +233,17 @@ jobs:
- name: Install toolchain
run: rustup show active-toolchain

- name: Set LD_LIBRARY_PATH
run: |
SYSROOT=$(rustc --print sysroot)
echo "LD_LIBRARY_PATH=${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}" >> $GITHUB_ENV

# Download
- name: Download target dir
uses: actions/download-artifact@v1
uses: actions/download-artifact@v3
with:
name: target
path: target
name: binaries
path: target/debug

- name: Make Binaries Executable
run: chmod +x $CARGO_TARGET_DIR/debug/*
Expand All @@ -251,7 +252,7 @@ jobs:
- name: Test ${{ matrix.integration }}
run: |
RUSTUP_TOOLCHAIN="$(rustup show active-toolchain | grep -o -E "nightly-[0-9]{4}-[0-9]{2}-[0-9]{2}")" \
$CARGO_TARGET_DIR/debug/integration
$CARGO_TARGET_DIR/debug/integration --show-output
env:
INTEGRATION: ${{ matrix.integration }}

Expand Down
14 changes: 14 additions & 0 deletions src/tools/clippy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4680,6 +4680,7 @@ Released 2018-09-13

<!-- lint disable no-unused-definitions -->
<!-- begin autogenerated links to lint list -->
[`absolute_paths`]: https://rust-lang.github.io/rust-clippy/master/index.html#absolute_paths
[`absurd_extreme_comparisons`]: https://rust-lang.github.io/rust-clippy/master/index.html#absurd_extreme_comparisons
[`alloc_instead_of_core`]: https://rust-lang.github.io/rust-clippy/master/index.html#alloc_instead_of_core
[`allow_attributes`]: https://rust-lang.github.io/rust-clippy/master/index.html#allow_attributes
Expand Down Expand Up @@ -4819,6 +4820,7 @@ Released 2018-09-13
[`equatable_if_let`]: https://rust-lang.github.io/rust-clippy/master/index.html#equatable_if_let
[`erasing_op`]: https://rust-lang.github.io/rust-clippy/master/index.html#erasing_op
[`err_expect`]: https://rust-lang.github.io/rust-clippy/master/index.html#err_expect
[`error_impl_error`]: https://rust-lang.github.io/rust-clippy/master/index.html#error_impl_error
[`eval_order_dependence`]: https://rust-lang.github.io/rust-clippy/master/index.html#eval_order_dependence
[`excessive_nesting`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_nesting
[`excessive_precision`]: https://rust-lang.github.io/rust-clippy/master/index.html#excessive_precision
Expand All @@ -4842,6 +4844,7 @@ Released 2018-09-13
[`field_reassign_with_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#field_reassign_with_default
[`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
[`filter_map_identity`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_identity
[`filter_map_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_map_next
[`filter_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#filter_next
Expand All @@ -4865,8 +4868,10 @@ Released 2018-09-13
[`forget_copy`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_copy
[`forget_non_drop`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_non_drop
[`forget_ref`]: https://rust-lang.github.io/rust-clippy/master/index.html#forget_ref
[`format_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#format_collect
[`format_in_format_args`]: https://rust-lang.github.io/rust-clippy/master/index.html#format_in_format_args
[`format_push_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#format_push_string
[`four_forward_slashes`]: https://rust-lang.github.io/rust-clippy/master/index.html#four_forward_slashes
[`from_iter_instead_of_collect`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_iter_instead_of_collect
[`from_over_into`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_over_into
[`from_raw_with_void_ptr`]: https://rust-lang.github.io/rust-clippy/master/index.html#from_raw_with_void_ptr
Expand Down Expand Up @@ -4937,6 +4942,7 @@ Released 2018-09-13
[`iter_on_single_items`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_on_single_items
[`iter_overeager_cloned`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_overeager_cloned
[`iter_skip_next`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_next
[`iter_skip_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_skip_zero
[`iter_with_drain`]: https://rust-lang.github.io/rust-clippy/master/index.html#iter_with_drain
[`iterator_step_by_zero`]: https://rust-lang.github.io/rust-clippy/master/index.html#iterator_step_by_zero
[`just_underscores_and_digits`]: https://rust-lang.github.io/rust-clippy/master/index.html#just_underscores_and_digits
Expand Down Expand Up @@ -5092,6 +5098,7 @@ Released 2018-09-13
[`needless_raw_string_hashes`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_string_hashes
[`needless_raw_strings`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_raw_strings
[`needless_return`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_return
[`needless_return_with_question_mark`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_return_with_question_mark
[`needless_splitn`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_splitn
[`needless_update`]: https://rust-lang.github.io/rust-clippy/master/index.html#needless_update
[`neg_cmp_op_on_partial_ord`]: https://rust-lang.github.io/rust-clippy/master/index.html#neg_cmp_op_on_partial_ord
Expand Down Expand Up @@ -5174,6 +5181,7 @@ Released 2018-09-13
[`rc_mutex`]: https://rust-lang.github.io/rust-clippy/master/index.html#rc_mutex
[`read_line_without_trim`]: https://rust-lang.github.io/rust-clippy/master/index.html#read_line_without_trim
[`read_zero_byte_vec`]: https://rust-lang.github.io/rust-clippy/master/index.html#read_zero_byte_vec
[`readonly_write_lock`]: https://rust-lang.github.io/rust-clippy/master/index.html#readonly_write_lock
[`recursive_format_impl`]: https://rust-lang.github.io/rust-clippy/master/index.html#recursive_format_impl
[`redundant_allocation`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_allocation
[`redundant_async_block`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_async_block
Expand All @@ -5185,6 +5193,8 @@ Released 2018-09-13
[`redundant_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_else
[`redundant_feature_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_feature_names
[`redundant_field_names`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_field_names
[`redundant_guards`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_guards
[`redundant_locals`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_locals
[`redundant_pattern`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern
[`redundant_pattern_matching`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching
[`redundant_pub_crate`]: https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pub_crate
Expand Down Expand Up @@ -5254,6 +5264,7 @@ Released 2018-09-13
[`string_extend_chars`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_extend_chars
[`string_from_utf8_as_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_from_utf8_as_bytes
[`string_lit_as_bytes`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_lit_as_bytes
[`string_lit_chars_any`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_lit_chars_any
[`string_slice`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_slice
[`string_to_string`]: https://rust-lang.github.io/rust-clippy/master/index.html#string_to_string
[`strlen_on_c_strings`]: https://rust-lang.github.io/rust-clippy/master/index.html#strlen_on_c_strings
Expand Down Expand Up @@ -5362,6 +5373,7 @@ Released 2018-09-13
[`unused_unit`]: https://rust-lang.github.io/rust-clippy/master/index.html#unused_unit
[`unusual_byte_groupings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unusual_byte_groupings
[`unwrap_in_result`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_in_result
[`unwrap_or_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_or_default
[`unwrap_or_else_default`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_or_else_default
[`unwrap_used`]: https://rust-lang.github.io/rust-clippy/master/index.html#unwrap_used
[`upper_case_acronyms`]: https://rust-lang.github.io/rust-clippy/master/index.html#upper_case_acronyms
Expand Down Expand Up @@ -5462,4 +5474,6 @@ Released 2018-09-13
[`accept-comment-above-statement`]: https://doc.rust-lang.org/clippy/lint_configuration.html#accept-comment-above-statement
[`accept-comment-above-attributes`]: https://doc.rust-lang.org/clippy/lint_configuration.html#accept-comment-above-attributes
[`allow-one-hash-in-raw-strings`]: https://doc.rust-lang.org/clippy/lint_configuration.html#allow-one-hash-in-raw-strings
[`absolute-paths-max-segments`]: https://doc.rust-lang.org/clippy/lint_configuration.html#absolute-paths-max-segments
[`absolute-paths-allowed-crates`]: https://doc.rust-lang.org/clippy/lint_configuration.html#absolute-paths-allowed-crates
<!-- end autogenerated links to configuration documentation -->
21 changes: 21 additions & 0 deletions src/tools/clippy/book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,3 +730,24 @@ Whether to allow `r#""#` when `r""` can be used
* [`unnecessary_raw_string_hashes`](https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_raw_string_hashes)


## `absolute-paths-max-segments`
The maximum number of segments a path can have before being linted, anything above this will
be linted.

**Default Value:** `2` (`u64`)

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


## `absolute-paths-allowed-crates`
Which crates to allow absolute paths from

**Default Value:** `{}` (`rustc_data_structures::fx::FxHashSet<String>`)

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


2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn clippy_project_root() -> PathBuf {
for path in current_dir.ancestors() {
let result = std::fs::read_to_string(path.join("Cargo.toml"));
if let Err(err) = &result {
if err.kind() == std::io::ErrorKind::NotFound {
if err.kind() == io::ErrorKind::NotFound {
continue;
}
}
Expand Down
18 changes: 5 additions & 13 deletions src/tools/clippy/clippy_dev/src/new_lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {

path.push("src");
fs::create_dir(&path)?;
let header = format!("//@compile-flags: --crate-name={lint_name}");
write_file(path.join("main.rs"), get_test_file_contents(lint_name, Some(&header)))?;
write_file(path.join("main.rs"), get_test_file_contents(lint_name))?;

Ok(())
}
Expand All @@ -113,7 +112,7 @@ fn create_test(lint: &LintData<'_>) -> io::Result<()> {
println!("Generated test directories: `{relative_test_dir}/pass`, `{relative_test_dir}/fail`");
} else {
let test_path = format!("tests/ui/{}.rs", lint.name);
let test_contents = get_test_file_contents(lint.name, None);
let test_contents = get_test_file_contents(lint.name);
write_file(lint.project_root.join(&test_path), test_contents)?;

println!("Generated test file: `{test_path}`");
Expand Down Expand Up @@ -195,23 +194,16 @@ pub(crate) fn get_stabilization_version() -> String {
parse_manifest(&contents).expect("Unable to find package version in `Cargo.toml`")
}

fn get_test_file_contents(lint_name: &str, header_commands: Option<&str>) -> String {
let mut contents = formatdoc!(
fn get_test_file_contents(lint_name: &str) -> String {
formatdoc!(
r#"
#![allow(unused)]
#![warn(clippy::{lint_name})]

fn main() {{
// test code goes here
}}
"#
);

if let Some(header) = header_commands {
contents = format!("{header}\n{contents}");
}

contents
)
}

fn get_manifest_contents(lint_name: &str, hint: &str) -> String {
Expand Down
100 changes: 100 additions & 0 deletions src/tools/clippy/clippy_lints/src/absolute_paths.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
use clippy_utils::diagnostics::span_lint;
use clippy_utils::source::snippet_opt;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, CRATE_DEF_INDEX};
use rustc_hir::{HirId, ItemKind, Node, Path};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::symbol::kw;

declare_clippy_lint! {
/// ### What it does
/// Checks for usage of items through absolute paths, like `std::env::current_dir`.
///
/// ### Why is this bad?
/// Many codebases have their own style when it comes to importing, but one that is seldom used
/// is using absolute paths *everywhere*. This is generally considered unidiomatic, and you
/// should add a `use` statement.
///
/// The default maximum segments (2) is pretty strict, you may want to increase this in
/// `clippy.toml`.
///
/// Note: One exception to this is code from macro expansion - this does not lint such cases, as
/// using absolute paths is the proper way of referencing items in one.
///
/// ### Example
/// ```rust
/// let x = std::f64::consts::PI;
/// ```
/// Use any of the below instead, or anything else:
/// ```rust
/// use std::f64;
/// use std::f64::consts;
/// use std::f64::consts::PI;
/// let x = f64::consts::PI;
/// let x = consts::PI;
/// let x = PI;
/// use std::f64::consts as f64_consts;
/// let x = f64_consts::PI;
/// ```
#[clippy::version = "1.73.0"]
pub ABSOLUTE_PATHS,
restriction,
"checks for usage of an item without a `use` statement"
}
impl_lint_pass!(AbsolutePaths => [ABSOLUTE_PATHS]);

pub struct AbsolutePaths {
pub absolute_paths_max_segments: u64,
pub absolute_paths_allowed_crates: FxHashSet<String>,
}

impl LateLintPass<'_> for AbsolutePaths {
// We should only lint `QPath::Resolved`s, but since `Path` is only used in `Resolved` and `UsePath`
// we don't need to use a visitor or anything as we can just check if the `Node` for `hir_id` isn't
// a `Use`
#[expect(clippy::cast_possible_truncation)]
fn check_path(&mut self, cx: &LateContext<'_>, path: &Path<'_>, hir_id: HirId) {
let Self {
absolute_paths_max_segments,
absolute_paths_allowed_crates,
} = self;

if !path.span.from_expansion()
&& let Some(node) = cx.tcx.hir().find(hir_id)
&& !matches!(node, Node::Item(item) if matches!(item.kind, ItemKind::Use(_, _)))
&& let [first, rest @ ..] = path.segments
// Handle `::std`
&& let (segment, len) = if first.ident.name == kw::PathRoot {
// Indexing is fine as `PathRoot` must be followed by another segment. `len() - 1`
// is fine here for the same reason
(&rest[0], path.segments.len() - 1)
} else {
(first, path.segments.len())
}
&& len > *absolute_paths_max_segments as usize
&& let Some(segment_snippet) = snippet_opt(cx, segment.ident.span)
&& segment_snippet == segment.ident.as_str()
{
let is_abs_external =
matches!(segment.res, Res::Def(DefKind::Mod, DefId { index, .. }) if index == CRATE_DEF_INDEX);
let is_abs_crate = segment.ident.name == kw::Crate;

if is_abs_external && absolute_paths_allowed_crates.contains(segment.ident.name.as_str())
|| is_abs_crate && absolute_paths_allowed_crates.contains("crate")
{
return;
}

if is_abs_external || is_abs_crate {
span_lint(
cx,
ABSOLUTE_PATHS,
path.span,
"consider bringing this path into scope with the `use` keyword",
);
}
}
}
}
12 changes: 7 additions & 5 deletions src/tools/clippy/clippy_lints/src/arc_with_non_send_sync.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clippy_utils::diagnostics::span_lint_and_then;
use clippy_utils::last_path_segment;
use clippy_utils::ty::{implements_trait, is_type_diagnostic_item};
use clippy_utils::{is_from_proc_macro, last_path_segment};
use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
Expand Down Expand Up @@ -38,10 +38,11 @@ declare_clippy_lint! {
}
declare_lint_pass!(ArcWithNonSendSync => [ARC_WITH_NON_SEND_SYNC]);

impl LateLintPass<'_> for ArcWithNonSendSync {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
let ty = cx.typeck_results().expr_ty(expr);
if is_type_diagnostic_item(cx, ty, sym::Arc)
impl<'tcx> LateLintPass<'tcx> for ArcWithNonSendSync {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if !expr.span.from_expansion()
&& let ty = cx.typeck_results().expr_ty(expr)
&& is_type_diagnostic_item(cx, ty, sym::Arc)
&& let ExprKind::Call(func, [arg]) = expr.kind
&& let ExprKind::Path(func_path) = func.kind
&& last_path_segment(&func_path).ident.name == sym::new
Expand All @@ -54,6 +55,7 @@ impl LateLintPass<'_> for ArcWithNonSendSync {
&& let Some(sync) = cx.tcx.lang_items().sync_trait()
&& let [is_send, is_sync] = [send, sync].map(|id| implements_trait(cx, arg_ty, id, &[]))
&& !(is_send && is_sync)
&& !is_from_proc_macro(cx, expr)
{
span_lint_and_then(
cx,
Expand Down
8 changes: 8 additions & 0 deletions src/tools/clippy/clippy_lints/src/casts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,14 @@ declare_clippy_lint! {
/// ### Why is this bad?
/// It's just unnecessary.
///
/// ### Known problems
/// When the expression on the left is a function call, the lint considers the return type to be
/// a type alias if it's aliased through a `use` statement
/// (like `use std::io::Result as IoResult`). It will not lint such cases.
///
/// This check is also rather primitive. It will only work on primitive types without any
/// intermediate references, raw pointers and trait objects may or may not work.
///
/// ### Example
/// ```rust
/// let _ = 2i32 as i32;
Expand Down
Loading