about summary refs log tree commit diff
path: root/compiler/rustc_trait_selection/src
AgeCommit message (Collapse)AuthorLines
2024-03-22Rename `hir::Node::Local` into `hir::Node::LetStmt`Guillaume Gomez-8/+8
2024-03-22Rename `hir::Local` into `hir::LetStmt`Guillaume Gomez-3/+3
2024-03-22Use != Positive rather than == NegativeMichael Goulet-3/+3
Feels more complete, and for ImplPolarity has the side-effect of making sure we also handle reservation impls correctly
2024-03-22Split out ImplPolarity and PredicatePolarityMichael Goulet-50/+55
2024-03-22Programmatically convert some of the pat ctorsMichael Goulet-23/+19
2024-03-22Ty::new_ref and Ty::new_ptr stop using TypeAndMutMichael Goulet-3/+3
2024-03-22Update local variables and tracing callsLeón Orell Valerian Liehr-3/+2
Most of the tracing calls didn't fully leverage the power of `tracing`. For example, several of them used to hard-code method names / tracing spans as well as variable names. Use `#[instrument]` and `?var` / `%var` (etc.) instead. In my opinion, this is the proper way to migrate them from the old AstConv nomenclature to the new HIR ty lowering one.
2024-03-22Update (doc) commentsLeón Orell Valerian Liehr-5/+6
Several (doc) comments were super outdated or didn't provide enough context. Some doc comments shoved everything in a single paragraph without respecting the fact that the first paragraph should be a single sentence because rustdoc treats these as item descriptions / synopses on module pages.
2024-03-22Rename AstConv to HIR ty loweringLeón Orell Valerian Liehr-2/+2
This includes updating astconv-related items and a few local variables.
2024-03-22Rollup merge of #122829 - ShoyuVanilla:gen-block-impl-fused-iter, ↵Matthias Krüger-7/+80
r=compiler-errors Implement `FusedIterator` for `gen` block cc #117078
2024-03-22Implement `FusedIterator` for `gen` blockShoyu Vanilla-7/+80
2024-03-21Rollup merge of #122402 - weiznich:fix/122391, r=compiler-errorsMatthias Krüger-54/+135
Make `#[diagnostic::on_unimplemented]` format string parsing more robust This commit fixes several issues with the format string parsing of the `#[diagnostic::on_unimplemented]` attribute that were pointed out by `@ehuss.` In detail it fixes: * Appearing format specifiers (display, etc). For these we generate a warning that the specifier is unsupported. Otherwise we ignore them * Positional arguments. For these we generate a warning that positional arguments are unsupported in that location and replace them with the format string equivalent (so `{}` or `{n}` where n is the index of the positional argument) * Broken format strings with enclosed }. For these we generate a warning about the broken format string and set the emitted message literally to the provided unformatted string * Unknown format specifiers. For these we generate an additional warning about the unknown specifier. Otherwise we emit the literal string as message. This essentially makes those strings behave like `format!` with the minor difference that we do not generate hard errors but only warnings. After that we continue trying to do something unsuprising (mostly either ignoring the broken parts or falling back to just giving back the literal string as provided). Fix #122391 r? `@compiler-errors`
2024-03-21Rollup merge of #122358 - compiler-errors:bound-regions-in-generator, r=lcnrMatthias Krüger-36/+8
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-21Make `#[diagnostic::on_unimplemented]` format string parsing more robustGeorg Semmler-54/+135
This commit fixes several issues with the format string parsing of the `#[diagnostic::on_unimplemented]` attribute that were pointed out by @ehuss. In detail it fixes: * Appearing format specifiers (display, etc). For these we generate a warning that the specifier is unsupported. Otherwise we ignore them * Positional arguments. For these we generate a warning that positional arguments are unsupported in that location and replace them with the format string equivalent (so `{}` or `{n}` where n is the index of the positional argument) * Broken format strings with enclosed }. For these we generate a warning about the broken format string and set the emitted message literally to the provided unformatted string * Unknown format specifiers. For these we generate an additional warning about the unknown specifier. Otherwise we emit the literal string as message. This essentially makes those strings behave like `format!` with the minor difference that we do not generate hard errors but only warnings. After that we continue trying to do something unsuprising (mostly either ignoring the broken parts or falling back to just giving back the literal string as provided). Fix #122391
2024-03-21Provide structured suggestion for unconstrained generic constantEsteban Küber-5/+32
``` error: unconstrained generic constant --> $DIR/const-argument-if-length.rs:18:10 | LL | pad: [u8; is_zst::<T>()], | ^^^^^^^^^^^^^^^^^^^ | help: try adding a `where` bound | LL | pub struct AtLeastByte<T: ?Sized> where [(); is_zst::<T>()]: { | ++++++++++++++++++++++++++ ``` Detect when the constant expression isn't `usize` and suggest casting: ``` error: unconstrained generic constant --> f300.rs:6:10 | 6 | bb::<{!N}>(); | ^^^^ -Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs:3539:36 | help: try adding a `where` bound | 5 | fn b<const N: bool>() where [(); {!N} as usize]: { | ++++++++++++++++++++++++++ ``` Fix #122395.
2024-03-20Split item bounds and item super predicatesMichael Goulet-18/+16
2024-03-20Auto merge of #122754 - Mark-Simulacrum:bootstrap-bump, r=albertlarsan68bors-1/+0
Bump to 1.78 bootstrap compiler https://forge.rust-lang.org/release/process.html#master-bootstrap-update-t-2-day-tuesday
2024-03-20step cfgsMark Rousskov-1/+0
2024-03-20Auto merge of #120717 - compiler-errors:cap-closure-kind, r=oli-obkbors-7/+7
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-20Rollup merge of #122732 - compiler-errors:coroutine-captures-note, r=nnethercoteMatthias Krüger-60/+58
Remove redundant coroutine captures note This note is redundant, since we'll always be printing this "captures the following types..." between *more* descriptive `BuiltinDerivedObligationCause`s. Please review with whitespace disabled, since I also removed an unnecessary labeled break.
2024-03-20Auto merge of #122119 - estebank:issue-117846, r=Nadrierilbors-0/+10
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/+10
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-19Only split by-ref/by-move futures for async closuresMichael Goulet-7/+7
2024-03-19Remove redundant coroutine captures noteMichael Goulet-60/+58
2024-03-19Do binder folding eagerly in bound_coroutine_hidden_typesMichael Goulet-35/+8
I refuse to fix this in the old solver; its lazy instantiation of binders will be the end of me.
2024-03-19Don't ICE when encountering bound regions in generator interior typeMichael Goulet-1/+0
2024-03-19Auto merge of #122493 - lukas-code:sized-constraint, r=lcnrbors-21/+31
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-3/+2
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-9/+13
2024-03-18Rollup merge of #122687 - lcnr:normalizes-to-emit-nested-goals, ↵Matthias Krüger-156/+189
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-3/+5
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-18cleanup + reviewlcnr-22/+27
2024-03-18Provide structured suggestion for `#![feature(foo)]`Esteban Küber-3/+5
``` 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-72/+107
2024-03-18move `normalizes_to_hack` to `AliasRelate`lcnr-67/+60
2024-03-18Avoid various uses of `Option<Span>` in favor of using `DUMMY_SP` in the few ↵Oli Scherer-6/+6
cases that used `None`
2024-03-15Auto merge of #122571 - matthiaskrgr:rollup-36wwovk, r=matthiaskrgrbors-8/+8
Rollup of 6 pull requests Successful merges: - #122254 (Detect calls to .clone() on T: !Clone types on borrowck errors) - #122495 (Visually mark 👻hidden👻 items with document-hidden-items) - #122543 (Add `#![rustc_never_type_mode = "..."]` crate-level attribute to allow experimenting) - #122560 (Safe Transmute: Use 'not yet supported', not 'unspecified' in errors) - #122562 (Mention labelled blocks in `break` docs) - #122563 (CI: cache PR CI Docker builds) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-15Rollup merge of #122560 - jswrenn:not-yet-supported, r=compiler-errorsMatthias Krüger-8/+8
Safe Transmute: Use 'not yet supported', not 'unspecified' in errors We can (and will) support analyzing the transmutability of types whose layouts aren't completely specified by its repr. This change ensures that the error messages remain sensible after this support lands. r? ``@compiler-errors``
2024-03-15Auto merge of #122341 - compiler-errors:alias-wfness, r=lcnrbors-20/+8
Consolidate WF for aliases Make RPITs/TAITs/weak (type) aliases/projections all enforce: 1. their nominal predicates 2. their args are WF This possibly does extra work, but is also nice for consistency sake. r? lcnr
2024-03-15Safe Transmute: lowercase diagnosticsJack Wrenn-4/+4
2024-03-15Safe Transmute: Use 'not yet supported', not 'unspecified' in errorsJack Wrenn-4/+4
We can (and will) support analyzing the transmutability of types whose layouts aren't completely specified by its repr. This change ensures that the error messages remain sensible after this support lands.
2024-03-15Rollup merge of #122513 - petrochenkov:somehir4, r=fmeaseGuillaume Gomez-13/+12
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-15Rollup merge of #122174 - notriddle:master, r=TaKO8KiMatthias Krüger-10/+50
diagnostics: suggest `Clone` bounds when noop `clone()` Fixes #121524
2024-03-15Auto merge of #122511 - matthiaskrgr:rollup-swzilin, r=matthiaskrgrbors-1/+1
Rollup of 10 pull requests Successful merges: - #117118 ([AIX] Remove AixLinker's debuginfo() implementation) - #121650 (change std::process to drop supplementary groups based on CAP_SETGID) - #121764 (Make incremental sessions identity no longer depend on the crate names provided by source code) - #122212 (Copy byval argument to alloca if alignment is insufficient) - #122322 (coverage: Initial support for branch coverage instrumentation) - #122373 (Fix the conflict problem between the diagnostics fixes of lint `unnecessary_qualification` and `unused_imports`) - #122479 (Implement `Duration::as_millis_{f64,f32}`) - #122487 (Rename `StmtKind::Local` variant into `StmtKind::Let`) - #122498 (Update version of cc crate) - #122503 (Make `SubdiagMessageOp` well-formed) r? `@ghost` `@rustbot` modify labels: rollup
2024-03-14use a let chainLukas Markeffsky-7/+4
2024-03-14remove unnecessary sized checksLukas Markeffsky-3/+4
2024-03-14clean up ADT sized constraint computationLukas Markeffsky-7/+15
2024-03-14hir: Remove `opt_local_def_id_to_hir_id` and `opt_hir_node_by_def_id`Vadim Petrochenkov-13/+12
Also replace a few `hir_node()` calls with `hir_node_by_def_id()`
2024-03-14Rollup merge of #122487 - GuillaumeGomez:rename-stmtkind-local, r=oli-obkMatthias Krüger-1/+1
Rename `StmtKind::Local` variant into `StmtKind::Let` It comes from this [discussion](https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/Improve.20naming.20of.20.60ExprKind.3A.3ALet.60.3F). Starting point was: > I often end up looking at [ExprKind::Let](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/enum.ExprKind.html#variant.Let) instead of Local because of the name. I think renaming it (both the `ExprKind` variant and the Let struct) to `LetPattern` or LetPat could improve the situation as I'm not sure I'm not the only one encountering this issue. And then it evolved into: > It's already `Expr::Let` instead of `StmtKind::Local`. Counterproposal: rename `StmtKind::Local` to `StmtKind::Let`. The goal here is to clear this confusion. r? `@oli-obk`
2024-03-14Auto merge of #119849 - lcnr:eagerly-instantiate-binders, r=compiler-errorsbors-23/+49
more eagerly instantiate binders The old solver sometimes incorrectly used `sub`, change it to explicitly instantiate binders and use `eq` instead. While doing so I also moved the instantiation before the normalize calls. This caused some observable changes, will explain these inline. This PR therefore requires a crater run and an FCP. r? types