about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty
AgeCommit message (Collapse)AuthorLines
2025-08-20Rollup merge of #145623 - compiler-errors:pretty-async-name, r=wesleywiserJacob Pratt-3/+13
Pretty print the name of an future from calling async closure Fixes https://github.com/rust-lang/rust/issues/145606 by introducing a way to customize the path rendering of async closures' futures in the pretty printer API.
2025-08-19Pretty print the name of an future from calling async closureMichael Goulet-3/+13
2025-08-19Rollup merge of #145338 - lcnr:coroutine-witness-yikes, r=compiler-errors许杰友 Jieyou Xu (Joe)-2/+38
actually provide the correct args to coroutine witnesses rust-lang/rust#145194 accidentally provided all arguments of the closure to the witness, but the witness only takes the generic parameters of the defining scope: https://github.com/rust-lang/rust/blob/216cdb7b22b637cef75b7225c642cb7587192643/compiler/rustc_hir_typeck/src/closure.rs#L164 Fixes rust-lang/rust#145288
2025-08-17Auto merge of #145284 - nnethercote:type_name-print-regions, r=lcnrbors-7/+7
Print regions in `type_name`. Currently they are skipped, which is a bit weird, and it sometimes causes malformed output like `Foo<>` and `dyn Bar<, A = u32>`. Most regions are erased by the time `type_name` does its work. So all regions are now printed as `'_` in non-optional places. Not perfect, but better than the status quo. `c_name` is updated to trim lifetimes from MIR pass names, so that the `PASS_NAMES` sanity check still works. It is also renamed as `simplify_pass_type_name` and made non-const, because it doesn't need to be const and the non-const implementation is much shorter. The commit also renames `should_print_region` as `should_print_optional_region`, which makes it clearer that it only applies to some regions. Fixes rust-lang/rust#145168. r? `@lcnr`
2025-08-15Auto merge of #144591 - RalfJung:pattern-valtrees, r=BoxyUwUbors-9/+19
Patterns: represent constants as valtrees Const patterns are always valtrees now. Let's represent that in the types. We use `ty::Value` for this since it nicely packages value and type, and has some convenient methods. Cc `@Nadrieril` `@BoxyUwU`
2025-08-14Print regions in `type_name`.Nicholas Nethercote-7/+7
Currently they are skipped, which is a bit weird, and it sometimes causes malformed output like `Foo<>` and `dyn Bar<, A = u32>`. Most regions are erased by the time `type_name` does its work. So all regions are now printed as `'_` in non-optional places. Not perfect, but better than the status quo. `c_name` is updated to trim lifetimes from MIR pass names, so that the `PASS_NAMES` sanity check still works. It is also renamed as `simplify_pass_type_name` and made non-const, because it doesn't need to be const and the non-const implementation is much shorter. The commit also renames `should_print_region` as `should_print_optional_region`, which makes it clearer that it only applies to some regions. Fixes #145168.
2025-08-14Rollup merge of #145266 - camsteffen:reduce-queries, r=petrochenkovGuillaume Gomez-5/+34
Reduce some queries around associated items
2025-08-14Apply suggestions from code reviewRalf Jung-1/+1
Co-authored-by: Boxy <rust@boxyuwu.dev>
2025-08-14avoid unnecessary type sanity checksRalf Jung-8/+4
2025-08-14use ty::Value instead of manual pairs of types and valtreesRalf Jung-4/+10
2025-08-14pattern testing: store constants as valtreesRalf Jung-9/+17
2025-08-13Rollup merge of #144949 - nnethercote:more-Printer-cleanups, r=davidtwcoGuillaume Gomez-81/+110
More `Printer` cleanups A sequel to rust-lang/rust#144776. r? ```@davidtwco```
2025-08-13Cleanup assoc parent utilsCameron Steffen-5/+34
2025-08-13`fn new_coroutine_witness_for_coroutine` woopslcnr-0/+33
2025-08-13check args in new_coroutine_witnesslcnr-2/+5
2025-08-10Rollup merge of #145147 - fee1-dead-contrib:push-mxxpmlpmzmsz, r=compiler-errorsStuart Cook-5/+5
rename `TraitRef::from_method` to `from_assoc` also add a note to `GenericArgs::truncate_to`
2025-08-09Auto merge of #145142 - Zalathar:rollup-oi6s8kg, r=Zalatharbors-0/+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-09rename `TraitRef::from_method` to `from_assoc`Deadbeef-5/+5
also add a note to `GenericArgs::truncate_to`
2025-08-09Rollup merge of #145097 - lcnr:type-foldable-yeet, r=wesleywiserStuart Cook-0/+2
remove unnecessary `TypeFoldable` impls
2025-08-09Auto merge of #143376 - dianne:guard-scope, r=matthewjasperbors-1/+1
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-08Rollup merge of #144192 - RalfJung:atomicrmw-ptr, r=nikicTrevor Gross-5/+12
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-08Rollup merge of #144039 - estebank:short-paths, r=fee1-deadTrevor Gross-1/+1
Use `tcx.short_string()` in more diagnostics `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).
2025-08-08remove unnecessary `TypeFoldable` implslcnr-0/+2
2025-08-08Rollup merge of #145009 - jackh726:ra-next-solver-changes, r=compiler-errorsStuart Cook-11/+1
A couple small changes for rust-analyzer next-solver work Originally written by `@flodiebold`
2025-08-07add a scope for `if let` guard temporaries and bindingsdianne-1/+1
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-1/+1
`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-07Add a missing UpcastFrom impl in rustc_type_irFlorian Diebold-11/+1
2025-08-06Add support for shortening `Instance` and use itEsteban Küber-110/+86
Replace ad-hoc type path shortening logic for recursive mono instantiation errors to use `tcx.short_string()` instead.
2025-08-06Rename some `PrettyPrinter` methods.Nicholas Nethercote-26/+26
More consistency.
2025-08-06Rename some `Printer` methods.Nicholas Nethercote-30/+37
I find these name clearer, and starting them all with `print_` makes things more consistent.
2025-08-06Move `should_truncate` from trait `Printer` to sub-trait `PrettyPrinter`.Nicholas Nethercote-8/+8
It's not used in `Printer`.
2025-08-06Add comments to `Printer`.Nicholas Nethercote-17/+39
These details took me some time to work out.
2025-08-05Clarify `value_path_str_with_args`.Nicholas Nethercote-4/+4
The use of `print_value_path` means the value namespace is always used and the `guess_def_namespace` call is unnecessary. This commit removes the `guess_def_namespace` call and hard-codes `ValueNS`. It also changes the `print_value_path` to `print_def_path` for consistency with `def_path_str_with_args`.
2025-08-05Rollup merge of #144817 - WaffleLapkin:reject-referety, r=UrgauSamuel Tardieu-1/+1
Properly reject tail calls to `&FnPtr` or `&FnDef` Fixes rust-lang/rust#144795
2025-08-05Rollup merge of #144776 - nnethercote:Printer-cleanups, r=cjgillotSamuel Tardieu-511/+485
`Printer` cleanups The trait `Printer` is implemented by six types, and the sub-trait `PrettyPrinter` is implemented by three of those types. The traits and the impls are complex and a bit of a mess. This PR starts to clean them up. r? ``@davidtwco``
2025-08-04drive-by cleanup: fix outdated documentationWaffle Lapkin-1/+1
2025-08-04Avoid some code duplication.Nicholas Nethercote-6/+1
`print_binder` can call `wrap_binder`.
2025-08-03Rollup merge of #144822 - Zalathar:hash-owner-nodes, r=compiler-errorsSamuel Tardieu-1/+1
Return a struct with named fields from `hash_owner_nodes` While looking through this code for other reasons, I noticed a nice opportunity to return a struct with named fields instead of a tuple. The first patch also introduces an early-return to flatten the rest of `hash_owner_nodes`. There are further changes that could potentially be made here (renaming things, `Option<Hashes>` instead of optional fields), but I'm not deeply familiar with this code so I didn't want to disturb the calling code too much.
2025-08-03Remove unused arg from `path_append_impl`.Nicholas Nethercote-8/+1
None of the impls use it.
2025-08-03Remove `p!`.Nicholas Nethercote-362/+370
It's a cryptic macro that makes some things slightly more concise in `PrettyPrinter`. E.g. if you declare `define_scope_printer!(p)` in a scope you can then call `p! to get these transformations: ``` p!("foo"); --> write!(p, "foo")?; p!(print(ty)); --> ty.print(p)?; p!(method(args)); --> p.method(args)?; ``` You can also chain calls, e.g.: ``` p!("foo", print(ty)); --> write!(p, "foo")?; ty.print(p)?; ``` Ultimately this doesn't seem worth it. The macro definition is hard to read, the call sites are hard to read, `define_scope_printer!` is pretty gross, and the code size reductions are small. Tellingly, many normal `write!` and `print` calls are sprinkled throughout the code, probably because people have made modifications and didn't want to use or understand how to use `p!`. This commit removes it.
2025-08-03Rename `Printer` variables.Nicholas Nethercote-139/+139
Currently they are mostly named `cx`, which is a terrible name for a type that impls `Printer`/`PrettyPrinter`, and is easy to confuse with other types like `TyCtxt`. This commit changes them to `p`. A couple of existing `p` variables had to be renamed to make way.
2025-08-03Inline and remove two `FmtPrinter` methods.Nicholas Nethercote-34/+12
They each have a single call site.
2025-08-03Auto merge of #144677 - nnethercote:bound-const-handling, r=lcnrbors-57/+64
Improve bound const handling A few changes to make const handling more similar to type handling. r? `@compiler-errors` -errors
2025-08-02Return a struct with named fields from `hash_owner_nodes`Zalathar-1/+1
2025-08-01Auto merge of #144458 - compiler-errors:no-witness-mini, r=lcnrbors-25/+12
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-25/+12
2025-07-31Rollup merge of #144726 - jdonszelmann:move-attr-data-structures, r=lcnrJana Dönszelmann-11/+12
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-31Rollup merge of #144712 - nnethercote:dedup-num-types, r=fmeaseJana Dönszelmann-53/+0
Deduplicate `IntTy`/`UintTy`/`FloatTy`. 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. r? `@fmease`
2025-07-31remove rustc_attr_data_structuresJana Dönszelmann-11/+12
2025-07-31Deduplicate `IntTy`/`UintTy`/`FloatTy`.Nicholas Nethercote-53/+0
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.