about summary refs log tree commit diff
path: root/compiler/rustc_middle
AgeCommit message (Collapse)AuthorLines
2024-03-20mentioned_items: record all callee and coerced closure types, whether they ↵Ralf Jung-6/+18
are FnDef/Closure or not They may become FnDef during monomorphization!
2024-03-20mentioned items: also handle closure-to-fn-ptr coercionsRalf Jung-1/+2
2024-03-20mentioned items: also handle vtablesRalf Jung-1/+5
2024-03-20avoid processing mentioned items that are also still usedRalf Jung-1/+1
2024-03-20collector: recursively traverse 'mentioned' items to evaluate their constantsRalf Jung-0/+29
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-20Update documentationOli Scherer-4/+5
2024-03-20Rename mir_const query to mir_builtOli Scherer-2/+2
2024-03-20Replace `mir_built` query with a hook and use mir_const everywhere insteadOli Scherer-7/+6
2024-03-20Rollup merge of #121543 - onur-ozkan:clippy-args, r=oli-obkMatthias Krüger-14/+10
various clippy fixes We need to keep the order of the given clippy lint rules before passing them. Since clap doesn't offer any useful interface for this purpose out of the box, we have to handle it manually. Additionally, this PR makes `-D` rules work as expected. Previously, lint rules were limited to `-W`. By enabling `-D`, clippy began to complain numerous lines in the tree, all of which have been resolved in this PR as well. Fixes #121481 cc `@matthiaskrgr`
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-20resolve clippy errorsonur-ozkan-14/+10
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2024-03-19Add a few more commentsMichael Goulet-1/+5
2024-03-19Fix ABI for FnMut/Fn impls for async closuresMichael Goulet-1/+11
2024-03-19Only split by-ref/by-move futures for async closuresMichael Goulet-28/+25
2024-03-19Auto merge of #122735 - matthiaskrgr:rollup-pgb1s90, r=matthiaskrgrbors-10/+25
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-2/+23
Ensure nested statics have a HIR node to prevent various queries from ICEing fixes https://github.com/rust-lang/miri/issues/3389
2024-03-19Rollup merge of #122695 - surechen:make_only_local_explict_argument, r=lcnrMatthias Krüger-8/+2
Change only_local to a enum type. Change only_local to enum type and change the macros to always require a variant of that enum. r? `@lcnr`
2024-03-19Do binder folding eagerly in bound_coroutine_hidden_typesMichael Goulet-2/+34
I refuse to fix this in the old solver; its lazy instantiation of binders will be the end of me.
2024-03-19Auto merge of #122392 - BoxyUwU:misc_cleanup, r=lcnrbors-2/+16
misc cleanups from debugging something rename `instantiate_canonical_with_fresh_inference_vars` to `instantiate_canonical` the substs for the canonical are not solely infer vars as that would be wildly wrong and it is rather confusing to see this method called and think that the entire canonicalization setup is completely broken when it is not :thumbsup: also update region debug printing to be more like the custom impls for Ty/Const, right now regions in debug output are horribly verbose and make it incredibly hard to read but with this atleast boundvars and placeholders when debugging the new solver do not take up excessive amounts of space. r? `@lcnr`
2024-03-19Auto merge of #122037 - oli-obk:more_new_intrinsics, r=Nilstriebbors-9/+18
Move more intrinsics to rustc_intrinsic cc https://github.com/rust-lang/rust/issues/63585
2024-03-19Change only_local to enum type and change the macros to always require a ↵surechen-8/+2
variant of that enum.
2024-03-19Auto merge of #122021 - oli-obk:delangitemification, r=compiler-errorsbors-47/+7
Use hir::Node helper methods instead of repeating the same impl multiple times I wanted to do something entirely different and stumbled upon a bunch of cleanups
2024-03-19Ensure nested statics have a HIR node to prevent various queries from ICEingOli Scherer-0/+21
2024-03-19Remove all checks of `IntrinsicDef::must_be_overridden` except for the ↵Oli Scherer-3/+1
actual overrides in codegen
2024-03-19Make span_bug panic site useful againOli Scherer-9/+18
2024-03-19Make `const_eval_select` a rustc_intrinsicOli Scherer-1/+3
2024-03-19Auto merge of #119212 - w-utter:pretty-print-const-expr, r=compiler-errorsbors-2/+152
Fix representation when printing abstract consts Previously, when printing a const generic expr, it would only display it as `{{const expr}}`. This allows for a more legible representation when printing these out. I also zipped the types with their constants for abstract consts that contain function calls when using type annotations, eg: `foo(S: usize, true: bool) -> usize` insteaad of `foo(S, true): fn(usize, bool) -> usize` for conciseness.
2024-03-19The AssocOpaqueTy HIR node is not actually needed to differentiate from ↵Oli Scherer-2/+2
other hir nodes that were fed
2024-03-19Auto merge of #122493 - lukas-code:sized-constraint, r=lcnrbors-16/+19
clean up `Sized` checking This PR cleans up `sized_constraint` and related functions to make them simpler and faster. This should not make more or less code compile, but it can change error output in some rare cases. ## enums and unions are `Sized`, even if they are not WF The previous code has some special handling for enums, which made them sized if and only if the last field of each variant is sized. For example given this definition (which is not WF) ```rust enum E<T1: ?Sized, T2: ?Sized, U1: ?Sized, U2: ?Sized> { A(T1, T2), B(U1, U2), } ``` the enum was sized if and only if `T2` and `U2` are sized, while `T1` and `T2` were ignored for `Sized` checking. After this PR this enum will always be sized. Unsized enums are not a thing in Rust and removing this special case allows us to return an `Option<Ty>` from `sized_constraint`, rather than a `List<Ty>`. Similarly, the old code made an union defined like this ```rust union Union<T: ?Sized, U: ?Sized> { head: T, tail: U, } ``` sized if and only if `U` is sized, completely ignoring `T`. This just makes no sense at all and now this union is always sized. ## apply the "perf hack" to all (non-error) types, instead of just type parameters This "perf hack" skips evaluating `sized_constraint(adt): Sized` if `sized_constraint(adt): Sized` exactly matches a predicate defined on `adt`, for example: ```rust // `Foo<T>: Sized` iff `T: Sized`, but we know `T: Sized` from a predicate of `Foo` struct Foo<T /*: Sized */>(T); ``` Previously this was only applied to type parameters and now it is applied to every type. This means that for example this type is now always sized: ```rust // Note that this definition is WF, but the type `S<T>` not WF in the global/empty ParamEnv struct S<T>([T]) where [T]: Sized; ``` I don't anticipate this to affect compile time of any real-world program, but it makes the code a bit nicer and it also makes error messages a bit more consistent if someone does write such a cursed type. ## tuples are sized if the last type is sized The old solver already has this behavior and this PR also implements it for the new solver and `is_trivially_sized`. This makes it so that tuples work more like a struct defined like this: ```rust struct TupleN<T1, T2, /* ... */ Tn: ?Sized>(T1, T2, /* ... */ Tn); ``` This might improve the compile time of programs with large tuples a little, but is mostly also a consistency fix. ## `is_trivially_sized` for more types This function is used post-typeck code (borrowck, const eval, codegen) to skip evaluating `T: Sized` in some cases. It will now return `true` in more cases, most notably `UnsafeCell<T>` and `ManuallyDrop<T>` where `T.is_trivially_sized`. I'm anticipating that this change will improve compile time for some real world programs.
2024-03-19Auto merge of #122055 - compiler-errors:stabilize-atb, r=oli-obkbors-1/+1
Stabilize associated type bounds (RFC 2289) This PR stabilizes associated type bounds, which were laid out in [RFC 2289]. This gives us a shorthand to express nested type bounds that would otherwise need to be expressed with nested `impl Trait` or broken into several `where` clauses. ### What are we stabilizing? We're stabilizing the associated item bounds syntax, which allows us to put bounds in associated type position within other bounds, i.e. `T: Trait<Assoc: Bounds...>`. See [RFC 2289] for motivation. In all position, the associated type bound syntax expands into a set of two (or more) bounds, and never anything else (see "How does this differ[...]" section for more info). Associated type bounds are stabilized in four positions: * **`where` clauses (and APIT)** - This is equivalent to breaking up the bound into two (or more) `where` clauses. For example, `where T: Trait<Assoc: Bound>` is equivalent to `where T: Trait, <T as Trait>::Assoc: Bound`. * **Supertraits** - Similar to above, `trait CopyIterator: Iterator<Item: Copy> {}`. This is almost equivalent to breaking up the bound into two (or more) `where` clauses; however, the bound on the associated item is implied whenever the trait is used. See #112573/#112629. * **Associated type item bounds** - This allows constraining the *nested* rigid projections that are associated with a trait's associated types. e.g. `trait Trait { type Assoc: Trait2<Assoc2: Copy>; }`. * **opaque item bounds (RPIT, TAIT)** - This allows constraining associated types that are associated with the opaque without having to *name* the opaque. For example, `impl Iterator<Item: Copy>` defines an iterator whose item is `Copy` without having to actually name that item bound. The latter three are not expressible in surface Rust (though for associated type item bounds, this will change in #120752, which I don't believe should block this PR), so this does represent a slight expansion of what can be expressed in trait bounds. ### How does this differ from the RFC? Compared to the RFC, the current implementation *always* desugars associated type bounds to sets of `ty::Clause`s internally. Specifically, it does *not* introduce a position-dependent desugaring as laid out in [RFC 2289], and in particular: * It does *not* desugar to anonymous associated items in associated type item bounds. * It does *not* desugar to nested RPITs in RPIT bounds, nor nested TAITs in TAIT bounds. This position-dependent desugaring laid out in the RFC existed simply to side-step limitations of the trait solver, which have mostly been fixed in #120584. The desugaring laid out in the RFC also added unnecessary complication to the design of the feature, and introduces its own limitations to, for example: * Conditionally lowering to nested `impl Trait` in certain positions such as RPIT and TAIT means that we inherit the limitations of RPIT/TAIT, namely lack of support for higher-ranked opaque inference. See this code example: https://github.com/rust-lang/rust/pull/120752#issuecomment-1979412531. * Introducing anonymous associated types makes traits no longer object safe, since anonymous associated types are not nameable, and all associated types must be named in `dyn` types. This last point motivates why this PR is *not* stabilizing support for associated type bounds in `dyn` types, e.g, `dyn Assoc<Item: Bound>`. Why? Because `dyn` types need to have *concrete* types for all associated items, this would necessitate a distinct lowering for associated type bounds, which seems both complicated and unnecessary compared to just requiring the user to write `impl Trait` themselves. See #120719. ### Implementation history: Limited to the significant behavioral changes and fixes and relevant PRs, ping me if I left something out-- * #57428 * #108063 * #110512 * #112629 * #120719 * #120584 Closes #52662 [RFC 2289]: https://rust-lang.github.io/rfcs/2289-associated-type-bounds.html
2024-03-18address nitsLukas Markeffsky-1/+1
2024-03-18Rollup merge of #122687 - lcnr:normalizes-to-emit-nested-goals, ↵Matthias Krüger-15/+25
r=compiler-errors `NormalizesTo`: return nested goals to caller Fixes the regression of `paperclip-core`. see https://hackmd.io/IsVAafiOTAaPIFcUxRJufw for more details. r? ```@compiler-errors```
2024-03-18Rollup merge of #122158 - estebank:feature-sugg, r=WaffleLapkinMatthias Krüger-1/+42
Provide structured suggestion for `#![feature(foo)]` ``` error: `S2<'_>` is forbidden as the type of a const generic parameter --> $DIR/lifetime-in-const-param.rs:5:23 | LL | struct S<'a, const N: S2>(&'a ()); | ^^ | = note: the only supported types are integers, `bool` and `char` help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | LL + #![feature(adt_const_params)] | ``` Fix #55941.
2024-03-18Deduplicate `associated_body` and `body_id`Oli Scherer-47/+7
They match on almost the same patterns, which is fishy. Also turn `associated_body` into a method and do some cleanups nearby the call sites
2024-03-18cleanup + reviewlcnr-13/+4
2024-03-18update region debug formattingBoxy-2/+16
2024-03-18Provide structured suggestion for `#![feature(foo)]`Esteban Küber-1/+42
``` error: `S2<'_>` is forbidden as the type of a const generic parameter --> $DIR/lifetime-in-const-param.rs:5:23 | LL | struct S<'a, const N: S2>(&'a ()); | ^^ | = note: the only supported types are integers, `bool` and `char` help: add `#![feature(adt_const_params)]` to the crate attributes to enable more complex and user defined types | LL + #![feature(adt_const_params)] | ``` Fix #55941.
2024-03-18`NormalizesTo` return nested goalslcnr-2/+21
2024-03-18Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in the few ↵Oli Scherer-18/+18
cases that used `None`
2024-03-17Print a backtrace in const eval if interruptedBen Kimock-0/+2
2024-03-17Guard decorate on when not to skip instead许杰友 Jieyou Xu (Joe)-7/+4
2024-03-17Invoke decorate when error level is beyond warning, including error许杰友 Jieyou Xu (Joe)-7/+16
2024-03-17Only invoke `decorate` if the diag can eventually be emitted许杰友 Jieyou Xu (Joe)-2/+10
2024-03-17added pretty_print_const_exprwill-2/+152
2024-03-16Auto merge of #121926 - tgross35:f16-f128-step3-feature-gate, ↵bors-2/+64
r=compiler-errors,petrochenkov `f16` and `f128` step 3: compiler support & feature gate Continuation of https://github.com/rust-lang/rust/pull/121841, another portion of https://github.com/rust-lang/rust/pull/114607 This PR exposes the new types to the world and adds a feature gate. Marking this as a draft because I need some feedback on where I did the feature gate check. It also does not yet catch type via suffixed literals (so the feature gate test will fail, probably some others too because I haven't belssed). If there is a better place to check all types after resolution, I can do that. If not, I figure maybe I can add a second gate location in AST when it checks numeric suffixes. Unfortunately I still don't think there is much testing to be done for correctness (codegen tests or parsed value checks) until we have basic library support. I think that will be the next step. Tracking issue: https://github.com/rust-lang/rust/issues/116909 r? `@compiler-errors` cc `@Nilstrieb` `@rustbot` label +F-f16_and_f128
2024-03-15Rollup merge of #122513 - petrochenkov:somehir4, r=fmeaseGuillaume Gomez-18/+5
hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id` Also replace a few `hir_node()` calls with `hir_node_by_def_id()`. Follow up to https://github.com/rust-lang/rust/pull/120943.
2024-03-15interpret/allocation: fix aliasing issue in interpreter and refactor getters ↵Ralf Jung-11/+31
a bit - rename mutating functions to be more scary - add a new raw bytes getter
2024-03-15Rollup merge of #122526 - Zalathar:thir-expr-docs, r=oli-obkMatthias Krüger-1/+12
Docs for `thir::ExprKind::Use` and `thir::ExprKind::Let` These docs are based on my own recent investigations; hopefully they're reasonably accurate. `Use` was particularly puzzling to me at first, since the name is not very suggestive, and the old docs were quite cryptic.