about summary refs log tree commit diff
path: root/src/tools/clippy
AgeCommit message (Collapse)AuthorLines
2024-06-05Make top-level `rustc_parse` functions fallible.Nicholas Nethercote-2/+2
Currently we have an awkward mix of fallible and infallible functions: ``` new_parser_from_source_str maybe_new_parser_from_source_str new_parser_from_file (maybe_new_parser_from_file) // missing (new_parser_from_source_file) // missing maybe_new_parser_from_source_file source_str_to_stream maybe_source_file_to_stream ``` We could add the two missing functions, but instead this commit removes of all the infallible ones and renames the fallible ones leaving us with these which are all fallible: ``` new_parser_from_source_str new_parser_from_file new_parser_from_source_file source_str_to_stream source_file_to_stream ``` This requires making `unwrap_or_emit_fatal` public so callers of formerly infallible functions can still work. This does make some of the call sites slightly more verbose, but I think it's worth it for the simpler API. Also, there are two `catch_unwind` calls and one `catch_fatal_errors` call in this diff that become removable thanks this change. (I will do that in a follow-up PR.)
2024-06-04Add safe/unsafe to static inside extern blocksSantiago Pastorino-1/+3
2024-06-04Handle safety keyword for extern block inner itemsSantiago Pastorino-1/+3
2024-06-03Align Term methods with GenericArg methodsMichael Goulet-8/+8
2024-06-03Opt-in diagnostics reporting to avoid doing extra work in the new solverMichael Goulet-1/+1
2024-06-01Auto merge of #125775 - compiler-errors:uplift-closure-args, r=lcnrbors-2/+2
Uplift `{Closure,Coroutine,CoroutineClosure}Args` and friends to `rustc_type_ir` Part of converting the new solver's `structural_traits.rs` to be interner-agnostic. I decided against aliasing `ClosureArgs<TyCtxt<'tcx>>` to `ClosureArgs<'tcx>` because it seemed so rare. I could do so if desired, though. r? lcnr
2024-06-01Uplift TypeRelation and RelateMichael Goulet-2/+2
2024-06-01Deduplicate supertrait_def_ids codeMark Rousskov-1/+1
2024-05-31Rollup merge of #125635 - fmease:mv-type-binding-assoc-item-constraint, ↵Matthias Krüger-51/+44
r=compiler-errors Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanup Rename `hir::TypeBinding` and `ast::AssocConstraint` to `AssocItemConstraint` and update all items and locals using the old terminology. Motivation: The terminology *type binding* is extremely outdated. "Type bindings" not only include constraints on associated *types* but also on associated *constants* (feature `associated_const_equality`) and on RPITITs of associated *functions* (feature `return_type_notation`). Hence the word *item* in the new name. Furthermore, the word *binding* commonly refers to a mapping from a binder/identifier to a "value" for some definition of "value". Its use in "type binding" made sense when equality constraints (e.g., `AssocTy = Ty`) were the only kind of associated item constraint. Nowadays however, we also have *associated type bounds* (e.g., `AssocTy: Bound`) for which the term *binding* doesn't make sense. --- Old terminology (HIR, rustdoc): ``` `TypeBinding`: (associated) type binding ├── `Constraint`: associated type bound └── `Equality`: (associated) equality constraint (?) ├── `Ty`: (associated) type binding └── `Const`: associated const equality (constraint) ``` Old terminology (AST, abbrev.): ``` `AssocConstraint` ├── `Bound` └── `Equality` ├── `Ty` └── `Const` ``` New terminology (AST, HIR, rustdoc): ``` `AssocItemConstraint`: associated item constraint ├── `Bound`: associated type bound └── `Equality`: associated item equality constraint OR associated item binding (for short) ├── `Ty`: associated type equality constraint OR associated type binding (for short) └── `Const`: associated const equality constraint OR associated const binding (for short) ``` r? compiler-errors
2024-05-30Rename HIR `TypeBinding` to `AssocItemConstraint` and related cleanupLeón Orell Valerian Liehr-51/+44
2024-05-30Auto merge of #125764 - flip1995:clippy-subtree-update, r=Manishearthbors-676/+1422
Clippy subtree update r? `@Manishearth`
2024-05-30Merge commit 'c9139bd546d9cd69df817faeab62c5f9b1a51337' into ↵Philipp Krones-676/+1422
clippy-subtree-update
2024-05-30Auto merge of #125711 - oli-obk:const_block_ice2, r=Nadrierilbors-22/+21
Make `body_owned_by` return the `Body` instead of just the `BodyId` fixes #125677 Almost all `body_owned_by` callers immediately called `body`, too, so just return `Body` directly. This makes the inline-const query feeding more robust, as all calls to `body_owned_by` will now yield a body for inline consts, too. I have not yet figured out a good way to make `tcx.hir().body()` return an inline-const body, but that can be done as a follow-up
2024-05-29ast: Revert a breaking attribute visiting order changeVadim Petrochenkov-24/+24
2024-05-29Auto merge of #125360 - RalfJung:packed-field-reorder, r=fmeasebors-1/+1
don't inhibit random field reordering on repr(packed(1)) `inhibit_struct_field_reordering_opt` being false means we exclude this type from random field shuffling. However, `packed(1)` types can still be shuffled! The logic was added in https://github.com/rust-lang/rust/pull/48528 since it's pointless to reorder fields in packed(1) types (there's no padding that could be saved) -- but that shouldn't inhibit `-Zrandomize-layout` (which did not exist at the time). We could add an optimization elsewhere to not bother sorting the fields for `repr(packed)` types, but I don't think that's worth the effort. This *does* change the behavior in that we may now reorder fields of `packed(1)` structs (e.g. if there are niches, we'll try to move them to the start/end, according to `NicheBias`). We were always allowed to do that but so far we didn't. Quoting the [reference](https://doc.rust-lang.org/reference/type-layout.html): > On their own, align and packed do not provide guarantees about the order of fields in the layout of a struct or the layout of an enum variant, although they may be combined with representations (such as C) which do provide such guarantees.
2024-05-29Make `body_owned_by` return the body directly.Oli Scherer-8/+7
Almost all callers want this anyway, and now we can use it to also return fed bodies
2024-05-29Don't require `visit_body` to take a lifetime that must outlive the function ↵Oli Scherer-14/+14
call
2024-05-28Create const block DefIds in typeck instead of ast loweringOli Scherer-9/+33
2024-05-27Auto merge of #125410 - fmease:adj-lint-diag-api, r=nnethercotebors-12/+18
[perf] Delay the construction of early lint diag structs Attacks some of the perf regressions from https://github.com/rust-lang/rust/pull/124417#issuecomment-2123700666. See individual commits for details. The first three commits are not strictly necessary. However, the 2nd one (06bc4fc67145e3a7be9b5a2cf2b5968cef36e587, *Remove `LintDiagnostic::msg`*) makes the main change way nicer to implement. It's also pretty sweet on its own if I may say so myself.
2024-05-27Auto merge of #125468 - BoxyUwU:remove_defid_from_regionparam, r=compiler-errorsbors-10/+9
Remove `DefId` from `EarlyParamRegion` Currently we represent usages of `Region` parameters via the `ReEarlyParam` or `ReLateParam` variants. The `ReEarlyParam` is effectively equivalent to `TyKind::Param` and `ConstKind::Param` (i.e. it stores a `Symbol` and a `u32` index) however it also stores a `DefId` for the definition of the lifetime parameter. This was used in roughly two places: - Borrowck diagnostics instead of threading the appropriate `body_id` down to relevant locations. Interestingly there were already some places that had to pass down a `DefId` manually. - Some opaque type checking logic was using the `DefId` field to track captured lifetimes I've split this PR up into a commit for generate rote changes to diagnostics code to pass around a `DefId` manually everywhere, and another commit for the opaque type related changes which likely require more careful review as they might change the semantics of lints/errors. Instead of manually passing the `DefId` around everywhere I previously tried to bundle it in with `TypeErrCtxt` but ran into issues with some call sites of `infcx.err_ctxt` being unable to provide a `DefId`, particularly places involved with trait solving and normalization. It might be worth investigating adding some new wrapper type to pass this around everywhere but I think this might be acceptable for now. This pr also has the effect of reducing the size of `EarlyParamRegion` from 16 bytes -> 8 bytes. I wouldn't expect this to have any direct performance improvement however, other variants of `RegionKind` over `8` bytes are all because they contain a `BoundRegionKind` which is, as far as I know, mostly there for diagnostics. If we're ever able to remove this it would shrink the `RegionKind` type from `24` bytes to `12` (and with clever bit packing we might be able to get it to `8` bytes). I am curious what the performance impact would be of removing interning of `Region`'s if we ever manage to shrink `RegionKind` that much. Sidenote: by removing the `DefId` the `Debug` output for `Region` has gotten significantly nicer. As an example see this opaque type debug print before vs after this PR: `Opaque(DefId(0:13 ~ impl_trait_captures[aeb9]::foo::{opaque#0}), [DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a)_'a/#0, T, DefId(0:9 ~ impl_trait_captures[aeb9]::foo::'a)_'a/#0])` `Opaque(DefId(0:13 ~ impl_trait_captures[aeb9]::foo::{opaque#0}), ['a/#0, T, 'a/#0])` r? `@compiler-errors` (I would like someone who understands the opaque type setup to atleast review the type system commit, but the rest is likely reviewable by anyone)
2024-05-24Remove `DefId` from `EarlyParamRegion` (clippy/smir)Boxy-10/+9
2024-05-23Remove `LintDiagnostic::msg`León Orell Valerian Liehr-12/+18
* instead simply set the primary message inside the lint decorator functions * it used to be this way before [#]101986 which introduced `msg` to prevent good path delayed bugs (which no longer exist) from firing under certain circumstances when lints were suppressed / silenced * this is no longer necessary for various reasons I presume * it shaves off complexity and makes further changes easier to implement
2024-05-22rustc: Use `tcx.used_crates(())` moreVadim Petrochenkov-1/+1
And explain when it should be used.
2024-05-21Merge commit '2efebd2f0c03dabbe5c3ad7b4ebfbd99238d1fb2' into ↵Philipp Krones-1120/+4025
clippy-subtree-update
2024-05-21don't inhibit random field reordering on repr(packed(1))Ralf Jung-1/+1
2024-05-20Remove a clippy test that doesn't apply anymoreMichael Goulet-34/+26
2024-05-20Rollup merge of #125173 - scottmcm:never-checked, r=davidtwcoMatthias Krüger-3/+3
Remove `Rvalue::CheckedBinaryOp` Zulip conversation: <https://rust-lang.zulipchat.com/#narrow/stream/189540-t-compiler.2Fwg-mir-opt/topic/intrinsics.20vs.20binop.2Funop/near/438729996> cc `@RalfJung` While it's a draft, r? ghost
2024-05-19Auto merge of #125294 - matthiaskrgr:rollup-w42c829, r=matthiaskrgrbors-2/+2
Rollup of 4 pull requests Successful merges: - #124948 (chore: Remove repeated words (extension of #124924)) - #124992 (Add example to IsTerminal::is_terminal) - #125279 (make `Debug` impl for `Term` simpler) - #125286 (Miri subtree update) r? `@ghost` `@rustbot` modify labels: rollup
2024-05-19Rollup merge of #124948 - blyxyas:remove-repeated-words, r=compiler-errorsMatthias Krüger-2/+2
chore: Remove repeated words (extension of #124924) When I saw #124924 I thought "Hey, I'm sure that there are far more than just two typos of this nature in the codebase". So here's some more typo-fixing. Some found with regex, some found with a spellchecker. Every single one manually reviewed by me (along with hundreds of false negatives by the tools)
2024-05-19Add and use generics.is_empty() and generics.is_own_empty, rather than using ↵Santiago Pastorino-2/+2
generics' attributes
2024-05-18Auto merge of #125077 - spastorino:add-new-fnsafety-enum2, r=jackh726bors-62/+57
Rename Unsafe to Safety Alternative to #124455, which is to just have one Safety enum to use everywhere, this opens the posibility of adding `ast::Safety::Safe` that's useful for unsafe extern blocks. This leaves us today with: ```rust enum ast::Safety { Unsafe(Span), Default, // Safe (going to be added for unsafe extern blocks) } enum hir::Safety { Unsafe, Safe, } ``` We would convert from `ast::Safety::Default` into the right Safety level according the context.
2024-05-18Fix typos (taking into account review comments)blyxyas-2/+2
2024-05-17Fix clippyScott McMurray-3/+3
2024-05-17Rename Unsafe to SafetySantiago Pastorino-62/+57
2024-05-16Remove trivial Binder::dummy callsMichael Goulet-1/+1
2024-05-16Fix toolsMichael Goulet-4/+4
2024-05-13Apply nitsMichael Goulet-3/+3
2024-05-13split out AliasTy -> AliasTermMichael Goulet-12/+9
2024-05-12Propagate errors rather than using return_if_errMichael Goulet-13/+17
2024-05-12Make LateCtxt be a type info delegate for EUV for clippyMichael Goulet-60/+21
2024-05-12Inline MemCategorization into ExprUseVisitorMichael Goulet-3/+3
2024-05-10Lift `TraitRef` into `rustc_type_ir`Michael Goulet-1/+2
2024-05-10Rollup merge of #124957 - compiler-errors:builtin-deref, r=michaelwoeristerMatthias Krüger-6/+6
Make `Ty::builtin_deref` just return a `Ty` Nowhere in the compiler are we using the mutability part of the `TyAndMut` that we used to return.
2024-05-10Auto merge of #124961 - matthiaskrgr:rollup-1jj65p6, r=matthiaskrgrbors-12/+11
Rollup of 7 pull requests Successful merges: - #124551 (Add benchmarks for `impl Debug for str`) - #124915 (`rustc_target` cleanups) - #124918 (Eliminate some `FIXME(lcnr)` comments) - #124927 (opt-dist: use xz2 instead of xz crate) - #124936 (analyse visitor: build proof tree in probe) - #124943 (always use `GenericArgsRef`) - #124955 (Use fewer origins when creating type variables.) r? `@ghost` `@rustbot` modify labels: rollup
2024-05-10Rollup merge of #124955 - nnethercote:next_ty_var, r=lcnrMatthias Krüger-6/+1
Use fewer origins when creating type variables. To reduce lots of repetitive boilerplate code. Details in the individual commit messages. r? ``@lcnr``
2024-05-09Make builtin_deref just return a TyMichael Goulet-6/+6
2024-05-09Rename Generics::params to Generics::own_paramsMichael Goulet-11/+11
2024-05-10Use fewer origins when creating type variables.Nicholas Nethercote-6/+1
`InferCtxt::next_{ty,const}_var*` all take an origin, but the `param_def_id` is almost always `None`. This commit changes them to just take a `Span` and build the origin within the method, and adds new methods for the rare cases where `param_def_id` might not be `None`. This avoids a lot of tedious origin building. Specifically: - next_ty_var{,_id_in_universe,_in_universe}: now take `Span` instead of `TypeVariableOrigin` - next_ty_var_with_origin: added - next_const_var{,_in_universe}: takes Span instead of ConstVariableOrigin - next_const_var_with_origin: added - next_region_var, next_region_var_in_universe: these are unchanged, still take RegionVariableOrigin The API inconsistency (ty/const vs region) seems worth it for the large conciseness improvements.
2024-05-09always use `GenericArgsRef`lcnr-6/+10
2024-05-08Rollup merge of #124876 - nnethercote:rm-use-crate-rustc_foo, r=compiler-errorsMatthias Krüger-7/+4
Simplify `use crate::rustc_foo::bar` occurrences. They can just be written as `use rustc_foo::bar`, which is far more standard. (I didn't even know that a `crate::` prefix was valid.) r? ``@eholk``