summary refs log tree commit diff
path: root/src/test/ui/impl-trait
AgeCommit message (Collapse)AuthorLines
2023-01-19Do not filter substs in `remap_generic_params_to_declaration_params`.Camille GILLOT-0/+39
The relevant filtering should have been performed by borrowck.
2022-12-06Rollup merge of #105254 - cjgillot:issue-105251, r=oli-obkMatthias Krüger-0/+28
Recurse into nested impl-trait when computing variance. Fixes https://github.com/rust-lang/rust/issues/105251
2022-12-05Tweak "the following other types implement trait"Esteban Küber-9/+4
When *any* of the suggested impls is an exact match, *only* show the exact matches. This is particularly relevant for integer types. fix fmt
2022-12-04Recurse into nested impl-trait when computing variance.Camille GILLOT-0/+28
2022-12-04Use parent function WfCheckingContext to check RPITIT.Camille GILLOT-0/+24
2022-11-28Rollup merge of #104936 - cjgillot:self-rpit-orig-too, r=oli-obkMatthias Krüger-0/+66
Ignore bivariant parameters in test_type_match. https://github.com/rust-lang/rust/pull/103491 made opaque types bivariant with respect of some of their lifetime parameters. Because of this bivariance, some lifetime variables were not unified to anything during borrowck, and were considered as unequal by borrowck type test. This PR makes type test ignore the bivariant parameters in test_type_match. Fixes https://github.com/rust-lang/rust/issues/104815 r? `@oli-obk`
2022-11-26Pretty-print generators with their `generator_kind`Arpad Borsos-5/+5
After removing `GenFuture`, I special-cased async generators to pretty-print as `impl Future<Output = X>` mainly to avoid too much diagnostics changes originally. This now reverses that change so that async fn/blocks are pretty-printed as `[$movability `async` $something@$source-position]` in various diagnostics, and updates the tests that this touches.
2022-11-26Ignore bivariant parameters in test_type_match.Camille GILLOT-0/+66
2022-11-22Rollup merge of #103488 - oli-obk:impl_trait_for_tait, r=lcnrManish Goregaokar-46/+59
Allow opaque types in trait impl headers and rely on coherence to reject unsound cases r? ````@lcnr```` fixes #99840
2022-11-22Rollup merge of #104295 - compiler-errors:rpitit-generics-parity, r=eholkDylan DPC-0/+29
Check generics parity before collecting return-position `impl Trait`s in trait The only thing is that this duplicates the error message for number of generics mismatch, but we already deduplicate that error message in Cargo. I could add a flag to delay the error if the reviewer cares. Fixes #104281 Also drive-by adds a few comments to the `collect_trait_impl_trait_tys` method, and removes an unused argument from `compare_number_of_generics`.
2022-11-22Delay bug to deduplicate diagnosticsMichael Goulet-11/+1
2022-11-22Check generics parity between impl and trait before collecting RPITITsMichael Goulet-0/+39
2022-11-22Rollup merge of #104656 - c410-f3r:moar-errors, r=petrochenkovMatthias Krüger-0/+41
Move tests r? `@petrochenkov`
2022-11-21Allow opaque types in trait impl headers and rely on coherence to reject ↵Oli Scherer-46/+59
unsound cases
2022-11-21Auto merge of #103491 - cjgillot:self-rpit, r=oli-obkbors-10/+151
Support using `Self` or projections inside an RPIT/async fn I reuse the same idea as https://github.com/rust-lang/rust/pull/103449 to use variances to encode whether a lifetime parameter is captured by impl-trait. The current implementation of async and RPIT replace all lifetimes from the parent generics by `'static`. This PR changes the scheme ```rust impl<'a> Foo<'a> { fn foo<'b, T>() -> impl Into<Self> + 'b { ... } } opaque Foo::<'_a>::foo::<'_b, T>::opaque<'b>: Into<Foo<'_a>> + 'b; impl<'a> Foo<'a> { // OLD fn foo<'b, T>() -> Foo::<'static>::foo::<'static, T>::opaque::<'b> { ... } ^^^^^^^ the `Self` becomes `Foo<'static>` // NEW fn foo<'b, T>() -> Foo::<'a>::foo::<'b, T>::opaque::<'b> { ... } ^^ the `Self` stays `Foo<'a>` } ``` There is the same issue with projections. In the example, substitute `Self` by `<T as Trait<'b>>::Assoc` in the sugared version, and `Foo<'_a>` by `<T as Trait<'_b>>::Assoc` in the desugared one. This allows to support `Self` in impl-trait, since we do not replace lifetimes by `'static` any more. The same trick allows to use projections like `T::Assoc` where `Self` is allowed. The feature is gated behind a `impl_trait_projections` feature gate. The implementation relies on 2 tweaking rules for opaques in 2 places: - we only relate substs that correspond to captured lifetimes during TypeRelation; - we only list captured lifetimes in choice region computation. For simplicity, I encoded the "capturedness" of lifetimes as a variance, `Bivariant` vs `Invariant` for unused vs captured lifetimes. The `variances_of` query used to ICE for opaques. Impl-trait that do not reference `Self` or projections will have their variances as: - `o` (invariant) for each parent type or const; - `*` (bivariant) for each parent lifetime --> will not participate in borrowck; - `o` (invariant) for each own lifetime. Impl-trait that does reference `Self` and/or projections will have some parent lifetimes marked as `o` (as the example above), and participate in type relation and borrowck. In the example above, `variances_of(opaque) = ['_a: o, '_b: *, T: o, 'b: o]`. r? types cc `@compiler-errors` , as you asked about the issue with `Self` and projections.
2022-11-20Move testsCaio-0/+41
2022-11-19Rollup merge of #104593 - compiler-errors:rpitit-object-safety-spans, ↵Matthias Krüger-6/+6
r=fee1-dead Improve spans for RPITIT object-safety errors No reason why we can't point at the `impl Trait` that causes the object-safety violation. Also [drive-by: Add is_async fn to hir::IsAsync](https://github.com/rust-lang/rust/pull/104593/commits/c4165f3a965e258531928180195637455299c6f3), which touches clippy too.
2022-11-19Improve spans for RPITIT object-safety errorsMichael Goulet-6/+6
2022-11-18Add testMichael Goulet-0/+47
2022-11-15Rollup merge of #104258 - compiler-errors:tait-closure-deduce, r=oli-obkMatthias Krüger-0/+15
Deduce closure signature from a type alias `impl Trait`'s supertraits r? `@oli-obk` Basically pass the TAIT's bounds through the same method that we're using to deduce a signature from infer var closure bounds. Does this need a new FCP? I see it as a logical extension of #101834, but happy to rfcbot a new one if it does.
2022-11-13Create bidirectional bounds between original and duplicated parameters.Camille GILLOT-4/+1
2022-11-12Make impl_trait_projections a feature gate.Camille GILLOT-2/+146
2022-11-12Bless ui tests.Camille GILLOT-4/+4
2022-11-12Auto merge of #104310 - Dylan-DPC:rollup-wgt1z4a, r=Dylan-DPCbors-0/+135
Rollup of 7 pull requests Successful merges: - #102049 (Add the `#[derive_const]` attribute) - #103970 (Unhide unknown spans) - #104206 (Remove `save_and_restore_in_snapshot_flag`, use `ObligationCtxt` more) - #104214 (Emit error in `collecting_trait_impl_trait_tys` on mismatched signatures) - #104267 (rustdoc: use checkbox instead of switch for settings toggles) - #104302 (Update cargo) - #104303 (UI tests can be assigned to T-compiler) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2022-11-11Visit opaque types during type collection too.Camille GILLOT-228/+25
2022-11-11Resolve lifetimes using the regular logic for RPIT.Camille GILLOT-25/+202
2022-11-10Deduce closure signature from TAIT supertraitsMichael Goulet-0/+15
2022-11-09Emit error in `collecting_trait_impl_trait_tys` on mismatched signaturesNilstrieb-0/+135
Previously, a `delay_span_bug` was isssued, failing normalization. This create a `TyKind::Error` in the signature, which caused `compare_predicate_entailment` to swallow its signature mismatch error, causing ICEs because no error was emitted.
2022-11-08Rollup merge of #103827 - compiler-errors:rpitit-substs-compat, r=wesleywiserManish Goregaokar-0/+102
Properly remap and check for substs compatibility in `confirm_impl_trait_in_trait_candidate` Fixes #103824
2022-11-08selection failure: recompute applicable implslcnr-5/+8
2022-11-01Fix ICE in default impl error reportingMichael Goulet-0/+49
2022-11-01Remap RPITIT substs properlyMichael Goulet-0/+24
2022-11-01Check for substs compatibility for RPITITsMichael Goulet-0/+29
2022-10-30Rollup merge of #93582 - WaffleLapkin:rpitirpit, r=compiler-errorsDylan DPC-75/+256
Allow `impl Fn() -> impl Trait` in return position _This was originally proposed as part of #93082 which was [closed](https://github.com/rust-lang/rust/pull/93082#issuecomment-1027225715) due to allowing `impl Fn() -> impl Trait` in argument position._ This allows writing the following function signatures: ```rust fn f0() -> impl Fn() -> impl Trait; fn f3() -> &'static dyn Fn() -> impl Trait; ``` These signatures were already allowed for common traits and associated types, there is no reason why `Fn*` traits should be special in this regard. `impl Trait` in both `f0` and `f3` means "new existential type", just like with `-> impl Iterator<Item = impl Trait>` and such. Arrow in `impl Fn() ->` is right-associative and binds from right to left, it's tested by [this test](https://github.com/WaffleLapkin/rust/blob/a819fecb8dea438fc70488ddec30a61e52942672/src/test/ui/impl-trait/impl_fn_associativity.rs). There even is a test that `f0` compiles: https://github.com/rust-lang/rust/blob/2f004d2d401682e553af3984ebd9a3976885e752/src/test/ui/impl-trait/nested_impl_trait.rs#L25-L28 But it was changed in [PR 48084 (lines)](https://github.com/rust-lang/rust/pull/48084/files#diff-ccecca938872d65ffe8cd1c3ef1956e309fac83bcda547d8b16b89257e53a437R37) to test the opposite, probably unintentionally given [PR 48084 (lines)](https://github.com/rust-lang/rust/pull/48084/files#diff-5a02f1ed43debed1fd24f7aad72490064f795b9420f15d847bac822aa4621a1cR476-R477). r? `@nikomatsakis` ---- This limitation is especially annoying with async code, since it forces one to write this: ```rust trait AsyncFn3<A, B, C>: Fn(A, B, C) -> <Self as AsyncFn3<A, B, C>>::Future { type Future: Future<Output = Self::Out>; type Out; } impl<A, B, C, Fut, F> AsyncFn3<A, B, C> for F where F: Fn(A, B, C) -> Fut, Fut: Future, { type Future = Fut; type Out = Fut::Output; } fn async_closure() -> impl AsyncFn3<i32, i32, i32, Out = u32> { |a, b, c| async move { (a + b + c) as u32 } } ``` Instead of: ```rust fn async_closure() -> impl Fn(i32, i32, i32) -> impl Future<Output = u32> { |a, b, c| async move { (a + b + c) as u32 } } ```
2022-10-28Rollup merge of #103608 - compiler-errors:rpitit-early-lt, r=cjgillotMatthias Krüger-0/+23
Remap early bound lifetimes in return-position `impl Trait` in traits too Fixes part of #103457 r? ``@cjgillot,`` though feel free to reassign, just thought you'd have sufficient context to review.
2022-10-27Remap early bound lifetimes tooMichael Goulet-0/+23
2022-10-26No need to probe when relating opaques in nll_relateMichael Goulet-0/+24
2022-10-25Name impl trait in region bound suggestionMichael Goulet-16/+16
2022-10-25adopt to compiler changesMaybe Waffle-9/+20
2022-10-25--blessMaybe Waffle-89/+106
2022-10-25Add even more tests for `impl Fn() -> impl Trait`Maybe Waffle-1/+53
2022-10-25Add more tests for `impl Fn() -> impl Trait`Maybe Waffle-0/+106
2022-10-25Allow `impl Fn() -> impl Trait` in return positionMaybe Waffle-66/+61
This allows writing the following function signatures: ```rust fn f0() -> impl Fn() -> impl Trait; fn f3() -> &'static dyn Fn() -> impl Trait; ``` These signatures were already allowed for common traits and associated types, there is no reason why `Fn*` traits should be special in this regard.
2022-10-24Delay span bug when we can't map lifetimes back in collect_trait_impl_trait_tysMichael Goulet-0/+37
2022-10-23Rollup merge of #103414 - compiler-errors:rpit-print-lt, r=cjgillotMichael Howell-2/+2
Pretty print lifetimes captured by RPIT This specifically makes the output in #103409 change from: ```diff error: `impl` item signature doesn't match `trait` item signature --> $DIR/signature-mismatch.rs:15:5 | LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>; | ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>>` ... LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>>` + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2` | = note: expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>>` - found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>>` + found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2` = help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait` = help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output error: aborting due to previous error ``` Along with the UI tests in this PR, which I think are all improvements! r? `@oli-obk` though feel free to re-roll
2022-10-23Rollup merge of #103368 - compiler-errors:normalization-ambiguity-bug, r=oli-obkMatthias Krüger-0/+135
Delay ambiguity span bug in normalize query iff not rustdoc Oli and I decided that the compiler debt of adding another usage of `tcx.sess.opts.actually_rustdoc` is fine, because we don't really want to add more complexity to the normalize query, and moving rustdoc to use fulfill normalization (`fully_normalize`, i.e. not use the normalize query) is unnecessary overhead given that it's skipping binders and stuff. r? oli-obk Fixes #102827 Fixes #103181
2022-10-22Pretty print lifetimes captured by RPITMichael Goulet-2/+2
2022-10-21testsMichael Goulet-0/+135
2022-10-21Handle RPITITs properly in register_hidden_typeMichael Goulet-13/+50
2022-10-20Auto merge of #103205 - spastorino:fix-rpits-lifetime-remapping, r=cjgillotbors-0/+23
Do anonymous lifetimes remapping correctly for nested rpits Closes #103141 r? `@cjgillot` `@nikomatsakis` This fixes a stable to stable regression that in my opinion is `P-critical` so, we probably want to backport it all the way up to stable.