about summary refs log tree commit diff
path: root/compiler/rustc_hir_analysis/src
AgeCommit message (Collapse)AuthorLines
2025-08-20make `prefetch` intrinsics safeFolkert de Vries-1/+5
2025-08-15Rollup merge of #145235 - compiler-errors:comment, r=BoxyUwUStuart Cook-33/+1
Minor `[const]` tweaks Self explanatory
2025-08-14Complete functionality and general cleanupMarcelo Domínguez-2/+1
2025-08-14Basic implementation of `autodiff` intrinsicMarcelo Domínguez-1/+4
2025-08-13Cleanup assoc parent utilsCameron Steffen-5/+4
2025-08-11Propagate TraitImplHeader to hirCameron Steffen-90/+91
2025-08-11Rollup merge of #135331 - fmease:ban-assoc-ty-unbounds, r=lcnrStuart Cook-5/+3
Reject relaxed bounds inside associated type bounds (ATB) **Reject** relaxed bounds — most notably `?Sized` — inside associated type bounds `TraitRef<AssocTy: …>`. This was previously accepted without warning despite being incorrect: ATBs are *not* a place where we perform *sized elaboration*, meaning `TraitRef<AssocTy: …>` does *not* elaborate to `TraitRef<AssocTy: Sized + …>` if `…` doesn't contain `?Sized`. Therefore `?Sized` is meaningless. In no other (stable) place do we (intentionally) allow relaxed bounds where we don't also perform sized elab, this is highly inconsistent and confusing! Another point of comparison: For the desugared `$SelfTy: TraitRef, $SelfTy::AssocTy: …` we don't do sized elab either (and thus also don't allow relaxed bounds). Moreover — as I've alluded to back in https://github.com/rust-lang/rust/pull/135841#pullrequestreview-2619462717 — some later validation steps only happen during sized elaboration during HIR ty lowering[^1]. Namely, rejecting duplicates (e.g., `?Trait + ?Trait`) and ensuring that `Trait` in `?Trait` is equal to `Sized`[^2]. As you can probably guess, on stable/master we don't run these checks for ATBs (so we allow even more nonsensical bounds like `Iterator<Item: ?Copy>` despite T-types's ruling established in the FCP'ed rust-lang/rust#135841). This PR rectifies all of this. I cratered this back in 2025-01-10 with (allegedly) no regressions found ([report](https://github.com/rust-lang/rust/pull/135331#issuecomment-2585330783), [its analysis](https://github.com/rust-lang/rust/pull/135331#issuecomment-2585356422)). [However a contributor manually found two occurrences](https://github.com/rust-lang/rust/issues/135229#issuecomment-2581832852) of `TraitRef<AssocTy: ?Sized>` in small hobby projects (presumably via GH code search). I immediately sent downstream PRs: https://github.com/Gui-Yom/turbo-metrics/pull/14, https://github.com/ireina7/summon/pull/1 (however, the owners have showed no reaction so far). I'm leaning towards banning these forms **without a FCW** because a FCW isn't worth the maintenance cost[^3]. Note that associated type bounds were stabilized in 1.79.0 (released 2024-06-13 which is 13 months ago), so the proliferation of ATBs shouldn't be that high yet. If you think we should do another crater run since the last one was 6 months ago, I'm fine with that. Fixes rust-lang/rust#135229. [^1]: I consider this a flaw in the implementation and [I've already added a huge FIXME](https://github.com/rust-lang/rust/blob/82a02aefe07092c737c852daccebf49ca25507e3/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs#L195-L207). [^2]: To be more precise, if the internal flag `-Zexperimental-default-bounds` is provided other "default traits" (needs internal feature `lang_items`) are permitted as well (cc closely related internal feature: `more_maybe_bounds`). [^3]: Having to track this and adding an entire lint whose remnants would remain in the code base forever (we never *fully* remove lints).
2025-08-11Remove unnecessary trait predicate eq functionMichael Goulet-33/+1
2025-08-09Auto merge of #145142 - Zalathar:rollup-oi6s8kg, r=Zalatharbors-3/+2
Rollup of 23 pull requests Successful merges: - rust-lang/rust#141658 (rustdoc search: prefer stable items in search results) - rust-lang/rust#141828 (Add diagnostic explaining STATUS_STACK_BUFFER_OVERRUN not only being used for stack buffer overruns if link.exe exits with that exit code) - rust-lang/rust#144823 (coverage: Extract HIR-related helper code out of the main module) - rust-lang/rust#144883 (Remove unneeded `drop_in_place` calls) - rust-lang/rust#144923 (Move several more float tests to floats/mod.rs) - rust-lang/rust#144988 (Add annotations to the graphviz region graph on region origins) - rust-lang/rust#145010 (Couple of minor abi handling cleanups) - rust-lang/rust#145017 (Explicitly disable vector feature on s390x baseline of bad-reg test) - rust-lang/rust#145027 (Optimize `char::is_alphanumeric`) - rust-lang/rust#145050 (add member constraints tests) - rust-lang/rust#145073 (update enzyme submodule to handle llvm 21) - rust-lang/rust#145080 (Escape diff strings in MIR dataflow graphviz) - rust-lang/rust#145082 (Fix some bad formatting in `-Zmacro-stats` output.) - rust-lang/rust#145083 (Fix cross-compilation of Cargo) - rust-lang/rust#145096 (Fix wasm target build with atomics feature) - rust-lang/rust#145097 (remove unnecessary `TypeFoldable` impls) - rust-lang/rust#145100 (Rank doc aliases lower than equivalently matched items) - rust-lang/rust#145103 (rustc_metadata: remove unused private trait impls) - rust-lang/rust#145115 (defer opaque type errors, generally greatly reduce tainting) - rust-lang/rust#145119 (rustc_public: fix missing parenthesis in pretty discriminant) - rust-lang/rust#145124 (Recover `for PAT = EXPR {}`) - rust-lang/rust#145132 (Refactor map_unit_fn lint) - rust-lang/rust#145134 (Reduce indirect assoc parent queries) r? `@ghost` `@rustbot` modify labels: rollup
2025-08-09Rollup merge of #145134 - camsteffen:indirect-assoc-parent, r=cjgillotStuart Cook-3/+2
Reduce indirect assoc parent queries Simplify some code that uses multiple queries to get the parent of an associated item.
2025-08-09Auto merge of #143376 - dianne:guard-scope, r=matthewjasperbors-0/+5
add a scope for `if let` guard temporaries and bindings This fixes my concern with `if let` guard drop order, namely that the guard's bindings and temporaries were being dropped after their arm's pattern's bindings, instead of before (https://github.com/rust-lang/rust/pull/141295#issuecomment-2968975596). The guard's bindings and temporaries now live in a new scope, which extends until (but not past) the end of the arm, guaranteeing they're dropped before the arm's pattern's bindings. This only introduces a new scope for match arms with guards. Perf results (https://github.com/rust-lang/rust/pull/143376#issuecomment-3034922617) seemed to indicate there wasn't a significant hit to introduce a new scope on all match arms, but guard patterns (rust-lang/rust#129967) will likely benefit from only adding new scopes when necessary (with some patterns requiring multiple nested scopes). Tracking issue for `if_let_guard`: rust-lang/rust#51114 Tests are adapted from examples by `@traviscross,` `@est31,` and myself on rust-lang/rust#141295.
2025-08-08Reduce indirect assoc parent queriesCameron Steffen-3/+2
2025-08-08Rollup merge of #144192 - RalfJung:atomicrmw-ptr, r=nikicTrevor Gross-6/+6
atomicrmw on pointers: move integer-pointer cast hacks into backend Conceptually, we want to have atomic operations on pointers of the form `fn atomic_add(ptr: *mut T, offset: usize, ...)`. However, LLVM does not directly support such operations (https://github.com/llvm/llvm-project/issues/120837), so we have to cast the `offset` to a pointer somewhere. This PR moves that hack into the LLVM backend, so that the standard library, intrinsic, and Miri all work with the conceptual operation we actually want. Hopefully, one day LLVM will gain a way to represent these operations without integer-pointer casts, and then the hack will disappear entirely. Cc ```@nikic``` -- this is the best we can do right now, right? Fixes https://github.com/rust-lang/rust/issues/134617
2025-08-07only introduce a guard scope for arms with guardsdianne-5/+5
2025-08-07add a scope for `if let` guard temporaries and bindingsdianne-0/+5
This ensures `if let` guard temporaries and bindings are dropped before the match arm's pattern's bindings.
2025-08-07Use `tcx.short_string()` in more diagnosticsEsteban Küber-2/+3
`TyCtxt::short_string` ensures that user visible type paths aren't overwhelming on the terminal output, and properly saves the long name to disk as a side-channel. We already use these throughout the compiler and have been using them as needed when users find cases where the output is verbose. This is a proactive search of some cases to use `short_string`. We add support for shortening the path of "trait path only". Every manual use of `short_string` is a bright marker that that error should be using structured diagnostics instead (as they have proper handling of long types without the maintainer having to think abou tthem). When we don't actually print out a shortened type we don't need the "use `--verbose`" note. On E0599 show type identity to avoid expanding the receiver's generic parameters. Unify wording on `long_ty_path` everywhere.
2025-08-06Fortify generic param default checksLeón Orell Valerian Liehr-99/+101
2025-08-04Rollup merge of #144694 - compiler-errors:with-self-ty, r=SparrowLiiStuart Cook-3/+3
Distinguish prepending and replacing self ty in predicates There are two kinds of functions called `with_self_ty`: 1. Prepends the `Self` type onto an `ExistentialPredicate` which lacks it in its internal representation. 2. Replaces the `Self` type of an existing predicate, either for diagnostics purposes or in the new trait solver when normalizing that self type. This PR distinguishes these two because I often want to only grep for one of them. Namely, let's call it `with_replaced_self_ty` when all we're doing is replacing the self type.
2025-08-03Auto merge of #144704 - compiler-errors:explode-wf, r=lcnrbors-8/+8
expand WF obligations when checking method calls Don't wrap a bunch of signatures in `FnPtr` then check their WF; instead, check the WFness of each input/output separately. This is useful for the new trait solver, since because we stall on root obligations we end up needing to repeatedly recompute the WFness of possibly very large function signature types if it ends up bottoming out in ambiguity. This may also give us more chances to hit the WF fast path for certain types like built-ins. Finally, this just seems conceptually correct to do. There's nothing conceptually that suggests that wrapping the function signature in an fn pointer makes sense at all to do; I'm guessing that it was just convenient so that we didn't have to register WF obligations in a loop, but it doesn't affect the readability of this code at all.
2025-08-03Auto merge of #144677 - nnethercote:bound-const-handling, r=lcnrbors-10/+12
Improve bound const handling A few changes to make const handling more similar to type handling. r? `@compiler-errors` -errors
2025-08-02Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=AmanieuSamuel Tardieu-1/+1
Improve formatting of doc code blocks We don't currently apply automatic formatting to doc comment code blocks. As a result, it has built up various idiosyncracies, which make such automatic formatting difficult. Some of those idiosyncracies also make things harder for human readers or other tools. This PR makes a few improvements to doc code formatting, in the hopes of making future automatic formatting easier, as well as in many cases providing net readability improvements. I would suggest reading each commit separately, as each commit contains one class of changes.
2025-08-01Auto merge of #144458 - compiler-errors:no-witness-mini, r=lcnrbors-9/+3
Remove the witness type from coroutine *args* (without actually removing the type) This does as much of rust-lang/rust#144157 as we can without having to break rust-lang/rust#143545 and/or introduce some better way of handling higher ranked assumptions. Namely, it: * Stalls coroutines based off of the *coroutine* type rather than the witness type. * Reworks the dtorck constraint hack to not rely on the witness type. * Removes the witness type from the args of the coroutine, eagerly creating the type for nested obligations when needed (auto/clone impls). I'll experiment with actually removing the witness type in a follow-up. r? lcnr
2025-07-31Remove the witness type from coroutine argsMichael Goulet-9/+3
2025-07-31Rollup merge of #144726 - jdonszelmann:move-attr-data-structures, r=lcnrJana Dönszelmann-13/+15
merge rustc_attr_data_structures into rustc_hir this move was discussed on zulip: [#t-compiler > attribute parsing rework @ 💬](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/attribute.20parsing.20rework/near/528530091) Many PRs in the attribute rework depend on this move.
2025-07-31remove rustc_attr_data_structuresJana Dönszelmann-13/+15
2025-07-31Deduplicate `IntTy`/`UintTy`/`FloatTy`.Nicholas Nethercote-3/+3
There are identical definitions in `rustc_type_ir` and `rustc_ast`. This commit removes them and places a single definition in `rustc_ast_ir`. This requires adding `rust_span` as a dependency of `rustc_ast_ir`, but means a bunch of silly conversion functions can be removed. The one annoying wrinkle is that the old version had differences in their `Debug` impls, e.g. one printed `u32` while the other printed `U32`. Some compiler error messages rely on the former (yuk), and some clippy output depends on the latter. So the commit also changes clippy to not rely on `Debug` and just implement what it needs itself.
2025-07-31Make const bound handling more like types/regions.Nicholas Nethercote-10/+12
Currently there is `Ty` and `BoundTy`, and `Region` and `BoundRegion`, and `Const` and... `BoundVar`. An annoying inconsistency. This commit repurposes the existing `BoundConst`, which was barely used, so it's the partner to `Const`. Unlike `BoundTy`/`BoundRegion` it lacks a `kind` field but it's still nice to have because it makes the const code more similar to the ty/region code everywhere. The commit also removes `impl From<BoundVar> for BoundTy`, which has a single use and doesn't seem worth it. These changes fix the "FIXME: We really should have a separate `BoundConst` for consts".
2025-07-30expand WF obligations when checking method callsMichael Goulet-8/+8
2025-07-30Distinguish appending and replacing self ty in predicatesMichael Goulet-3/+3
2025-07-28Rename impl_of_method -> impl_of_assocCameron Steffen-1/+1
2025-07-28Rename trait_of_item -> trait_of_assocCameron Steffen-1/+1
2025-07-28Auto merge of #144469 - Kivooeo:chains-cleanup, r=SparrowLiibors-27/+21
Some `let chains` clean-up Not sure if this kind of clean-up is welcoming because of size, but I decided to try out one r? compiler
2025-07-28use let chains in ast, borrowck, codegen, const_evalKivooeo-27/+21
2025-07-27check_static_item: explain should_check_for_sync choicesRalf Jung-3/+9
2025-07-27Rollup merge of #144226 - cjgillot:known-panics-panics, r=oli-obkMatthias Krüger-8/+25
Do not assert layout in KnownPanicsLint. Fixes rust-lang/rust#121176 Fixes rust-lang/rust#129109 Fixes rust-lang/rust#130970 Fixes rust-lang/rust#131347 Fixes rust-lang/rust#139872 Fixes rust-lang/rust#140332
2025-07-26Do not check Sync during type_of.Camille GILLOT-4/+7
2025-07-25Improve and regularize comment placement in doc codeJosh Triplett-1/+1
Because doc code does not get automatically formatted, some doc code has creative placements of comments that automatic formatting can't handle. Reformat those comments to make the resulting code support standard Rust formatting without breaking; this is generally an improvement to readability as well. Some comments are not indented to the prevailing indent, and are instead aligned under some bit of code. Indent them to the prevailing indent, and put spaces *inside* the comments to align them with code. Some comments span several lines of code (which aren't the line the comment is about) and expect alignment. Reformat them into one comment not broken up by unrelated intervening code. Some comments are placed on the same line as an opening brace, placing them effectively inside the subsequent block, such that formatting would typically format them like a line of that block. Move those comments to attach them to what they apply to. Some comments are placed on the same line as a one-line braced block, effectively attaching them to the closing brace, even though they're about the code inside the block. Reformat to make sure the comment will stay on the same line as the code it's commenting.
2025-07-25Check statics' type in type_of.Camille GILLOT-6/+20
2025-07-25Rollup merge of #144390 - oli-obk:arbitrary-enum-discrs, r=SparrowLiiMatthias Krüger-9/+29
Remove dead code and extend test coverage and diagnostics around it I was staring a bit at the `dont_niche_optimize_enum` variable and figured out that part of it is dead code (at least today it is). I changed the diagnostic and test around the code that makes that part dead code, so everything that makes removing that code sound is visible in this PR
2025-07-24Rollup merge of #144335 - fmease:no-angle-no-colon, r=SparrowLiiLeón Orell Valerian Liehr-3/+16
Don't suggest assoc ty bound on non-angle-bracketed problematic assoc ty binding Fixes https://github.com/rust-lang/rust/issues/140543.
2025-07-24Remove dead code and extend test coverage and diagnostics around itOli Scherer-9/+29
We lost the following comment during refactorings: The current code for niche-filling relies on variant indices instead of actual discriminants, so enums with explicit discriminants (RFC 2363) would misbehave.
2025-07-23atomicrmw on pointers: move integer-pointer cast hacks into backendRalf Jung-6/+6
2025-07-23Don't suggest assoc ty bound on non-angle-bracketed problematic assoc ty bindingLeón Orell Valerian Liehr-3/+16
2025-07-22Rollup merge of #143373 - cjgillot:bare-unused-trait-imports, r=petrochenkovMatthias Krüger-1/+1
Unquerify maybe_unused_trait_imports. Based on https://github.com/rust-lang/rust/pull/143247 r? ```@ghost``` for perf
2025-07-20Unquerify maybe_unused_trait_imports.Camille GILLOT-1/+1
2025-07-20Reject relaxed bounds inside associated type boundsLeón Orell Valerian Liehr-5/+3
2025-07-20Rollup merge of #144142 - compiler-errors:itib, r=fmeaseMatthias Krüger-0/+8
Add implicit sized bound to trait ascription types r? ```@fmease``` or reassign Thanks for catching this :) Fixes rust-lang/rust#144135
2025-07-19Auto merge of #144166 - matthiaskrgr:rollup-wccepuo, r=matthiaskrgrbors-9/+9
Rollup of 10 pull requests Successful merges: - rust-lang/rust#141076 (fix Zip unsoundness (again)) - rust-lang/rust#142444 (adding run-make test to autodiff) - rust-lang/rust#143704 (Be a bit more careful around exotic cycles in in the inliner) - rust-lang/rust#144073 (Don't test panic=unwind in panic_main.rs on Fuchsia) - rust-lang/rust#144083 (miri sleep tests: increase slack) - rust-lang/rust#144092 (bootstrap: Detect musl hosts) - rust-lang/rust#144098 (Do not lint private-in-public for RPITIT) - rust-lang/rust#144103 (Rename `emit_unless` to `emit_unless_delay`) - rust-lang/rust#144108 (Ignore tests/run-make/link-eh-frame-terminator/rmake.rs when cross-compiling) - rust-lang/rust#144115 (fix outdated comment) r? `@ghost` `@rustbot` modify labels: rollup
2025-07-19rename `emit_unless` to `emit_unless_delay`xizheyin-9/+9
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-07-18Rollup merge of #142693 - fmease:unbound-bettering, r=compiler-errorsMatthias Krüger-158/+105
More robustly deal with relaxed bounds and improve their diagnostics Scaffolding for https://github.com/rust-lang/rust/issues/135229 (CC https://github.com/rust-lang/rust/pull/135331) Fixes https://github.com/rust-lang/rust/issues/136944 (6th commit). Fixes https://github.com/rust-lang/rust/issues/142718 (8th commit).