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

Clippy subtree update #138761

merged 149 commits into from
Mar 21, 2025

Conversation

flip1995
Copy link
Member

r? @Manishearth

Cargo.lock update is because of the ui_test dependency bump in Clippy.

notriddle and others added 30 commits February 4, 2025 13:07
It can make sense to `collect()` an iterator and then immediately
iterate over it if the iterator has special methods that you need.
For example, the Map iterator doesn't implement Clone, but the
collection iterator might. Or the collection iterator might
support slicing.
The `comparison_chain` lint might suggest code which seems less natural
to beginners.

[Discussion](https://rust-lang.zulipchat.com/#narrow/channel/257328-clippy/topic/demote.20some.20lints.20to.20.60pedantic.60)
`AssocOp::AssignOp` contains a `BinOpToken`. `ExprKind::AssignOp`
contains a `BinOpKind`. Given that `AssocOp` is basically a cut-down
version of `ExprKind`, it makes sense to make `AssocOp` more like
`ExprKind`. Especially given that `AssocOp` and `BinOpKind` use semantic
operation names (e.g. `Mul`, `Div`), but `BinOpToken` uses syntactic
names (e.g. `Star`, `Slash`).

This results in more concise code, and removes the need for various
conversions. (Note that the removed functions `hirbinop2assignop` and
`astbinop2assignop` are semantically identical, because `hir::BinOp` is
just a synonum for `ast::BinOp`!)

The only downside to this is that it allows the possibility of some
nonsensical combinations, such as `AssocOp::AssignOp(BinOpKind::Lt)`.
But `ExprKind::AssignOp` already has that problem. The problem can be
fixed for both types in the future with some effort, by introducing an
`AssignOpKind` type.
It mirrors `ExprKind::Binary`, and contains a `BinOpKind`. This makes
`AssocOp` more like `ExprKind`. Note that the variants removed from
`AssocOp` are all named differently to `BinOpToken`, e.g. `Multiply`
instead of `Mul`, so that's an inconsistency removed.

The commit adds `precedence` and `fixity` methods to `BinOpKind`, and
calls them from the corresponding methods in `AssocOp`. This avoids the
need to create an `AssocOp` from a `BinOpKind` in a bunch of places, and
`AssocOp::from_ast_binop` is removed.

`AssocOp::to_ast_binop` is also no longer needed.

Overall things are shorter and nicer.
It makes `AssocOp` more similar to `ExprKind` and makes things a little
simpler. And the semantic names make more sense here than the syntactic
names.
To match `ExprKind::Cast`, and because a semantic name makes more sense
here than a syntactic name.
The `has_eligible_receiver()` function had been adapted *a minima* when
the `sym::ControlFlow` diagnostic item has been added to rustc. This
refactors the function content to make its meaning clearer.
- Remove the `Option` from the result type, as `None` is never returned.
- Document the difference from the `BindingMode` in `PatKind::Binding`.
…r=oli-obk

Clean up TypeckResults::extract_binding_mode

- Remove the `Option` from the result type, as `None` is never returned.
- Document the difference from the `BindingMode` in `PatKind::Binding`.
The lint for function calls was previously restricted to functions taking
exactly one argument. This was not documented.

Generalizing the lint to an arbitrary number of arguments in the function
call requires special casing some macro expansions from the standard
library. Macros such as `panic!()` or `assert_eq!()` exist since Rust
1.0.0, but modern stdlib expand those macros into calls to functions
introduced in later Rust versions. While it is desirable to lint code
inside macros, using MSRV-incompatible functions coming from `core`
in macro expansions has been special-cased to not trigger this lint.

Also, code coming from compiler desugaring may contain function calls
(for example, `a..=b` is now desugared into `RangeInclusive::new(a,
b)`. Those should not be linted either as the compiler is allowed to
use unstable function calls.
This test only makes sense to run in the Clippy repo

In the Rust repo the name of the host_compiler is dev, not nightly
Side-effect free expressions are eligible to these lints,
whereas previously only local variables were checked.
…#14310)

changelog: [`implicit_saturating_sub`, `inverted_saturating_sub`]:
extend lints from local variables to side-effect free expressions

Noticed when rust-lang#14308 introduced an implicit `saturating_sub` operation
and didn't get tagged.
Using `#[allow]` will also apply to child HIR nodes, while `#[expect]`
will ensure that the proper HIR node has been used for positioning the
lint.
Using `#[allow]` will also apply to child HIR nodes, while `#[expect]`
will ensure that the proper HIR node has been used for positioning the
lint.

changelog: none
fix typo

change replacement character in example, remove extraneous space from suggested change

add additional testcases; check doc comment not from expansion

do not lint on macros, add more testcases

fix wording, remove commented out code, add additonal testcase

uibless

fix doc comments, use optional snippets

Remove unneeded additional space
blyxyas and others added 14 commits March 18, 2025 12:29
I love this project but I (again) don't have the time nor energy at the
moment. Will go through my current assignments over time and still
review occasionally.

PS: sorry about the branch on upstream!
changelog: none
…t-lang#14420)

Commit efe3fe9 removed the ability for
`single_match` and `single_match_else` to trigger if comments were
present outside of the arms, as those comments would be lost while
rewriting the `match` expression.

This reinstates the lint, but prevents the suggestion from being applied
automatically in the presence of comments by using the `MaybeIncorrect`
applicability. Also, a note is added to the lint message to warn the
user about the need to preserve the comments if acting upon the
suggestion.

changelog: [`single_match`, `single_match_else`]: reinstate lint when
comments are inside the `match` but do not autofix the code

Fix rust-lang#14418
TLDR
```diff
- ///    01234
+ ///     01234
     12345
```

Sometimes, in doc comments, there are 3 spaces + 1 instead of 4 spaces +
1.
To make it coherent with the rest of the clippy codebase, I `fd -t f -X
sed -E -i 's,///\s{4}(\S),/// \1,g'` and manually verified and fixed the
relevant part of code that had bad indentation.

### Example

```rs
/// fn a() {
///    01234
/// }
```
Becomes
```rs
/// fn a() {
///     01234
/// }
```

changelog: none
)

fixes rust-lang#13964

The lint `option_map_unwrap_or` used to have a similar issue in rust-lang#10579,
so I borrowed its solution to fix this one.

changelog: [`option_if_let_else`]: fix FP when value partially moved
changelog: [`question_mark`]: Now respects the [`msrv`] configuration
…less_late_init` (rust-lang#14169)

fixes rust-lang#9895

changelog: [`needless_late_init`]: correct suggestion when assignments
have enclosing parentheses
The applicability of `never_loop` is currently set to `Unspecified`, but
if the loop block does not contain `break` or `continue`, it can be
`MachineApplicable`.

changelog: [`never_loop`]: the applicability is now `MachineApplicable`
when the loop block contains neither `break` nor `continue`
r? @ghost

changelog: none
)

Closes rust-lang#14020
Closes rust-lang#14290
Closes rust-lang#14091

Add checks for unstable const traits.

changelog: [`missing_const_for_fn`] fix FP on unstable const traits
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Mar 20, 2025

These commits modify the Cargo.lock file. Unintentional changes to Cargo.lock can be introduced when switching branches and rebasing PRs.

If this was unintentional then you should revert the changes before this PR is merged.
Otherwise, you can ignore this comment.

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@Manishearth
Copy link
Member

@bors r+ p=1 rollup=never

@bors
Copy link
Contributor

bors commented Mar 20, 2025

📌 Commit 58142e9 has been approved by Manishearth

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 20, 2025
@bors
Copy link
Contributor

bors commented Mar 21, 2025

⌛ Testing commit 58142e9 with merge 5d85a71...

@bors
Copy link
Contributor

bors commented Mar 21, 2025

☀️ Test successful - checks-actions
Approved by: Manishearth
Pushing 5d85a71 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 21, 2025
@bors bors merged commit 5d85a71 into rust-lang:master Mar 21, 2025
7 checks passed
@rustbot rustbot added this to the 1.87.0 milestone Mar 21, 2025
Copy link

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 01dc45c (parent) -> 5d85a71 (this PR)

Test differences

Show 32888 test diffs
  • ascii::short::case02_lookup_table (stage 2): pass -> [missing] (J0)
  • btree::map::iter_1m (stage 2): pass -> [missing] (J0)
  • btree::set::clone_100_and_drain_half (stage 1): [missing] -> pass (J0)
  • btree::set::intersection_random_10k_vs_100 (stage 1): [missing] -> pass (J0)
  • btree::set::is_subset_100_vs_100 (stage 1): [missing] -> pass (J0)
  • fs::tests::copy_file_src_dir (stage 2): pass -> [missing] (J0)
  • fs::tests::write_then_read (stage 1): [missing] -> pass (J0)
  • hash::sip::bench_str_under_8_bytes (stage 1): [missing] -> pass (J0)
  • iter::bench_rposition (stage 2): pass -> [missing] (J0)
  • num::dec2flt::bench_42 (stage 1): [missing] -> pass (J0)
  • num::int_log::u16_log10_predictable (stage 1): [missing] -> pass (J0)
  • num::int_log::u32_log10_random_small (stage 1): [missing] -> pass (J0)
  • slice::swap_with_slice_rgb_30 (stage 2): pass -> [missing] (J0)
  • sort::tests::stable::deterministic_cell_i32_random_d2 (stage 2): pass -> [missing] (J0)
  • sort::tests::unstable::deterministic_cell_i32_random (stage 2): pass -> [missing] (J0)
  • sort::tests::unstable::deterministic_i32_random (stage 1): [missing] -> pass (J0)
  • sort::tests::unstable::observable_is_less_descending (stage 2): pass -> [missing] (J0)
  • sort::tests::unstable::panic_observable_is_less_random_d2 (stage 2): pass -> [missing] (J0)
  • stats::tests::test_unif25 (stage 2): pass -> [missing] (J0)
  • vec::bench_chain_chain_collect (stage 1): [missing] -> pass (J0)
  • vec::bench_clone_0100 (stage 1): [missing] -> pass (J0)
  • back::rpath::tests::test_rpath_relative (stage 2): pass -> [missing] (J1)
  • bit_set::tests::bench_remove (stage 2): pass -> [missing] (J1)
  • bit_set::tests::bitset_iter_works_2 (stage 1): [missing] -> pass (J1)
  • errors::verify_ast_passes_pattern_in_bodiless_53 (stage 1): [missing] -> pass (J1)
  • errors::verify_ast_passes_unsafe_static_18 (stage 2): pass -> [missing] (J1)
  • errors::verify_builtin_macros_asm_sym_no_path_73 (stage 1): [missing] -> pass (J1)
  • errors::verify_builtin_macros_concat_bytes_missing_literal_38 (stage 1): [missing] -> pass (J1)
  • errors::verify_codegen_ssa_failed_to_get_layout_136 (stage 2): pass -> [missing] (J1)
  • errors::verify_codegen_ssa_invalid_monomorphization_expected_return_type_116 (stage 1): [missing] -> pass (J1)
  • errors::verify_codegen_ssa_invalid_monomorphization_return_integer_type_109 (stage 2): pass -> [missing] (J1)
  • errors::verify_codegen_ssa_rlib_not_found_42 (stage 1): [missing] -> pass (J1)
  • errors::verify_const_eval_non_const_fn_call_18 (stage 1): [missing] -> pass (J1)
  • errors::verify_interface_rustc_error_unexpected_annotation_13 (stage 2): pass -> [missing] (J1)
  • errors::verify_metadata_import_name_type_x86_72 (stage 2): pass -> [missing] (J1)
  • errors::verify_monomorphize_no_optimized_mir_1 (stage 2): pass -> [missing] (J1)
  • errors::verify_parse_attribute_on_param_type_47 (stage 1): [missing] -> pass (J1)
  • errors::verify_parse_unknown_builtin_construct_153 (stage 2): pass -> [missing] (J1)
  • errors::verify_passes_allow_incoherent_impl_51 (stage 1): [missing] -> pass (J1)
  • errors::verify_resolve_forward_declared_generic_param_7 (stage 2): pass -> [missing] (J1)
  • errors::verify_session_function_return_requires_x86_or_x86_64_41 (stage 2): pass -> [missing] (J1)
  • graph::scc::tests::bench_sccc (stage 2): pass -> [missing] (J1)
  • lints::verify_lint_builtin_non_shorthand_field_patterns_5 (stage 1): [missing] -> pass (J1)
  • lints::verify_lint_macro_expanded_macro_exports_accessed_by_absolute_paths_125 (stage 2): pass -> [missing] (J1)
  • parser::tests::different_note_2 (stage 2): pass -> [missing] (J1)
  • parser::tests::multiple_labels_secondary_without_message_3 (stage 1): [missing] -> pass (J1)
  • parser::tests::parse_extern_crate (stage 1): [missing] -> pass (J1)
  • session_diagnostics::verify_attr_parsing_multiple_stability_levels_5 (stage 1): [missing] -> pass (J1)
  • session_diagnostics::verify_attr_parsing_rustc_promotable_pairing_17 (stage 2): pass -> [missing] (J1)
  • spec::tests::i586_unknown_redox (stage 1): [missing] -> pass (J1)
  • spec::tests::riscv32imac_unknown_xous_elf (stage 1): [missing] -> pass (J1)
  • spec::tests::riscv64gc_unknown_freebsd (stage 2): pass -> [missing] (J1)
  • spec::tests::x86_64_uwp_windows_msvc (stage 1): [missing] -> pass (J1)
  • unescape::tests::test_unescape_byte_str_good (stage 2): pass -> [missing] (J1)
  • collections::hash::map::tests::test_try_reserve (stage 2): ignore -> [missing] (J2)
  • sleep_very_long (stage 2): ignore -> [missing] (J2)
  • sort::tests::stable::correct_f128_random_d20 (stage 2): ignore -> [missing] (J2)
  • sort::tests::stable::correct_i32_random_z1_03 (stage 2): ignore -> [missing] (J2)
  • sort::tests::unstable::correct_i32_random_d1024 (stage 1): [missing] -> ignore (J2)
  • sort::tests::unstable::correct_string_random_s95 (stage 1): [missing] -> ignore (J2)
  • ascii::test_make_ascii_upper_case (stage 2): pass -> [missing] (J3)
  • atomic::uint_min (stage 2): pass -> [missing] (J3)
  • collections::btree::map::tests::test_clone_panic_leak_height_1 (stage 1): [missing] -> pass (J3)
  • collections::btree::map::tests::test_range_equal_excluded (stage 2): pass -> [missing] (J3)
  • collections::hash::map::tests::test_extract_if::empty (stage 1): [missing] -> pass (J3)
  • collections::hash::set::tests::test_symmetric_difference (stage 1): [missing] -> pass (J3)
  • collections::vec_deque::tests::test_from_array (stage 1): [missing] -> pass (J3)
  • condvar::wait_timeout_while_wake (stage 2): pass -> [missing] (J3)
  • const_fns::test_const (stage 2): pass -> [missing] (J3)
  • error_with_backtrace_outputs_correctly_with_one_source (stage 1): [missing] -> pass (J3)
  • fmt::num::test_format_debug_hex (stage 2): pass -> [missing] (J3)
  • fmt::num::test_format_int_sign_padding (stage 1): [missing] -> pass (J3)
  • hash::test_writer_hasher (stage 1): [missing] -> pass (J3)
  • io::cursor::tests::test_box_slice_writer (stage 1): [missing] -> pass (J3)
  • io::cursor::tests::test_mem_reader_vectored (stage 1): [missing] -> pass (J3)
  • iter::range::test_range_trusted_random_access (stage 1): [missing] -> pass (J3)
  • lazy_lock::lazy_force_mut (stage 1): [missing] -> pass (J3)
  • lazy_lock::lazy_poisoning (stage 1): [missing] -> pass (J3)
  • lazy_lock::sync_lazy_default (stage 1): [missing] -> pass (J3)
  • mem::uninit_write_clone_of_slice (stage 1): [missing] -> pass (J3)
  • mem::uninit_write_copy_of_slice (stage 2): pass -> [missing] (J3)
  • mpmc::smoke_shared_port_gone2 (stage 1): [missing] -> pass (J3)
  • mpsc_sync::oneshot_single_thread_peek_close (stage 2): pass -> [missing] (J3)
  • mpsc_sync::smoke_shared_port_gone2 (stage 1): [missing] -> pass (J3)
  • num::bignum::test_mul_pow5_overflow_1 (stage 1): [missing] -> pass (J3)
  • num::flt2dec::strategy::dragon::test_to_shortest_str (stage 2): pass -> [missing] (J3)
  • num::flt2dec::strategy::grisu::test_max_pow10_no_more_than (stage 1): [missing] -> pass (J3)
  • num::i16::test_abs (stage 2): pass -> [missing] (J3)
  • num::int_sqrt::i16::isqrt (stage 2): pass -> [missing] (J3)
  • num::test_f32f64 (stage 1): [missing] -> pass (J3)
  • num::wrapping::test_wrapping_i32 (stage 1): [missing] -> pass (J3)
  • num::wrapping::test_wrapping_u64 (stage 1): [missing] -> pass (J3)
  • result::test_unwrap_err_unchecked (stage 2): pass -> [missing] (J3)
  • slice::slice_index::boundpair_len::pass (stage 2): pass -> [missing] (J3)
  • slice::test_slice_to (stage 2): pass -> [missing] (J3)
  • str::slice_index::boundary::range_1::index_fail (stage 1): [missing] -> pass (J3)
  • str::test_bytesator_count (stage 1): [missing] -> pass (J3)
  • str::test_char_indices_revator (stage 1): [missing] -> pass (J3)
  • string::test_str_clear (stage 2): pass -> [missing] (J3)
  • thread::tests::test_try_panic_any_message_any (stage 2): pass -> [missing] (J3)

(and 16356 additional test diffs)

Additionally, 16432 doctest diffs were found. These are ignored, as they are noisy.

Job group index

  • J0: aarch64-apple, test-various, x86_64-apple-1
  • J1: aarch64-apple, x86_64-apple-1
  • J2: x86_64-gnu-aux
  • J3: aarch64-apple, test-various, x86_64-apple-1, x86_64-gnu-aux

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (5d85a71): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -2.7%, secondary -3.2%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.7% [-2.7%, -2.7%] 1
Improvements ✅
(secondary)
-3.2% [-3.2%, -3.2%] 1
All ❌✅ (primary) -2.7% [-2.7%, -2.7%] 1

Cycles

Results (primary 2.5%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
2.5% [2.5%, 2.5%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.5% [2.5%, 2.5%] 1

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 774.81s -> 774.966s (0.02%)
Artifact size: 365.53 MiB -> 365.53 MiB (-0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.