about summary refs log tree commit diff
path: root/tests/ui/impl-trait
AgeCommit message (Collapse)AuthorLines
2024-03-27Use `TraitRef::to_string` sorting in favor of `TraitRef::ord`, as the latter ↵Oli Scherer-10/+10
compares `DefId`s which we need to avoid
2024-03-26ignore uncaptured lifetimes when checking opaquesAli MJ Al-Nasrawy-3/+106
2024-03-24add test for ICE: no errors encountered even though delay_span_bug issued, ↵Matthias Krüger-0/+35
expected ReFree to map to ReEarlyBound #108580 Fixes https://github.com/rust-lang/rust/issues/108580
2024-03-24Rollup merge of #122943 - matthiaskrgr:ice-tests-9xxxx-to-12xxxx, r=fmeaseMatthias Krüger-0/+36
add a couple more ice tests Fixes rust-lang/rust#104779 Fixes rust-lang/rust#106423 Fixes rust-lang/rust#106444 Fixes rust-lang/rust#101852 Fixes rust-lang/rust#106874 Fixes rust-lang/rust#105047 Fixes rust-lang/rust#107228 Fixes rust-lang/rust#99945
2024-03-23add test for opaque type with non-universal region substs #101852Matthias Krüger-0/+36
Fixes #101852
2024-03-22Delay a bug if no RPITITs were foundLeón Orell Valerian Liehr-17/+71
2024-03-22add test for https://github.com/rust-lang/rust/issues/112823Matthias Krüger-0/+61
Fixes #112823
2024-03-21Auto merge of #121123 - compiler-errors:item-assumptions, r=oli-obkbors-8/+67
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-20register opaques that reference errorsAli MJ Al-Nasrawy-13/+24
2024-03-20make `type_flags(ReError) & HAS_ERROR`Ali MJ Al-Nasrawy-77/+17
2024-03-20Bless test fallout (duplicate diagnostics)Michael Goulet-8/+67
2024-03-19Auto merge of #116935 - oli-obk:different_lifetime_taits_in_same_sig, ↵bors-21/+0
r=compiler-errors Prevent opaque types being instantiated twice with different regions within the same function addresses https://github.com/orgs/rust-lang/projects/22/views/1?pane=issue&itemId=41329537 r? `@compiler-errors`
2024-03-19Auto merge of #122392 - BoxyUwU:misc_cleanup, r=lcnrbors-8/+8
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 #122055 - compiler-errors:stabilize-atb, r=oli-obkbors-2/+0
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-18Rollup merge of #122158 - estebank:feature-sugg, r=WaffleLapkinMatthias Krüger-1/+4
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-18update region debug formattingBoxy-8/+8
2024-03-18Provide structured suggestion for `#![feature(foo)]`Esteban Küber-1/+4
``` 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-18Prevent opaque types being instantiated twice with different regions within ↵Oli Scherer-21/+0
the same function
2024-03-16Rollup merge of #121720 - tmandry:split-refining, r=compiler-errorsLeón Orell Valerian Liehr-7/+126
Split refining_impl_trait lint into _reachable, _internal variants As discussed in https://github.com/rust-lang/rust/issues/119535#issuecomment-1909352040: > We discussed this today in triage and developed a consensus to: > > * Add a separate lint against impls that refine a return type defined with RPITIT even when the trait is not crate public. > * Place that in a lint group along with the analogous crate public lint. > * Create an issue to solicit feedback on these lints (or perhaps two separate ones). > * Have the warnings displayed with each lint reference this issue in a similar manner to how we do that today with the required `Self: '0'` bound on GATs. > * Make a note to review this feedback on 2-3 release cycles. This points users to https://github.com/rust-lang/rust/issues/121718 to leave feedback.
2024-03-15Auto merge of #122341 - compiler-errors:alias-wfness, r=lcnrbors-1/+18
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-14Ensure RPITITs are created before def-id freezingMichael Goulet-0/+22
2024-03-14Consolidate WF for aliasesMichael Goulet-1/+18
2024-03-13Delay a bug for stranded opaquesMichael Goulet-0/+22
2024-03-12Rollup merge of #122366 - oli-obk:opaques_defined_by_overflow, r=lcnrJubilee-0/+26
Fix stack overflow with recursive associated types fixes #122364
2024-03-12Fix stack overflow with recursive associated typesOli Scherer-0/+26
2024-03-12Rollup merge of #122343 - compiler-errors:rando, r=fmeaseMatthias Krüger-39/+15
Remove some unnecessary `allow(incomplete_features)` in the test suite A useless change, but I like things to be clean.
2024-03-11Remove some unnecessary allow(incomplete_features)Michael Goulet-39/+15
2024-03-11Auto merge of #121796 - oli-obk:eager_opaque_checks3, r=lcnrbors-28/+15
Make `DefiningAnchor::Bind` only store the opaque types that may be constrained, instead of the current infcx root item. This makes `Bind` almost always be empty, so we can start forwarding it to queries, allowing us to remove `Bubble` entirely (not done in this PR) The only behaviour change is in diagnostics. r? `@lcnr` `@compiler-errors`
2024-03-11Make `DefiningAnchor::Bind` only store the opaque types that may be ↵Oli Scherer-28/+15
constrained, instead of the current infcx root item. This makes `Bind` almost always be empty, so we can start forwarding it to queries, allowing us to remove `Bubble` entirely
2024-03-10Ignore tests w/ current/next revisions from compare-mode=next-solverMichael Goulet-21/+32
2024-03-08Stabilize associated type boundsMichael Goulet-2/+0
2024-03-08Rollup merge of #122172 - compiler-errors:rpitit-collect-ice, r=fmeaseMatthias Krüger-0/+85
Don't ICE if we collect no RPITITs unless there are no unification errors Move an assertion in `collect_return_position_impl_trait_in_trait_tys` to after the `ObligationCtxt::eq` calls, so that we only assert and ICE if we have unification errors. Fixes #121468
2024-03-08Improve error message for opaque capturesMichael Goulet-31/+43
2024-03-08Don't ICE if we collect no RPITITs unless there are no unification errorsMichael Goulet-0/+85
2024-03-07Merge collect_mod_item_types query into check_well_formedOli Scherer-58/+58
2024-03-07Merge `check_mod_impl_wf` and `check_mod_type_wf`Oli Scherer-10/+25
2024-03-06Rollup merge of #122027 - compiler-errors:rpitit-cycle, r=spastorinoMatthias Krüger-0/+18
Uplift some feeding out of `associated_type_for_impl_trait_in_impl` and into queries This PR moves the `type_of` and `generics_of` query feeding out of `associated_type_for_impl_trait_in_impl`, since eagerly feeding results in query cycles due to a subtle interaction with `resolve_bound_vars`. Fixes #122019 r? spastorino
2024-03-06Auto merge of #121679 - lcnr:opaque-wf-check-2, r=oli-obkbors-20/+64
stricter hidden type wf-check [based on #115008] Original work by `@aliemjay` in #115008. A huge thanks to them for originally figuring out this approach :heart: Fixes https://github.com/rust-lang/rust/issues/114728 Fixes https://github.com/rust-lang/rust/issues/114572 Instead of adding the `WellFormed` obligations when relating opaque types, we now always emit such an obligation when defining the hidden type. This causes nested opaque types which aren't wf to error, see the comment below for the described impact. I believe this change to be desirable as it significantly reduces complexity by removing special-cases. It also caused an issue with RPITIT: in defaulted trait methods, we add a `Projection(synthetic_assoc, rpit_of_trait_method)` clause to the `param_env`. This clause is not added to the `ParamEnv` of the nested coroutines. This caused a normalization failure in `fn check_coroutine_obligations` with the new solver. I fixed that by using the env of the typeck root instead. r? `@oli-obk`
2024-03-05Split refining_impl_trait lint into _reachable, _internal variantsTyler Mandry-7/+126
2024-03-05Uplift some feeding out of associated_type_for_impl_trait_in_impl and into ↵Michael Goulet-0/+18
queries
2024-03-03Use root obligation on E0277 for some casesEsteban Küber-1/+0
When encountering trait bound errors that satisfy some heuristics that tell us that the relevant trait for the user comes from the root obligation and not the current obligation, we use the root predicate for the main message. This allows to talk about "X doesn't implement Pattern<'_>" over the most specific case that just happened to fail, like "char doesn't implement Fn(&mut char)" in `tests/ui/traits/suggest-dereferences/root-obligation.rs` The heuristics are: - the type of the leaf predicate is (roughly) the same as the type from the root predicate, as a proxy for "we care about the root" - the leaf trait and the root trait are different, so as to avoid talking about `&mut T: Trait` and instead remain talking about `T: Trait` instead - the root trait is not `Unsize`, as to avoid talking about it in `tests/ui/coercion/coerce-issue-49593-box-never.rs`. ``` error[E0277]: the trait bound `&char: Pattern<'_>` is not satisfied --> $DIR/root-obligation.rs:6:38 | LL | .filter(|c| "aeiou".contains(c)) | -------- ^ the trait `Fn<(char,)>` is not implemented for `&char`, which is required by `&char: Pattern<'_>` | | | required by a bound introduced by this call | = note: required for `&char` to implement `FnOnce<(char,)>` = note: required for `&char` to implement `Pattern<'_>` note: required by a bound in `core::str::<impl str>::contains` --> $SRC_DIR/core/src/str/mod.rs:LL:COL help: consider dereferencing here | LL | .filter(|c| "aeiou".contains(*c)) | + ``` Fix #79359, fix #119983, fix #118779, cc #118415 (the suggestion needs to change).
2024-03-02Rollup merge of #121731 - oli-obk:eager_opaque_checks, r=compiler-errorsGuillaume Boisseau-2/+35
Now that inlining, mir validation and const eval all use reveal-all, we won't be constraining hidden types here anymore r? `@compiler-errors` one bubble down, two more to go the test is unrelated, just something I noticed would be good to test in both the old solver and the new.
2024-02-29Rollup merge of #121669 - nnethercote:count-stashed-errs-again, r=estebankGuillaume Gomez-0/+22
Count stashed errors again Stashed diagnostics are such a pain. Their "might be emitted, might not" semantics messes with lots of things. #120828 and #121206 made some big changes to how they work, improving some things, but still leaving some problems, as seen by the issues caused by #121206. This PR aims to fix all of them by restricting them in a way that eliminates the "might be emitted, might not" semantics while still allowing 98% of their benefit. Details in the individual commit logs. r? `@oli-obk`
2024-02-29Rollup merge of #121745 - compiler-errors:refining-impl-trait-deeply-norm, ↵Jacob Pratt-0/+20
r=lcnr Deeply normalize obligations in `refining_impl_trait` We somewhat awkwardly use semantic comparison when checking the `refining_impl_trait` lint. This relies on us being able to normalize bounds eagerly to avoid cases where an unnormalized alias is not considered equal to a normalized alias. Since `normalize` in the new solver is a noop, let's use `deeply_normalize` instead. r? lcnr cc ``@tmandry,`` this should fix your bug lol
2024-02-29Overhaul how stashed diagnostics work, again.Nicholas Nethercote-0/+22
Stashed errors used to be counted as errors, but could then be cancelled, leading to `ErrorGuaranteed` soundness holes. #120828 changed that, closing the soundness hole. But it introduced other difficulties because you sometimes have to account for pending stashed errors when making decisions about whether errors have occured/will occur and it's easy to overlook these. This commit aims for a middle ground. - Stashed errors (not warnings) are counted immediately as emitted errors, avoiding the possibility of forgetting to consider them. - The ability to cancel (or downgrade) stashed errors is eliminated, by disallowing the use of `steal_diagnostic` with errors, and introducing the more restrictive methods `try_steal_{modify,replace}_and_emit_err` that can be used instead. Other things: - `DiagnosticBuilder::stash` and `DiagCtxt::stash_diagnostic` now both return `Option<ErrorGuaranteed>`, which enables the removal of two `delayed_bug` calls and one `Ty::new_error_with_message` call. This is possible because we store error guarantees in `DiagCtxt::stashed_diagnostics`. - Storing the guarantees also saves us having to maintain a counter. - Calls to the `stashed_err_count` method are no longer necessary alongside calls to `has_errors`, which is a nice simplification, and eliminates two more `span_delayed_bug` calls and one FIXME comment. - Tests are added for three of the four fixed PRs mentioned below. - `issue-121108.rs`'s output improved slightly, omitting a non-useful error message. Fixes #121451. Fixes #121477. Fixes #121504. Fixes #121508.
2024-02-28Deeply normalize obligations in refining_impl_traitMichael Goulet-0/+20
2024-02-28test that fudging with opaque types is the same in the new solverOli Scherer-2/+35
2024-02-27Print RPITIT like an opaqueMichael Goulet-6/+6
2024-02-27rename RPITIT from opaque to syntheticMichael Goulet-8/+8
2024-02-27when defining opaques, require the hidden type to be well-formedlcnr-36/+39