about summary refs log tree commit diff
path: root/clippy_lints/src/utils
AgeCommit message (Collapse)AuthorLines
2025-02-20Merge remote-tracking branch 'upstream/master' into rustupPhilipp Krones-1/+1
2025-02-18Move methods from `Map` to `TyCtxt`, part 2.Nicholas Nethercote-3/+2
Continuing the work started in #136466. Every method gains a `hir_` prefix, though for the ones that already have a `par_` or `try_par_` prefix I added the `hir_` after that.
2025-02-17Overhaul the `intravisit::Map` trait.Nicholas Nethercote-1/+1
First of all, note that `Map` has three different relevant meanings. - The `intravisit::Map` trait. - The `map::Map` struct. - The `NestedFilter::Map` associated type. The `intravisit::Map` trait is impl'd twice. - For `!`, where the methods are all unreachable. - For `map::Map`, which gets HIR stuff from the `TyCtxt`. As part of getting rid of `map::Map`, this commit changes `impl intravisit::Map for map::Map` to `impl intravisit::Map for TyCtxt`. It's fairly straightforward except various things are renamed, because the existing names would no longer have made sense. - `trait intravisit::Map` becomes `trait intravisit::HirTyCtxt`, so named because it gets some HIR stuff from a `TyCtxt`. - `NestedFilter::Map` assoc type becomes `NestedFilter::MaybeTyCtxt`, because it's always `!` or `TyCtxt`. - `Visitor::nested_visit_map` becomes `Visitor::maybe_tcx`. I deliberately made the new trait and associated type names different to avoid the old `type Map: Map` situation, which I found confusing. We now have `type MaybeTyCtxt: HirTyCtxt`.
2025-02-17Move some `Map` methods onto `TyCtxt`.Nicholas Nethercote-5/+5
The end goal is to eliminate `Map` altogether. I added a `hir_` prefix to all of them, that seemed simplest. The exceptions are `module_items` which became `hir_module_free_items` because there was already a `hir_module_items`, and `items` which became `hir_free_items` for consistency with `hir_module_free_items`.
2025-02-03tree-wide: parallel: Fully removed all `Lrc`, replaced with `Arc`Askar Safin-3/+2
2025-01-29Eliminate PatKind::PathOli Scherer-5/+0
2025-01-28Merge commit '51d49c1ae2785b24ef18a46ef233fc1d91844666' into ↵Philipp Krones-1/+1
clippy-subtree-update
2025-01-09Merge commit '19e305bb57a7595f2a8d81f521c0dd8bf854e739' into ↵Philipp Krones-0/+1
clippy-subtree-update
2025-01-08Rename PatKind::Lit to ExprOli Scherer-3/+3
2025-01-08Exhaustively handle expressions in patternsOli Scherer-4/+25
2024-12-31cover guard patterns in clippy lintsMax Niederman-0/+6
2024-12-26Merge commit '609cd310be44677ae31d452a17b0f8207e1abfe1' into ↵Philipp Krones-18/+22
clippy-subtree-update
2024-12-16rename rustc_attr to rustc_attr_parsing and create rustc_attr_data_structuresJonathan Dönszelmann-1/+1
2024-12-12Fix toolsMichael Goulet-0/+3
2024-12-09Introduce `default_field_values` featureEsteban Küber-2/+5
Initial implementation of `#[feature(default_field_values]`, proposed in https://github.com/rust-lang/rfcs/pull/3681. Support default fields in enum struct variant Allow default values in an enum struct variant definition: ```rust pub enum Bar { Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Allow using `..` without a base on an enum struct variant ```rust Bar::Foo { .. } ``` `#[derive(Default)]` doesn't account for these as it is still gating `#[default]` only being allowed on unit variants. Support `#[derive(Default)]` on enum struct variants with all defaulted fields ```rust pub enum Bar { #[default] Foo { bar: S = S, baz: i32 = 42 + 3, } } ``` Check for missing fields in typeck instead of mir_build. Expand test with `const` param case (needs `generic_const_exprs` enabled). Properly instantiate MIR const The following works: ```rust struct S<A> { a: Vec<A> = Vec::new(), } S::<i32> { .. } ``` Add lint for default fields that will always fail const-eval We *allow* this to happen for API writers that might want to rely on users' getting a compile error when using the default field, different to the error that they would get when the field isn't default. We could change this to *always* error instead of being a lint, if we wanted. This will *not* catch errors for partially evaluated consts, like when the expression relies on a const parameter. Suggestions when encountering `Foo { .. }` without `#[feature(default_field_values)]`: - Suggest adding a base expression if there are missing fields. - Suggest enabling the feature if all the missing fields have optional values. - Suggest removing `..` if there are no missing fields.
2024-12-01Rollup merge of #133589 - voidc:remove-array-len, r=boxyuwuJacob Pratt-9/+3
Remove `hir::ArrayLen` This refactoring removes `hir::ArrayLen`, replacing it with `hir::ConstArg`. To represent inferred array lengths (previously `hir::ArrayLen::Infer`), a new variant `ConstArgKind::Infer` is added. r? `@BoxyUwU`
2024-11-30Remove hir::ArrayLen, introduce ConstArgKind::InferDominik Stolz-9/+3
Remove Node::ArrayLenInfer
2024-11-28Merge commit 'ff4a26d442bead94a4c96fb1de967374bc4fbd8e' into ↵Philipp Krones-4/+7
clippy-subtree-update
2024-11-07Merge commit 'f712eb5cdccd121d0569af12f20e6a0fabe4364d' into ↵Philipp Krones-11/+121
clippy-subtree-update
2024-10-18Merge commit 'a109190d7060236e655fc75533373fa274ec5343' into ↵Philipp Krones-16/+23
clippy-subtree-update
2024-10-03Merge commit 'aa0d551351a9c15d8a95fdb3e2946b505893dda8' into ↵Philipp Krones-4/+3
clippy-subtree-update
2024-09-24Merge commit '7901289135257ca0fbed3a5522526f95b0f5edba' into ↵Philipp Krones-9/+9
clippy-subtree-update
2024-08-24Merge commit '0f8eabd6231366bfc1bb1464601297c2d48f8f68' into clippyupJason Newcomb-1118/+23
2024-08-08Merge commit 'cb806113e0f83a8f9b47d35b453b676543bcc40e' into ↵Philipp Krones-144/+72
clippy-subtree-update
2024-07-25Merge commit '37f4fbb92913586b73a35772efd00eccd1cbbe13' into ↵Philipp Krones-4/+4
clippy-subtree-update
2024-07-16Add `ConstArgKind::Path` and make `ConstArg` its own HIR nodeNoah Lev-7/+6
This is a very large commit since a lot needs to be changed in order to make the tests pass. The salient changes are: - `ConstArgKind` gets a new `Path` variant, and all const params are now represented using it. Non-param paths still use `ConstArgKind::Anon` to prevent this change from getting too large, but they will soon use the `Path` variant too. - `ConstArg` gets a distinct `hir_id` field and its own variant in `hir::Node`. This affected many parts of the compiler that expected the parent of an `AnonConst` to be the containing context (e.g., an array repeat expression). They have been changed to check the "grandparent" where necessary. - Some `ast::AnonConst`s now have their `DefId`s created in rustc_ast_lowering rather than `DefCollector`. This is because in some cases they will end up becoming a `ConstArgKind::Path` instead, which has no `DefId`. We have to solve this in a hacky way where we guess whether the `AnonConst` could end up as a path const since we can't know for sure until after name resolution (`N` could refer to a free const or a nullary struct). If it has no chance as being a const param, then we create a `DefId` in `DefCollector` -- otherwise we decide during ast_lowering. This will have to be updated once all path consts use `ConstArgKind::Path`. - We explicitly use `ConstArgHasType` for array lengths, rather than implicitly relying on anon const type feeding -- this is due to the addition of `ConstArgKind::Path`. - Some tests have their outputs changed, but the changes are for the most part minor (including removing duplicate or almost-duplicate errors). One test now ICEs, but it is for an incomplete, unstable feature and is now tracked at #127009.
2024-07-16Use `ConstArg` for array lengthsNoah Lev-7/+22
2024-07-11Merge commit 'b794b8e08c16517a941dc598bb1483e8e12a8592' into ↵Philipp Krones-74/+0
clippy-subtree-update
2024-06-27Merge commit '68a799aea9b65e2444fbecfe32217ce7d5a3604f' into ↵Philipp Krones-0/+1
clippy-subtree-update
2024-06-13Merge commit '3e5a02b13b1244545454752c6629b767522a44b1' into ↵Philipp Krones-4/+4
clippy-subtree-update
2024-05-29Make `body_owned_by` return the body directly.Oli Scherer-2/+2
Almost all callers want this anyway, and now we can use it to also return fed bodies
2024-05-21Merge commit '2efebd2f0c03dabbe5c3ad7b4ebfbd99238d1fb2' into ↵Philipp Krones-12/+15
clippy-subtree-update
2024-05-02Merge commit '20b085d500dfba5afe0869707bf357af3afe20be' into ↵Philipp Krones-2/+2
clippy-subtree-update
2024-04-17Rename `BindingAnnotation` to `BindingMode`Jules Bertholet-8/+8
2024-04-04Merge commit '9725c4a162502a02c1c67fdca6b797fe09b2b73c' into ↵Philipp Krones-26/+24
clippy-subtree-update
2024-03-27Implement `mut ref`/`mut ref mut`Jules Bertholet-0/+2
2024-03-24Rename `{enter,exit}_lint_attrs` to `check_attributes{,_post}`Alex Macleod-1/+1
2024-03-22Rename `hir::Node::Local` into `hir::Node::LetStmt`Guillaume Gomez-2/+2
2024-03-21Merge commit '9d6f41691ed9dbfaec2a2df2661c42451f2fe0d3' into ↵Philipp Krones-2/+2
clippy-subtree-update
2024-03-21Implement macro-based deref!() syntax for deref patternsMichael Goulet-0/+5
Stop using `box PAT` syntax for deref patterns, as it's misleading and also causes their semantics being tangled up.
2024-03-14Rename `hir::StmtKind::Local` into `hir::StmtKind::Let`Guillaume Gomez-1/+1
2024-02-28Rename `DiagnosticBuilder` as `Diag`.Nicholas Nethercote-3/+3
Much better! Note that this involves renaming (and updating the value of) `DIAGNOSTIC_BUILDER` in clippy.
2024-02-27Merge commit '10136170fe9ed01e46aeb4f4479175b79eb0e3c7' into ↵Philipp Krones-2/+0
clippy-subtree-update
2024-02-15Add `ErrorGuaranteed` to `ast::LitKind::Err`, `token::LitKind::Err`.Nicholas Nethercote-1/+1
This mostly works well, and eliminates a couple of delayed bugs. One annoying thing is that we should really also add an `ErrorGuaranteed` to `proc_macro::bridge::LitKind::Err`. But that's difficult because `proc_macro` doesn't have access to `ErrorGuaranteed`, so we have to fake it.
2024-02-10hir: Remove `hir::Map::{opt_parent_id,parent_id,get_parent,find_parent}`Vadim Petrochenkov-5/+4
2024-02-08Merge commit '60cb29c5e4f9772685c9873752196725c946a849' into clippyupPhilipp Krones-3/+3
2024-02-06Add CoroutineClosure to TyKind, AggregateKind, UpvarArgsMichael Goulet-0/+3
2024-01-25Merge commit '66c29b973b3b10278bd39f4e26b08522a379c2c9' into ↵Philipp Krones-2/+4
clippy-subtree-update
2024-01-23Rename `LintContext::struct_span_lint` as `LintContext::span_lint`.Nicholas Nethercote-1/+0
2024-01-17Add `PatKind::Err`Lieselotte-0/+1