summary refs log tree commit diff
path: root/src/tools/clippy/clippy_lints
AgeCommit message (Collapse)AuthorLines
2023-08-17Auto merge of #11069 - y21:issue11063, r=Alexendoobors-6/+5
[`missing_fields_in_debug`]: make sure self type is an adt Fixes #11063, another ICE that can only happen in core. This lint needs the `DefId` of the implementor to get its fields, but that ICEs if the implementor does not have a `DefId` (as is the case with primitive types, e.g. `impl Debug for bool`), which is where this ICE comes from. This PR changes the check I added in #10897 to be more... robust against `Debug` implementations we don't want to lint. Instead of just checking if the self type is a type parameter and "special casing" one specific case we don't want to lint, we should probably rather just check that the self type is either a struct, an enum or a union and only then continue. That prevents weird edge cases like this one that can only happen in core. Again, I don't know if it's even possible to add a test case for this since one cannot implement `Debug` for primitive types outside of the crate that defined `Debug` (core). I did make sure that this PR no longer ICEs on `impl<T> Debug for T` and `impl Debug for bool`. Maybe writing such a test is possible with `#![no_core]` and then re-defining the `Debug` trait or something like that...? changelog: [`missing_fields_in_debug`]: make sure self type is an adt (fixes an ICE in core) r? `@Alexendoo` (reviewed the last PRs for this lint)
2023-08-17Auto merge of #11070 - y21:issue11065, r=flip1995bors-3/+15
[`useless_conversion`]: only lint on paths to fn items and fix FP in macro Fixes #11065 (which is actually two issues: an ICE and a false positive) It now makes sure that the function call path points to a function-like item (and not e.g. a `const` like in the linked issue), so that calling `TyCtxt::fn_sig` later in the lint does not ICE (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616836099). It *also* makes sure that the expression is not part of a macro call (fixes https://github.com/rust-lang/rust-clippy/issues/11065#issuecomment-1616919639). ~~I'm not sure if there's a better way to check this other than to walk the parent expr chain and see if any of them are expansions.~~ (edit: it doesn't do this anymore) changelog: [`useless_conversion`]: fix ICE when call receiver is a non-fn item changelog: [`useless_conversion`]: don't lint if argument is a macro argument (fixes a FP) r? `@llogiq` (reviewed #10814, which introduced these issues)
2023-08-17Auto merge of #11106 - syvb:literal_unwrap_ice, r=dswijbors-0/+31
[`unnecessary_literal_unwrap`]: Fix ICE on None.unwrap_or_default() Fixes #11099 Fixes #11064 I'm running into #11099 (cc `@y21)` on my Rust codebase. Clippy ICEs on this code when evaluating the `unnecessary_literal_unwrap` lint: ```rust fn main() { let val1: u8 = None.unwrap_or_default(); } ``` This fixes that ICE and adds an message specifically for that case: ``` error: used `unwrap_or_default()` on `None` value --> $DIR/unnecessary_literal_unwrap.rs:26:5 | LL | None::<String>.unwrap_or_default(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: remove the `None` and `unwrap_or_default()`: `String::default()` ``` This PR also fixes the same ICE with `None.unwrap_or_else` (by giving the generic error message for the lint in that case). changelog: Fix ICE in `unnecessary_literal_unwrap` on `None.unwrap_or_default()`
2023-08-17Auto merge of #11130 - smoelius:fix-10535, r=Jarchobors-2/+2
Fix ICE in #10535 Fixes #10535 r? `@Jarcho` changelog: Eliminate ICE described in #10535
2023-08-17Auto merge of #11191 - Alexendoo:redundant-type-annotations-ice, r=llogiqbors-4/+7
redundant_type_annotations: only pass certain def kinds to type_of Fixes #11190 Fixes rust-lang/rust#113516 Also adds an `is_lint_allowed` check to skip the lint when it's not needed changelog: none
2023-08-17Auto merge of #11104 - Alexendoo:arc-with-non-send-sync, r=Centri3bors-34/+37
`arc_with_non_send_sync`: reword and move to `suspicious` Fixes #11079 changelog: [`arc_with_non_send_sync`]: move to complexity
2023-08-17Auto merge of #11077 - y21:issue11076, r=Manishearthbors-1/+5
[`arc_with_non_send_sync`]: don't lint if type has nested type parameters Fixes #11076 changelog: [`arc_with_non_send_sync`]: don't lint if type has nested type parameters r? `@Manishearth`
2023-08-17Auto merge of #11172 - Alexendoo:tuple-array-conversions-nursery, r=xFrednetbors-1/+1
Move tuple_array_conversions to nursery changelog: Move [`tuple_array_conversions`] to `nursery` (Now allow-by-default) <!-- FIY: Ignore this change, if the commit gets backported and also https://github.com/rust-lang/rust-clippy/pull/11146 --> [#11172](https://github.com/rust-lang/rust-clippy/pull/11172) The nursery change got lost in #11146 and it ended up in pedantic, this puts it in nursery and gives something to backport r? `@xFrednet`
2023-08-11Rename cast_ref_to_mut to invalid_reference_casting (clippy side)Urgau-1/+1
(cherry picked from commit fa15df6f5a85ceb5919a47bb721a337c7b8f0adc)
2023-07-08Auto merge of #113376 - ↵bors-4/+4
Nilstrieb:pointer-coercions-are-not-casts-because-that-sounds-way-to-general-aaaa, r=oli-obk Rename `adjustment::PointerCast` and variants using it to `PointerCoercion` It makes it sounds like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a little enum variants. Make it clear there these are only coercions and that people who see this and think "why are so many pointer related casts not in these variants" aren't insane. This enum was added in #59987. I'm not sure whether the variant sharing is actually worth it, but this at least makes it less confusing. r? oli-obk
2023-07-07Fix failing clippy testsAlex Macleod-1/+1
Comments out the C string literals due to https://github.com/rust-lang/rust/pull/113334 Fixes https://github.com/rust-lang/rust-clippy/issues/11121
2023-07-07Rename `adjustment::PointerCast` and variants using it to `PointerCoercion`Nilstrieb-4/+4
It makes it sound like the `ExprKind` and `Rvalue` are supposed to represent all pointer related casts, when in reality their just used to share a some enum variants. Make it clear there these are only coercion to make it clear why only some pointer related "casts" are in the enum.
2023-07-05Move `TyCtxt::mk_x` to `Ty::new_x` where applicableBoxy-15/+16
2023-07-02Merge commit '37f4c1725d3fd7e9c3ffd8783246bc5589debc53' into clippyupPhilipp Krones-1181/+5394
2023-07-02Auto merge of #112718 - oli-obk:SIMD-destructure_mir_const, r=cjgillotbors-14/+50
Make simd_shuffle_indices use valtrees This removes the second-to-last user of the `destructure_mir_constant` query. So in a follow-up we can remove the query and just move the query provider function directly into pretty printing (which is the last user). cc `@rust-lang/clippy` there's a small functional change, but I think it is correct?
2023-06-26Migrate predicates_of and caller_bounds to ClauseMichael Goulet-20/+20
2023-06-26Auto merge of #112887 - WaffleLapkin:become_unuwuable_in_hir, ↵bors-0/+12
r=compiler-errors,Nilstrieb `hir`: Add `Become` expression kind (explicit tail calls experiment) This adds `hir::ExprKind::Become` alongside ast lowering. During hir-thir lowering we currently lower `become` as `return`, so that we can partially test `become` without ICEing. cc `@scottmcm` r? `@Nilstrieb`
2023-06-26Make simd_shuffle_indices use valtreesOli Scherer-14/+50
2023-06-26Support `hir::ExprKind::Become` in clippyMaybe Waffle-0/+12
2023-06-22Migrate item_bounds to ty::ClauseMichael Goulet-1/+1
2023-06-21Auto merge of #112877 - Nilstrieb:rollup-5g5hegl, r=Nilstriebbors-21/+21
Rollup of 6 pull requests Successful merges: - #112632 (Implement PartialOrd for `Vec`s over different allocators) - #112759 (Make closure_saved_names_of_captured_variables a query. ) - #112772 (Add a fully fledged `Clause` type, rename old `Clause` to `ClauseKind`) - #112790 (Syntactically accept `become` expressions (explicit tail calls experiment)) - #112830 (More codegen cleanups) - #112844 (Add retag in MIR transform: `Adt` for `Unique` may contain a reference) r? `@ghost` `@rustbot` modify labels: rollup
2023-06-21Auto merge of #106450 - albertlarsan68:fix-arc-ptr-eq, r=Amanieubors-3/+1
Make `{Arc,Rc,Weak}::ptr_eq` ignore pointer metadata FCP completed in https://github.com/rust-lang/rust/issues/103763#issuecomment-1362267967 Closes #103763
2023-06-19s/Clause/ClauseKindMichael Goulet-21/+21
2023-06-16Add `AliasKind::Weak` for type aliases.Oli Scherer-0/+1
Only use it when the type alias contains an opaque type. Also does wf-checking on such type aliases.
2023-06-10Drop uplifted `clippy:cmp_nan`Urgau-59/+1
2023-06-09Auto merge of #111530 - Urgau:uplift_undropped_manually_drops, r=compiler-errorsbors-43/+3
Uplift `clippy::undropped_manually_drops` lint This PR aims at uplifting the `clippy::undropped_manually_drops` lint. ## `undropped_manually_drops` (warn-by-default) The `undropped_manually_drops` lint check for calls to `std::mem::drop` with a value of `std::mem::ManuallyDrop` which doesn't drop. ### Example ```rust struct S; drop(std::mem::ManuallyDrop::new(S)); ``` ### Explanation `ManuallyDrop` does not drop it's inner value so calling `std::mem::drop` will not drop the inner value of the `ManuallyDrop` either. ----- Mostly followed the instructions for uplifting an clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 `@rustbot` label: +I-lang-nominated r? compiler ----- For Clippy: changelog: Moves: Uplifted `clippy::undropped_manually_drops` into rustc
2023-06-08Drop uplifted clippy::undropped_manually_dropsUrgau-43/+3
2023-06-08Whoops, submodule change was actually valid - undoing fixupAndrew Xie-1/+1
2023-06-08fixup! Removed stable/unstable sort arg from into_sorted_stable_ord, fixed a ↵Andrew Xie-1/+1
few misc issues, added collect to UnordItems
2023-06-08Removed stable/unstable sort arg from into_sorted_stable_ord, fixed a few ↵Andrew Xie-1/+1
misc issues, added collect to UnordItems
2023-06-02Rollup merge of #112165 - fee1-dead-contrib:rn-defualtness, r=compiler-errorsMatthias Krüger-1/+1
Rename `impl_defaultness` to `defaultness` Since this isn't just about the `impl`.
2023-06-02Merge commit '30448e8cf98d4754350db0c959644564f317bc0f' into clippyupPhilipp Krones-237/+732
2023-06-01Rename `impl_defaultness` to `defaultness`Deadbeef-1/+1
2023-05-31Drop uplifted clippy::cast_ref_to_mutUrgau-65/+1
2023-05-30Rollup merge of #112060 - lcnr:early-binder, r=jackh726Nilstrieb-5/+5
`EarlyBinder::new` -> `EarlyBinder::bind` for consistency with `Binder::bind`. it may make sense to also add `EarlyBinder::dummy` in places where we know that no parameters exist, but I left that out of this PR. r? `@jackh726` `@kylematsuda`
2023-05-30Rollup merge of #111543 - Urgau:uplift_invalid_utf8_in_unchecked, r=WaffleLapkinNilstrieb-77/+1
Uplift `clippy::invalid_utf8_in_unchecked` lint This PR aims at uplifting the `clippy::invalid_utf8_in_unchecked` lint into two lints. ## `invalid_from_utf8_unchecked` (deny-by-default) The `invalid_from_utf8_unchecked` lint checks for calls to `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut` with an invalid UTF-8 literal. ### Example ```rust unsafe { std::str::from_utf8_unchecked(b"cl\x82ippy"); } ``` ### Explanation Creating such a `str` would result in undefined behavior as per documentation for `std::str::from_utf8_unchecked` and `std::str::from_utf8_unchecked_mut`. ## `invalid_from_utf8` (warn-by-default) The `invalid_from_utf8` lint checks for calls to `std::str::from_utf8` and `std::str::from_utf8_mut` with an invalid UTF-8 literal. ### Example ```rust std::str::from_utf8(b"ru\x82st"); ``` ### Explanation Trying to create such a `str` would always return an error as per documentation for `std::str::from_utf8` and `std::str::from_utf8_mut`. ----- Mostly followed the instructions for uplifting a clippy lint described here: https://github.com/rust-lang/rust/pull/99696#pullrequestreview-1134072751 ````@rustbot```` label: +I-lang-nominated r? compiler ----- For Clippy: changelog: Moves: Uplifted `clippy::invalid_utf8_in_unchecked` into rustc
2023-05-29EarlyBinder::new -> EarlyBinder::bindlcnr-5/+5
2023-05-29Use `Cow` in `{D,Subd}iagnosticMessage`.Nicholas Nethercote-9/+6
Each of `{D,Subd}iagnosticMessage::{Str,Eager}` has a comment: ``` // FIXME(davidtwco): can a `Cow<'static, str>` be used here? ``` This commit answers that question in the affirmative. It's not the most compelling change ever, but it might be worth merging. This requires changing the `impl<'a> From<&'a str>` impls to `impl From<&'static str>`, which involves a bunch of knock-on changes that require/result in call sites being a little more precise about exactly what kind of string they use to create errors, and not just `&str`. This will result in fewer unnecessary allocations, though this will not have any notable perf effects given that these are error paths. Note that I was lazy within Clippy, using `to_string` in a few places to preserve the existing string imprecision. I could have used `impl Into<{D,Subd}iagnosticMessage>` in various places as is done in the compiler, but that would have required changes to *many* call sites (mostly changing `&format("...")` to `format!("...")`) which didn't seem worthwhile.
2023-05-28Make EarlyBinder's inner value private; and fix all of the resulting errorsKyle Matsuda-1/+1
2023-05-28Replace EarlyBinder(x) with EarlyBinder::new(x)Kyle Matsuda-5/+5
2023-05-27Drop uplifted clippy::invalid_utf8_in_uncheckedUrgau-77/+1
2023-05-21Rename `forget_ref` lint to `forgetting_references`Urgau-2/+2
2023-05-21Rename `drop_ref` lint to `dropping_references`Urgau-2/+2
2023-05-21Rename `forget_copy` lint to `forgetting_copy_types`Urgau-2/+2
2023-05-21Rename `drop_copy` lint to `dropping_copy_types`Urgau-2/+2
2023-05-20Merge commit '435a8ad86c7a33bd7ffb91c59039943408d3b6aa' into clippyupPhilipp Krones-446/+956
2023-05-17Rollup merge of #111648 - Nilstrieb:language-items, r=WaffleLapkinDylan DPC-4/+5
Remove `LangItems::require` It's just a short wrapper used by `tcx.require_lang_item`. Deleting it gives us a negative diff.
2023-05-16Remove `LangItems::require`Nilstrieb-4/+5
It's just a short wrapper used by `tcx.require_lang_item`. Deleting it gives us a negative diff.
2023-05-10Drop uplifted clippy::forget_copyUrgau-34/+3
2023-05-10Drop uplifted clippy::forget_refUrgau-28/+3