about summary refs log tree commit diff
path: root/src/tools/clippy
AgeCommit message (Collapse)AuthorLines
2024-02-13Bump `indexmap`clubby789-10/+20
`swap` has been deprecated in favour of `swap_remove` - the behaviour is the same though.
2024-02-12Rollup merge of #120950 - compiler-errors:miri-async-closurs, r=RalfJung,oli-obkMatthias Krüger-1/+1
Fix async closures in CTFE First commit renames `is_coroutine_or_closure` into `is_closure_like`, because `is_coroutine_or_closure_or_coroutine_closure` seems confusing and long. Second commit fixes some forgotten cases where we want to handle `TyKind::CoroutineClosure` the same as closures and coroutines. The test exercises the change to `ValidityVisitor::aggregate_field_path_elem` which is the source of #120946, but not the change to `UsedParamsNeedSubstVisitor`, though I feel like it's not that big of a deal. Let me know if you'd like for me to look into constructing a test for the latter, though I have no idea what it'd look like (we can't assert against `TooGeneric` anywhere?). Fixes #120946 r? oli-obk cc ``@RalfJung``
2024-02-12Rollup merge of #118983 - Urgau:invalid_ref_casting-bigger-layout, r=oli-obkMatthias Krüger-11/+11
Warn on references casting to bigger memory layout This PR extends the [`invalid_reference_casting`](https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html#invalid-reference-casting) lint (*deny-by-default*) which currently lint on `&T -> &mut T` casting to also lint on `&(mut) A -> &(mut) B` where `size_of::<B>() > size_of::<A>()` (bigger memory layout requirement). The goal is to detect such cases: ```rust let u8_ref: &u8 = &0u8; let u64_ref: &u64 = unsafe { &*(u8_ref as *const u8 as *const u64) }; //~^ ERROR casting references to a bigger memory layout is undefined behavior let mat3 = Mat3 { a: Vec3(0i32, 0, 0), b: Vec3(0, 0, 0), c: Vec3(0, 0, 0) }; let mat3 = unsafe { &*(&mat3 as *const _ as *const [[i64; 3]; 3]) }; //~^ ERROR casting references to a bigger memory layout is undefined behavior ``` This is added to help people who write unsafe code, especially when people have matrix struct that they cast to simple array of arrays. EDIT: One caveat, due to the [`&Header`](https://github.com/rust-lang/unsafe-code-guidelines/issues/256) uncertainty the lint only fires when it can find the underline allocation. ~~I have manually tested all the new expressions that warn against Miri, and they all report immediate UB.~~ r? ``@est31``
2024-02-12Avoid UB in clippy transmute_ptr_to_ptr UI testUrgau-11/+11
2024-02-12Auto merge of #120980 - matthiaskrgr:rollup-dsjsqql, r=matthiaskrgrbors-1/+1
Rollup of 11 pull requests Successful merges: - #120765 (Reorder diagnostics API) - #120833 (More internal emit diagnostics cleanups) - #120899 (Gracefully handle non-WF alias in `assemble_alias_bound_candidates_recur`) - #120917 (Remove a bunch of dead parameters in functions) - #120928 (Add test for recently fixed issue) - #120933 (check_consts: fix duplicate errors, make importance consistent) - #120936 (improve `btree_cursors` functions documentation) - #120944 (Check that the ABI of the instance we are inlining is correct) - #120956 (Clean inlined type alias with correct param-env) - #120962 (Add myself to library/std review) - #120972 (fix ICE for deref coercions with type errors) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-12Make `is_intrinsic` query return the intrinsic nameOli Scherer-1/+1
2024-02-12Tweak delayed bug mentions.Nicholas Nethercote-1/+1
Now that we have both `delayed_bug` and `span_delayed_bug`, it makes sense to use the generic term "delayed bug" more.
2024-02-12Lower anonymous structs or unions to HIRFrank King-1/+3
2024-02-12Auto merge of #120951 - matthiaskrgr:rollup-0nnm7dv, r=matthiaskrgrbors-102/+78
Rollup of 8 pull requests Successful merges: - #110483 (Create try_new function for ThinBox) - #120740 (Make cmath.rs a single file) - #120872 (hir: Refactor getters for HIR parents) - #120880 (add note on comparing vtables / function pointers) - #120885 (interpret/visitor: ensure we only see normalized types) - #120888 (assert_unsafe_precondition cleanup) - #120897 (Encode `coroutine_for_closure` for foreign crates) - #120937 ([docs] Update armv6k-nintendo-3ds platform docs for outdated info) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-11Auto merge of #120619 - compiler-errors:param, r=lcnrbors-4/+3
Assert that params with the same *index* have the same *name* Found this bug when trying to build libcore with the new solver, since it will canonicalize two params with the same index into *different* placeholders if those params differ by name.
2024-02-11is_closure_likeMichael Goulet-1/+1
2024-02-10hir: Remove `hir::Map::{opt_parent_id,parent_id,get_parent,find_parent}`Vadim Petrochenkov-102/+78
2024-02-09Rollup merge of #120806 - flip1995:clippy-subtree-update, r=ManishearthMatthias Krüger-604/+3869
Clippy subtree update r? `@Manishearth`
2024-02-09Auto merge of #120843 - matthiaskrgr:rollup-med37z5, r=matthiaskrgrbors-3/+18
Rollup of 8 pull requests Successful merges: - #113671 (Make privacy visitor use types more (instead of HIR)) - #120308 (core/time: avoid divisions in Duration::new) - #120693 (Invert diagnostic lints.) - #120704 (A drive-by rewrite of `give_region_a_name()`) - #120809 (Use `transmute_unchecked` in `NonZero::new`.) - #120817 (Fix more `ty::Error` ICEs in MIR passes) - #120828 (Fix `ErrorGuaranteed` unsoundness with stash/steal.) - #120831 (Startup objects disappearing from sysroot) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-09Rollup merge of #120693 - nnethercote:invert-diagnostic-lints, r=davidtwcoMatthias Krüger-3/+18
Invert diagnostic lints. That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has been converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted. r? ````@davidtwco````
2024-02-08Merge commit '60cb29c5e4f9772685c9873752196725c946a849' into clippyupPhilipp Krones-604/+3869
2024-02-08Add a new debug_assertions instrinsic (compiler)Ben Kimock-1/+1
And in clippy
2024-02-08Auto merge of #120767 - matthiaskrgr:rollup-0k8ib1c, r=matthiaskrgrbors-37/+32
Rollup of 9 pull requests Successful merges: - #119592 (resolve: Unload speculatively resolved crates before freezing cstore) - #120103 (Make it so that async-fn-in-trait is compatible with a concrete future in implementation) - #120206 (hir: Make sure all `HirId`s have corresponding HIR `Node`s) - #120214 (match lowering: consistently lower bindings deepest-first) - #120688 (GVN: also turn moves into copies with projections) - #120702 (docs: also check the inline stmt during redundant link check) - #120727 (exhaustiveness: Prefer "`0..MAX` not covered" to "`_` not covered") - #120734 (Add `SubdiagnosticMessageOp` as a trait alias.) - #120739 (improve pretty printing for associated items in trait objects) r? `@ghost` `@rustbot` modify labels: rollup
2024-02-08inline a function that is only used in clippyOli Scherer-1/+1
2024-02-07Use correct param env in clippyMichael Goulet-4/+3
2024-02-07hir: Remove `fn opt_hir_id` and `fn opt_span`Vadim Petrochenkov-36/+31
2024-02-07hir: Make sure all `HirId`s have corresponding HIR `Node`sVadim Petrochenkov-1/+1
2024-02-06Add CoroutineClosure to TyKind, AggregateKind, UpvarArgsMichael Goulet-2/+6
2024-02-06Invert diagnostic lints.Nicholas Nethercote-3/+18
That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.
2024-02-05Rollup merge of #116284 - RalfJung:no-nan-match, r=cjgillotMatthias Krüger-20/+12
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error. This is part of implementing https://github.com/rust-lang/rfcs/pull/3535. Closes https://github.com/rust-lang/rust/issues/41620 by removing the lint. https://github.com/rust-lang/reference/pull/1456 updates the reference to match.
2024-01-31Rollup merge of #120490 - nnethercote:Diagnostic-hashing, r=estebankNadrieril-2/+15
Don't hash lints differently to non-lints. `Diagnostic::keys`, which is used for hashing and equating diagnostics, has a surprising behaviour: it ignores children, but only for lints. This was added in #88493 to fix some duplicated diagnostics, but it doesn't seem necessary any more. This commit removes the special case and only four tests have changed output, with additional errors. And those additional errors aren't exact duplicates, they're just similar. For example, in src/tools/clippy/tests/ui/same_name_method.rs we currently have this error: ``` error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here --> $DIR/same_name_method.rs:79:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ ``` and with this change we also get this error: ``` error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here --> $DIR/same_name_method.rs:81:9 | LL | impl T2 for S {} | ``` I think printing this second argument is reasonable, possibly even preferable to hiding it. And the other cases are similar. r? `@estebank`
2024-01-31Auto merge of #120346 - petrochenkov:ownodes, r=oli-obkbors-5/+3
hir: Refactor getters for owner nodes
2024-01-31Don't hash lints differently to non-lints.Nicholas Nethercote-2/+15
`Diagnostic::keys`, which is used for hashing and equating diagnostics, has a surprising behaviour: it ignores children, but only for lints. This was added in #88493 to fix some duplicated diagnostics, but it doesn't seem necessary any more. This commit removes the special case and only four tests have changed output, with additional errors. And those additional errors aren't exact duplicates, they're just similar. For example, in src/tools/clippy/tests/ui/same_name_method.rs we currently have this error: ``` error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here --> $DIR/same_name_method.rs:79:9 | LL | impl T1 for S {} | ^^^^^^^^^^^^^^^^ ``` and with this change we also get this error: ``` error: method's name is the same as an existing method in a trait --> $DIR/same_name_method.rs:75:13 | LL | fn foo() {} | ^^^^^^^^^^^ | note: existing `foo` defined here --> $DIR/same_name_method.rs:81:9 | LL | impl T2 for S {} | ^^^^^^^^^^^^^^^^ ``` I think printing this second argument is reasonable, possibly even preferable to hiding it. And the other cases are similar.
2024-01-30Rollup merge of #120342 - oli-obk:track_errors6, r=nnethercoteGuillaume Gomez-17/+1
Remove various `has_errors` or `err_count` uses follow up to https://github.com/rust-lang/rust/pull/119895 r? `@nnethercote` since you recently did something similar. There are so many more of these, but I wanted to get a PR out instead of growing the commit list indefinitely. The commits all work on their own and can be reviewed commit by commit.
2024-01-30hir: Remove `hir::Map::{owner,expect_owner}`Vadim Petrochenkov-2/+2
2024-01-30hir: Add non-optional `hir_owner_nodes` for real `OwnerId`sVadim Petrochenkov-3/+1
2024-01-30hir: Simplify `hir_owner_nodes` queryVadim Petrochenkov-1/+1
The query accept arbitrary DefIds, not just owner DefIds. The return can be an `Option` because if there are no nodes, then it doesn't matter whether it's due to NonOwner or Phantom. Also rename the query to `opt_hir_owner_nodes`.
2024-01-27Fix `NonZero` clippy lints.Markus Reiter-42/+64
2024-01-26remove illegal_floating_point_literal_pattern lintRalf Jung-20/+12
2024-01-26Rollup merge of #120345 - flip1995:clippy-subtree-update, r=ManishearthMatthias Krüger-1000/+2840
Clippy subtree update r? `@Manishearth` Closes https://github.com/rust-lang/rust-clippy/issues/12148
2024-01-26Rollup merge of #120329 - nnethercote:3349-precursors, r=fee1-deadMatthias Krüger-1/+1
RFC 3349 precursors Some cleanups I found while working on RFC 3349 that are worth landing separately. r? `@fee1-dead`
2024-01-26Clippy: Fix empty suggestion in from_over_intoPhilipp Krones-5/+5
Co-authored-by: y21 <30553356+y21@users.noreply.github.com>
2024-01-26Auto merge of #116167 - RalfJung:structural-eq, r=lcnrbors-17/+0
remove StructuralEq trait The documentation given for the trait is outdated: *all* function pointers implement `PartialEq` and `Eq` these days. So the `StructuralEq` trait doesn't really seem to have any reason to exist any more. One side-effect of this PR is that we allow matching on some consts that do not implement `Eq`. However, we already allowed matching on floats and consts containing floats, so this is not new, it is just allowed in more cases now. IMO it makes no sense at all to allow float matching but also sometimes require an `Eq` instance. If we want to require `Eq` we should adjust https://github.com/rust-lang/rust/pull/115893 to check for `Eq`, and rule out float matching for good. Fixes https://github.com/rust-lang/rust/issues/115881
2024-01-25Merge commit '66c29b973b3b10278bd39f4e26b08522a379c2c9' into ↵Philipp Krones-999/+2839
clippy-subtree-update
2024-01-25Remove an unused error count checkOli Scherer-17/+1
2024-01-25Rename the unescaping functions.Nicholas Nethercote-1/+1
`unescape_literal` becomes `unescape_unicode`, and `unescape_c_string` becomes `unescape_mixed`. Because rfc3349 will mean that C string literals will no longer be the only mixed utf8 literals.
2024-01-24remove StructuralEq traitRalf Jung-17/+0
2024-01-23We don't look into static items anymore during const propOli Scherer-9/+2
2024-01-23Rename `TyCtxt::struct_span_lint_hir` as `TyCtxt::node_span_lint`.Nicholas Nethercote-6/+6
2024-01-23Rename `LintContext::struct_span_lint` as `LintContext::span_lint`.Nicholas Nethercote-10/+9
2024-01-22Auto merge of #120080 - cuviper:128-align-packed, r=nikicbors-35/+46
Pack u128 in the compiler to mitigate new alignment This is based on #116672, adding a new `#[repr(packed(8))]` wrapper on `u128` to avoid changing any of the compiler's size assertions. This is needed in two places: * `SwitchTargets`, otherwise its `SmallVec<[u128; 1]>` gets padded up to 32 bytes. * `LitKind::Int`, so that entire `enum` can stay 24 bytes. * This change definitely has far-reaching effects though, since it's public.
2024-01-22Rollup merge of #119710 - Nilstrieb:let-_-=-oops, r=TaKO8KiMatthias Krüger-0/+1
Improve `let_underscore_lock` - lint if the lock was in a nested pattern - lint if the lock is inside a `Result<Lock, _>` addresses https://github.com/rust-lang/rust/pull/119704#discussion_r1444044745
2024-01-21Auto merge of #120100 - oli-obk:astconv_lifetimes, r=BoxyUwUbors-23/+23
Don't forget that the lifetime on hir types is `'tcx` This PR just tracks the `'tcx` lifetime to wherever the original objects actually have that lifetime. This code is needed for https://github.com/rust-lang/rust/pull/107606 (now #120131) so that `ast_ty_to_ty` can invoke `lit_to_const` on an argument passed to it. Currently the argument is `&hir::Ty<'_>`, but after this PR it is `&'tcx hir::Ty<'tcx>`.
2024-01-20Rollup merge of #120000 - smoelius:fix-clippy, r=fee1-deadGuillaume Gomez-23/+15
Ensure `callee_id`s are body owners This PR makes the `callee_id` argument of Clippy's `implements_trait_with_env` optional, and when it is passed, ensures it is a body owner. #118661 added the `callee_id` parameter to alleviate an ICE. Specifically, the `callee_id` is used to determine an "effect arg" in certain situations. Frankly, I [do not completely understand](https://github.com/rust-lang/rust/pull/118661#discussion_r1449013176) what an "effect arg" is. But the code that determines it seems to require that `callee_id` is a body owner: - https://github.com/rust-lang/rust/blob/1ead4761e9e2f056385768614c23ffa7acb6a19e/src/tools/clippy/clippy_utils/src/ty.rs#L286-L288 - https://github.com/rust-lang/rust/blob/1ead4761e9e2f056385768614c23ffa7acb6a19e/compiler/rustc_middle/src/ty/util.rs#L834 - https://github.com/rust-lang/rust/blob/1ead4761e9e2f056385768614c23ffa7acb6a19e/compiler/rustc_middle/src/hir/map/mod.rs#L372 In the current head, some def ids passed as `callee_id`s are not body owners. This PR fixes that. cc ``@rust-lang/clippy`` r? ``@fee1-dead``
2024-01-19Pack the u128 in LitKind::IntJosh Stone-35/+46