about summary refs log tree commit diff
path: root/compiler/rustc_middle/src/ty
AgeCommit message (Collapse)AuthorLines
2024-03-27Remove `Partial/Ord` from `AdtDef`Oli Scherer-16/+1
2024-03-27Remove `Partial/Ord` from `BoundRegion`Oli Scherer-12/+10
2024-03-27Remove `Ord` from `BoundTy`Oli Scherer-3/+3
2024-03-27Remove `Ord` from `Binder`Oli Scherer-1/+1
2024-03-27Remove `Ord` from `Ty`, `Const`, and `Region`Oli Scherer-29/+16
2024-03-27Implement `mut ref`/`mut ref mut`Jules Bertholet-31/+16
2024-03-27Use a `dyn Debug` trait object instead of a closure.Oli Scherer-2/+10
Simplifies the API a bit.
2024-03-27Add a `CurrentGcx` type to let the deadlock handler access `TyCtxt`John Kåre Alsaker-3/+54
2024-03-27Rollup merge of #123021 - compiler-errors:coroutine-layout-lol, r=oli-obkGuillaume Gomez-4/+38
Make `TyCtxt::coroutine_layout` take coroutine's kind parameter For coroutines that come from coroutine-closures (i.e. async closures), we may have two kinds of bodies stored in the coroutine; one that takes the closure's captures by reference, and one that takes the captures by move. These currently have identical layouts, but if we do any optimization for these layouts that are related to the upvars, then they will diverge -- e.g. https://github.com/rust-lang/rust/pull/120168#discussion_r1536943728. This PR relaxes the assertion I added in #121122, and instead make the `TyCtxt::coroutine_layout` method take the `coroutine_kind_ty` argument from the coroutine, which will allow us to differentiate these by-move and by-ref bodies.
2024-03-27Make `def_path_hash_to_def_id` a hookOli Scherer-5/+1
2024-03-26Rollup merge of #122835 - compiler-errors:deref-pure, r=NadrierilMatthias Krüger-0/+25
Require `DerefMut` and `DerefPure` on `deref!()` patterns when appropriate Waiting on the deref pattern syntax pr to merge r? nadrieril
2024-03-26ignore uncaptured lifetimes when checking opaquesAli MJ Al-Nasrawy-0/+32
2024-03-25Extract helper, fix comment on DerefPureMichael Goulet-0/+25
2024-03-25Rollup merge of #123044 - compiler-errors:instance, r=oli-obkJubilee-4/+4
`Instance` is `Copy` No reason to take it by value; it was confusing ``@rcvalle`` to see it being mutated when it's also being passed by ref in some places.
2024-03-25Instance is CopyMichael Goulet-4/+4
2024-03-25In `pretty_print_type()`, print `async fn` futures' paths instead of spans.Kevin Reid-5/+13
This makes `-Zprint-type-sizes`'s output easier to read, because the name of an `async fn` is more immediately recognizable than its span. I also deleted the comment "FIXME(eddyb) should use `def_span`." because it appears to have already been fixed by commit 67727aa7c31a24ea73a91a9134c3653fae8209ab.
2024-03-24Relax validation nowMichael Goulet-2/+0
2024-03-24Require coroutine kind type to be passed to TyCtxt::coroutine_layoutMichael Goulet-4/+40
2024-03-23Add+Use `mir::BinOp::Cmp`Scott McMurray-0/+7
2024-03-23rename MIR int2ptr casts to match library nameRalf Jung-1/+1
2024-03-22Auto merge of #122900 - matthiaskrgr:rollup-nls90mb, r=matthiaskrgrbors-35/+60
Rollup of 8 pull requests Successful merges: - #114009 (compiler: allow transmute of ZST arrays with generics) - #122195 (Note that the caller chooses a type for type param) - #122651 (Suggest `_` for missing generic arguments in turbofish) - #122784 (Add `tag_for_variant` query) - #122839 (Split out `PredicatePolarity` from `ImplPolarity`) - #122873 (Merge my contributor emails into one using mailmap) - #122885 (Adjust better spastorino membership to triagebot's adhoc_groups) - #122888 (add a couple more tests) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-22Auto merge of #122852 - compiler-errors:raw-ptr, r=lcnrbors-74/+77
Remove `TypeAndMut` from `ty::RawPtr` variant, make it take `Ty` and `Mutability` Pretty much mechanically converting `ty::RawPtr(ty::TypeAndMut { ty, mutbl })` to `ty::RawPtr(ty, mutbl)` and its fallout. r? lcnr cc rust-lang/types-team#124
2024-03-22Rollup merge of #122839 - compiler-errors:predicate-polarity, r=lcnrMatthias Krüger-34/+54
Split out `PredicatePolarity` from `ImplPolarity` Because having to deal with a third `Reservation` level in all the trait solver code is kind of weird. r? `@lcnr` or `@oli-obk`
2024-03-22Rollup merge of #114009 - dvdhrm:pr/transmzst, r=pnkfelixMatthias Krüger-1/+6
compiler: allow transmute of ZST arrays with generics Extend the `SizeSkeleton` evaluator to shortcut zero-sized arrays, thus considering `[T; 0]` to have a compile-time fixed-size of 0. The existing evaluator already deals with generic arrays under the feature-guard `transmute_const_generics`. However, it merely allows comparing fixed-size types with fixed-size types, and generic types with generic types. For generic types, it merely compares whether their arguments match (ordering them first). Even if their exact sizes are not known at compile time, it can ensure that they will eventually be the same. This patch extends this by shortcutting the size-evaluation of zero sized arrays and thus allowing size comparisons of `()` with `[T; 0]`, where one contains generics and the other does not. This code is guarded by `transmute_const_generics` (#109929), even though it is unclear whether it should be. However, this assumes that a separate stabilization PR is required to move this out of the feature guard. Initially reported in #98104.
2024-03-22Auto merge of #122580 - saethlin:compiler-builtins-can-panic, r=pnkfelixbors-0/+6
"Handle" calls to upstream monomorphizations in compiler_builtins This is pretty cooked, but I think it works. compiler-builtins has a long-standing problem that at link time, its rlib cannot contain any calls to `core`. And yet, in codegen we _love_ inserting calls to symbols in `core`, generally from various panic entrypoints. I intend this PR to attack that problem as completely as possible. When we generate a function call, we now check if we are generating a function call from `compiler_builtins` and whether the callee is a function which was not lowered in the current crate, meaning we will have to link to it. If those conditions are met, actually generating the call is asking for a linker error. So we don't. If the callee diverges, we lower to an abort with the same behavior as `core::intrinsics::abort`. If the callee does not diverge, we produce an error. This means that compiler-builtins can contain panics, but they'll SIGILL instead of panicking. I made non-diverging calls a compile error because I'm guessing that they'd mostly get into compiler-builtins by someone making a mistake while working on the crate, and compile errors are better than linker errors. We could turn such calls into aborts as well if that's preferred.
2024-03-22Further simplificationsMichael Goulet-36/+5
2024-03-22Split out ImplPolarity and PredicatePolarityMichael Goulet-22/+73
2024-03-22Make RawPtr take Ty and Mutbl separatelyMichael Goulet-22/+20
2024-03-22Programmatically convert some of the pat ctorsMichael Goulet-20/+17
2024-03-22Ty::new_ref and Ty::new_ptr stop using TypeAndMutMichael Goulet-10/+15
2024-03-22Remove TypeAndMut from relateMichael Goulet-29/+32
2024-03-22Rollup merge of #122820 - oli-obk:no_ord_def_id, r=estebankMatthias Krüger-64/+3
Stop using `<DefId as Ord>` in various diagnostic situations work towards https://github.com/rust-lang/rust/issues/90317 Reverts part of https://github.com/rust-lang/rust/pull/106281, as it sorts constants and that's problematic since it can contain `ParamConst`, which contains `DefId`s
2024-03-21Rollup merge of #122799 - estebank:issue-122569, r=fee1-deadMatthias Krüger-6/+22
Replace closures with `_` when suggesting fully qualified path for method call ``` error[E0283]: type annotations needed --> $DIR/into-inference-needs-type.rs:12:10 | LL | .into()?; | ^^^^ | = note: cannot satisfy `_: From<...>` = note: required for `FilterMap<...>` to implement `Into<_>` help: try using a fully qualified path to specify the expected types | LL ~ let list = <FilterMap<Map<std::slice::Iter<'_, &str>, _>, _> as Into<T>>::into(vec LL | .iter() LL | .map(|s| s.strip_prefix("t")) LL ~ .filter_map(Option::Some))?; | ``` Fix #122569.
2024-03-21Rollup merge of #122358 - compiler-errors:bound-regions-in-generator, r=lcnrMatthias Krüger-2/+34
Don't ICE when encountering bound regions in generator interior type I'm pretty sure this meant to say "`has_free_regions`", probably just a typo in 4a4fc3bb5b1efe6857cf5d6c0b554ff36b966996. We can have bound regions (because we only convert non-bound regions into existential regions in generator interiors), but we can't have (non-ReErased) free regions. r? lcnr
2024-03-21Sorting arbitrary constants should not be done, as it relies on `DefId` ↵Oli Scherer-64/+3
ordering, which breaks incremental compilation.
2024-03-21Auto merge of #121123 - compiler-errors:item-assumptions, r=oli-obkbors-1/+1
Split an item bounds and an item's super predicates This is the moral equivalent of #107614, but instead for predicates this applies to **item bounds**. This PR splits out the item bounds (i.e. *all* predicates that are assumed to hold for the alias) from the item *super predicates*, which are the subset of item bounds which share the same self type as the alias. ## Why? Much like #107614, there are places in the compiler where we *only* care about super-predicates, and considering predicates that possibly don't have anything to do with the alias is problematic. This includes things like closure signature inference (which is at its core searching for `Self: Fn(..)` style bounds), but also lints like `#[must_use]`, error reporting for aliases, computing type outlives predicates. Even in cases where considering all of the `item_bounds` doesn't lead to bugs, unnecessarily considering irrelevant bounds does lead to a regression (#121121) due to doing extra work in the solver. ## Example 1 - Trait Aliases This is best explored via an example: ``` type TAIT<T> = impl TraitAlias<T>; trait TraitAlias<T> = A + B where T: C; ``` The item bounds list for `Tait<T>` will include: * `Tait<T>: A` * `Tait<T>: B` * `T: C` While `item_super_predicates` query will include just the first two predicates. Side-note: You may wonder why `T: C` is included in the item bounds for `TAIT`? This is because when we elaborate `TraitAlias<T>`, we will also elaborate all the predicates on the trait. ## Example 2 - Associated Type Bounds ``` type TAIT<T> = impl Iterator<Item: A>; ``` The `item_bounds` list for `TAIT<T>` will include: * `Tait<T>: Iterator` * `<Tait<T> as Iterator>::Item: A` But the `item_super_predicates` will just include the first bound, since that's the only bound that is relevant to the *alias* itself. ## So what This leads to some diagnostics duplication just like #107614, but none of it will be user-facing. We only see it in the UI test suite because we explicitly disable diagnostic deduplication. Regarding naming, I went with `super_predicates` kind of arbitrarily; this can easily be changed, but I'd consider better names as long as we don't block this PR in perpetuity.
2024-03-20Add a testBen Kimock-0/+6
2024-03-20Rollup merge of #122749 - aliemjay:region-err, r=compiler-errorsJacob Pratt-0/+1
make `type_flags(ReError) & HAS_ERROR` Self-explanatory. `TypeVisitableExt::references_error(ReError)` incorrectly returned `false`.
2024-03-21Replace closures with `_` when suggesting fully qualified path for method callEsteban Küber-6/+22
``` error[E0283]: type annotations needed --> $DIR/into-inference-needs-type.rs:12:10 | LL | .into()?; | ^^^^ | = note: cannot satisfy `_: From<...>` = note: required for `FilterMap<...>` to implement `Into<_>` help: try using a fully qualified path to specify the expected types | LL ~ let list = <FilterMap<Map<std::slice::Iter<'_, &str>, _>, _> as Into<T>>::into(vec LL | .iter() LL | .map(|s| s.strip_prefix("t")) LL ~ .filter_map(Option::Some))?; | ``` Fix #122569.
2024-03-20make `type_flags(ReError) & HAS_ERROR`Ali MJ Al-Nasrawy-0/+1
2024-03-20Split item bounds and item super predicatesMichael Goulet-1/+1
2024-03-20Auto merge of #120717 - compiler-errors:cap-closure-kind, r=oli-obkbors-11/+31
For async closures, cap closure kind, get rid of `by_mut_body` Right now we have three `AsyncFn*` traits, and three corresponding futures that are returned by the `call_*` functions for them. This is fine, but it is a bit excessive, since the future returned by `AsyncFn` and `AsyncFnMut` are identical. Really, the only distinction we need to make with these bodies is "by ref" and "by move". This PR removes `AsyncFn::CallFuture` and renames `AsyncFnMut::CallMutFuture` to `AsyncFnMut::CallRefFuture`. This simplifies MIR building for async closures, since we don't need to build an extra "by mut" body, but just a "by move" body which is materially different. We need to do a bit of delicate handling of the ClosureKind for async closures, since we need to "cap" it to `AsyncFnMut` in some cases when we only care about what body we're looking for. This also fixes a bug where `<{async closure} as Fn>::call` was returning a body that takes the async-closure receiver *by move*. This also helps align the `AsyncFn` traits to the `LendingFn` traits' eventual designs.
2024-03-20compiler: allow transmute of ZST arrays with genericsDavid Rheinsberg-1/+6
Extend the `SizeSkeleton` evaluator to shortcut zero-sized arrays, thus considering `[T; 0]` to have a compile-time fixed-size of 0. The existing evaluator already deals with generic arrays under the feature-guard `transmute_const_generics`. However, it merely allows comparing fixed-size types with fixed-size types, and generic types with generic types. For generic types, it merely compares whether their arguments match (ordering them first). Even if their exact sizes are not known at compile time, it can ensure that they will eventually be the same. This patch extends this by shortcutting the size-evaluation of zero sized arrays and thus allowing size comparisons of `()` with `[T; 0]`, where one contains generics and the other does not. This code is guarded by `transmute_const_generics` (#109929), even though it is unclear whether it should be. However, this assumes that a separate stabilization PR is required to move this out of the feature guard. Initially reported in #98104.
2024-03-20Auto merge of #122119 - estebank:issue-117846, r=Nadrierilbors-0/+5
Silence unecessary !Sized binding error When gathering locals, we introduce a `Sized` obligation for each binding in the pattern. *After* doing so, we typecheck the init expression. If this has a type failure, we store `{type error}`, for both the expression and the pattern. But later we store an inference variable for the pattern. We now avoid any override of an existing type on a hir node when they've already been marked as `{type error}`, and on E0277, when it comes from `VariableType` we silence the error in support of the type error. Fix https://github.com/rust-lang/rust/issues/117846
2024-03-19Silence unecessary `!Sized` binding errorEsteban Küber-0/+5
When gathering locals, we introduce a `Sized` obligation for each binding in the pattern. *After* doing so, we typecheck the init expression. If this has a type failure, we store `{type error}`, for both the expression and the pattern. But later we store an inference variable for the pattern. We now avoid any override of an existing type on a hir node when they've already been marked as `{type error}`, and on E0277, when it comes from `VariableType` we silence the error in support of the type error. Fix #117846.
2024-03-19Add a few more commentsMichael Goulet-1/+5
2024-03-19Fix ABI for FnMut/Fn impls for async closuresMichael Goulet-1/+10
2024-03-19Only split by-ref/by-move futures for async closuresMichael Goulet-14/+21
2024-03-19Auto merge of #122735 - matthiaskrgr:rollup-pgb1s90, r=matthiaskrgrbors-8/+23
Rollup of 10 pull requests Successful merges: - #122435 (Don't trigger `unused_qualifications` on global paths) - #122556 (Extend format arg help for simple tuple index access expression) - #122634 (compiletest: Add support for `//@ aux-bin: foo.rs`) - #122677 (Fix incorrect mutable suggestion information for binding in ref pattern.) - #122691 (Fix ICE: `global_asm!()` Don't Panic When Unable to Evaluate Constant) - #122695 (Change only_local to a enum type.) - #122717 (Ensure stack before parsing dot-or-call) - #122719 (Ensure nested statics have a HIR node to prevent various queries from ICEing) - #122720 ([doc]:fix error code example) - #122724 (add test for casting pointer to union with unsized tail) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-19Rollup merge of #122719 - oli-obk:nested_static_feed_hir, r=fee1-deadMatthias Krüger-0/+21
Ensure nested statics have a HIR node to prevent various queries from ICEing fixes https://github.com/rust-lang/miri/issues/3389