Commit Graph

11627 Commits

Author SHA1 Message Date
bors 206e4adb52 Auto merge of #13046 - Jarcho:check_conv, r=dswij
Refactor `checked_conversions`

Removes redundant checks across functions and check the HIR tree before anything else.

changelog: none
2024-07-13 16:07:29 +00:00
bors e7d17e6cb2 Auto merge of #13061 - tesuji:fix-map-unwrap-or-13018, r=dswij
Fix `manual_unwrap_or` false positive

changelog: [`manual_unwrap_or`]: fix false positive of `if let Option<T>`

Closes #13018
2024-07-13 15:59:11 +00:00
J-ZhengLi cc1bb8f57a make [or_fun_call] and [unwrap_or_default] recursive. 2024-07-13 23:15:40 +08:00
bors 0cbbee1e6e Auto merge of #13090 - J-ZhengLi:issue9790, r=blyxyas
[`unwrap_or_default`]: skip warning when calling inside of suggested method's implementation

fixes: #10228

---

changelog: [`unwrap_or_default`]: skip warning when calling inside of suggested method's implementation
2024-07-12 14:37:10 +00:00
J-ZhengLi 983b4c3720 [unwrap_or_default]: skip warning when calling inside of suggested method's implementation 2024-07-12 17:23:08 +08:00
Florian Bartels edeb0fcddc Fix syntax errors in example code 2024-07-12 11:12:01 +02:00
Philipp Krones 1ced73e66a Merge remote-tracking branch 'upstream/master' into rustup 2024-07-11 15:29:08 +02:00
bors 8d3b1f9e30 Auto merge of #12984 - bitfield:fix_doc_nits_c, r=Alexendoo
Fix doc nits

More tender love and polish for the documentation and suggestion texts: adding formatting, links, full stops, tweaking wording for readability, changing 'which' to 'that' where appropriate, and other standard copyediting changes.

changelog: Docs [ `await_holding_lock` ]: fix doc nits
changelog: Docs [ `await_holding_refcell_ref` ]: fix doc nits
changelog: Docs [ `await_holding_invalid_type` ]: fix doc nits
changelog: Docs [ `cast_precision_loss` ]: fix doc nits
changelog: Docs [ `cast_sign_loss` ]: fix doc nits
changelog: Docs [ `cast_possible_truncation` ]: fix doc nits
changelog: Docs [ `cast_possible_wrap` ]: fix doc nits
changelog: Docs [ `cast_lossless` ]: fix doc nits
changelog: Docs [ `unnecessary_cast` ]: fix doc nits
changelog: Docs [ `cast_ptr_alignment` ]: fix doc nits
changelog: Docs [ `fn_to_numeric_cast` ]: fix doc nits
changelog: Docs [ `fn_to_numeric_cast_with_truncation` ]: fix doc nits
changelog: Docs [ `fn_to_numeric_cast_any` ]: fix doc nits
changelog: Docs [ `char_lit_as_u8` ]: fix doc nits
changelog: Docs [ `ptr_as_ptr` ]: fix doc nits
changelog: Docs [ `ptr_cast_constness` ]: fix doc nits
changelog: Docs [ `as_ptr_cast_mut` ]: fix doc nits
changelog: Docs [ `little_endian_bytes` ]: fix doc nits
changelog: Docs [ `big_endian_bytes` ]: fix doc nits
changelog: Docs [ `bind_instead_of_map` ]: fix doc nits
changelog: Docs [ `same_name_method` ]: fix doc nits
2024-07-10 17:55:08 +00:00
bors b012421501 Auto merge of #12944 - Jarcho:overflow_check, r=y21
Fix and rename `overflow_check_conditional`

fixes #2457

Other changes:
* Limit the lint to unsigned types.
* Actually check if the operands are the same rather than using only the first part of the path.
* Allow the repeated expression to be anything as long as there are no side effects.

changelog: Rename `overflow_check_conditional` to `panicking_overflow_check` and move to `correctness`
2024-07-10 09:02:11 +00:00
bors ab7c910590 Auto merge of #13079 - sandersaares:u/sasaares/no-epsilon-guidance, r=y21
Fix guidance of [`float_cmp`] and [`float_cmp_const`] to not incorrectly recommend `f__::EPSILON` as the error margin.

Using `f32::EPSILON` or `f64::EPSILON` as the floating-point equality comparison error margin is incorrect, yet `float_cmp` has until now recommended this be done. This change fixes the given guidance (both in docs and compiler hints) to not reference these unsuitable constants.

Instead, the guidance now clarifies that the scenarios in which an absolute error margin is usable, provides a sample implementation for using a user-defined absolute error margin (as an absolute error margin can only be used-defined and may be different for different comparisons) and references the floating point guide for a reference implementation of relative error based equality comparison for cases where absolute error margins cannot be identified.

changelog: [`float_cmp`] Fix guidance to not incorrectly recommend `f__::EPSILON` as the error margin.
changelog: [`float_cmp_const`] Fix guidance to not incorrectly recommend `f__::EPSILON` as the error margin.

Fixes #6816
2024-07-10 06:36:10 +00:00
Sander Saares e42a380afc Revert accidental "Why restrict this?" change 2024-07-10 08:10:35 +03:00
bors 8fa406b03f Auto merge of #13069 - Jarcho:misc_small4, r=Manishearth
Misc refactorings part 4

And even more rearrangements to check the HIR tree before other checks.

changelog: none
2024-07-09 15:47:24 +00:00
Sander Saares a04dbb0ab9 Tidy the example code and ensure it builds as standalone snippets 2024-07-09 10:28:11 +03:00
Sander Saares a067cd24ac Replace incorrect suggested fix for float_cmp
Using `f32::EPSILON` or `f64::EPSILON` as the floating-point equality comparison error margin is incorrect, yet `float_cmp` has until now recommended this be done. This change fixes the given guidance (both in docs and compiler hints) to not reference these unsuitable constants.

Instead, the guidance now clarifies that the scenarios in which an absolute error margin is usable, provides a reference implementation of using a user-defined absolute error margin (as an absolute error margin can only be used-defined and may be different for different comparisons) and references the floating point guide for a reference implementation of relative error based equaltiy comparison for when absolute error margin cannot be used.

changelog: Fix guidance of [`float_cmp`] and [`float_cmp_const`] to not incorrectly recommend `f64::EPSILON` as the error margin.

Fixes #6816
2024-07-09 10:12:09 +03:00
bors 87f8a5b374 Auto merge of #13056 - y21:rm-compiler-lint-functions, r=Manishearth
Remove internal `compiler_lint_functions` lint

This internal lint has effectively been superseded by `disallowed_methods` when we started using that in #11811 (I didn't even know that we also had this internal lint at the time of when I created that PR).

Some of the methods that this looks for also don't exist anymore (`span_lint_note` and `span_lint_help`), though there was one that that lint had but wasn't disallowed in clippy.toml (`LintContext::lint`)

changelog: none
2024-07-08 23:10:11 +00:00
bors e64236ca3a Auto merge of #13044 - Jarcho:bool_int, r=Manishearth
Refactor `bool_to_int_with_if`

Rearranges things to check the HIR tree first and simplifies how the literals are read.

changelog: None
2024-07-08 22:58:50 +00:00
bors 058e6eaa3a Auto merge of #13043 - Jarcho:assign_clone, r=Manishearth
Refactor `assigning_clones`

Short list of changes:
* Inline and simplify `extract_call`
* Inline `is_ok_to_suggest`
* Inline `skip_drop_block`
* Check the HIR tree before the macro check
* Don't call `outer_expn_data`
* Use `find` instead of a loop in `clone_source_borrows_from_dest`

changelog: none
2024-07-08 22:48:19 +00:00
bors f6020fbd44 Auto merge of #13042 - Jarcho:almost_range, r=Manishearth
`almost_complete_range`: Delay suggestion creation.

Does less work when the lint doesn't trigger.

changelog: none
2024-07-08 22:39:01 +00:00
Michael Goulet 920cbcdd45 Move trait selection error reporting to its own top-level module 2024-07-08 16:04:47 -04:00
John Arundel d23df74712 resolve code review comments 2024-07-08 19:05:35 +01:00
bors 510cfe3dc4 Auto merge of #13067 - Jarcho:misc_small3, r=Manishearth
Misc refactorings part 3

And some more changes. Same general idea of checking the HIR tree first when linting.

changelog: none
2024-07-08 17:52:47 +00:00
bors dfb92532fa Auto merge of #12870 - lrh2000:sig-drop-while, r=blyxyas
`significant_drop_in_scrutinee`: Trigger lint also for scrutinees in `while let` and `if let`

This lint should also work for `if let` and `while let`, so this PR makes it actually work.

For `while let`, I can't think of any reason why this lint shouldn't be enabled. The only problem is that the lint suggests moving the significant drop above the `while let`, which is clearly invalid in the case of `while let`. I don't know if this is fixable, but this PR simply disables the wrong suggestions.

For `if let`, it seems that another lint called `if_let_mutex` has some overlapping functionality. But `significant_drop_in_scrutinee` is a bit stricter, as it will trigger even if the `else` branch does not try to lock the same mutex.

changelog: [`significant_drop_in_scrutinee`]: Trigger lint also for scrutinees in `while let` and `if let`.

r? `@blyxyas` (the third PR as promised in https://github.com/rust-lang/rust-clippy/pull/12740#issuecomment-2094876350, thanks for your review!)
2024-07-08 15:09:45 +00:00
bors 2ad8cdc81b Auto merge of #13045 - J-ZhengLi:missing_const_for_fn_FP, r=blyxyas
[`missing_const_for_fn`]: fix FP when arg ty is impl trait alias ty

closes: #13009

---

changelog: [`missing_const_for_fn`]: fix FP when arg ty is impl trait alias ty
2024-07-08 14:39:12 +00:00
J-ZhengLi 08992d0372 [missing_const_for_fn]: fix FP when arg ty is impl trait alias ty 2024-07-08 18:09:49 +08:00
Jason Newcomb 5b7ffa1a63 Rework init_numbered_fields:
* Only check the name of a single field
* Don't lint in macros
* Check for side effects
* Don't use a binary heap
2024-07-07 20:15:19 -04:00
Jason Newcomb eda45aaba1 minmax: use let chain 2024-07-07 18:12:39 -04:00
Jason Newcomb 488a545a50 map_unit_fn: Delay macro check 2024-07-07 18:12:05 -04:00
Jason Newcomb 7a942a5c99 manual_unwrap_or_default: Check HIR tree first. 2024-07-07 18:11:55 -04:00
Jason Newcomb 5d333e862b manual_strip: Delay msrv check. 2024-07-07 18:11:43 -04:00
Jason Newcomb c0068ba5ac manual_slice_size_calculation: Delay constant check. 2024-07-07 18:11:05 -04:00
Jason Newcomb 03117026ae manual_retain: Remove redundant match. 2024-07-07 18:10:46 -04:00
Jason Newcomb 0f4cd13f66 manual_rem_euclid: Check HIR tree first. 2024-07-07 18:08:44 -04:00
Jason Newcomb 44f87e8cc1 manual_range_patterns: Delay macro check. 2024-07-07 18:08:11 -04:00
Jason Newcomb 2309f8e4a1 manual_non_exhaustive: Delay msrv check. 2024-07-07 18:08:02 -04:00
Jason Newcomb f46c981f3f manual_main_separator_str: Check HIR tree first. 2024-07-07 18:07:52 -04:00
Jason Newcomb 2d9e67ea8a manual_let_else: Delay msrv and macro checks. 2024-07-07 18:07:36 -04:00
Jason Newcomb 95348adcb9 manual_float_methods:
* Check HIR tree first.
* Use `partition_in_place`.
2024-07-07 18:07:16 -04:00
Jason Newcomb b9ba340db6 manual_bits: Delay msrv check 2024-07-07 18:06:36 -04:00
Jason Newcomb c0fa6a92f0 literal_representation: Delay macro check. 2024-07-07 18:06:27 -04:00
Jason Newcomb 15f640a7cb let_with_type_underscore:
* Delay macro check.
* Use `is_from_proc_macro
2024-07-07 18:06:17 -04:00
Jason Newcomb 5332def0fd let_underscore: Delay macro check. 2024-07-07 18:06:00 -04:00
Jason Newcomb fed75b3895 let_if_seq: use array_windows. 2024-07-07 18:05:51 -04:00
Jason Newcomb ff4e62d3ec len_zero: Check HIR tree first 2024-07-07 18:05:41 -04:00
Jason Newcomb 5ae33c7699 legacy_numeric_constants: Check HIR tree first. 2024-07-07 16:52:59 -04:00
Jason Newcomb 03036c11b3 large_include_file: Check HIR tree first. 2024-07-07 16:52:33 -04:00
Jason Newcomb c3dd028d3e large_futures: Delay macro check 2024-07-07 16:52:13 -04:00
Jason Newcomb 430c02cbd0 large_enum_variant: Delay macro check 2024-07-07 16:51:58 -04:00
Jason Newcomb 3092c8a5fd large_const_arrays: Check HIR tree first. 2024-07-07 16:51:33 -04:00
Jason Newcomb 6b10b4360c iter_without_into_iter: Delay macro check 2024-07-07 16:51:20 -04:00
Jason Newcomb fa1a690b23 iter_not_returning_iterator:
* Check HIR tree first.
* Check name by symbol.
2024-07-07 16:43:07 -04:00