rust/tests/ui/async-await
Matthias Krüger 9ec287dec2
Rollup merge of #120584 - compiler-errors:u, r=lcnr
For a rigid projection, recursively look at the self type's item bounds to fix the `associated_type_bounds` feature

Given a deeply nested rigid projection like `<<<T as Trait1>::Assoc1 as Trait2>::Assoc2 as Trait3>::Assoc3`, this PR adjusts both trait solvers to look at the item bounds for all of `Assoc3`, `Assoc2`, and `Assoc1` in order to satisfy a goal. We do this because the item bounds for projections may contain relevant bounds for *other* nested projections when the `associated_type_bounds` (ATB) feature is enabled. For example:

```rust
#![feature(associated_type_bounds)]

trait Trait1 {
    type Assoc1: Trait2<Assoc2: Foo>;
    // Item bounds for `Assoc1` are:
    // `<Self as Trait1>::Assoc1: Trait2`
    // `<<Self as Trait1>::Assoc1 as Trait2>::Assoc2: Foo`
}

trait Trait2 {
    type Assoc2;
}

trait Foo {}

fn hello<T: Trait1>(x: <<T as Trait1>::Assoc1 as Trait2>::Assoc2) {
    fn is_foo(_: impl Foo) {}
    is_foo(x);
    // Currently fails with:
    // ERROR the trait bound `<<Self as Trait1>::Assoc1 as Trait2>::Assoc2: Foo` is not satisfied
}
```

This has been a long-standing place of brokenness for ATBs, and is also part of the reason why ATBs currently desugar so differently in various positions (i.e. sometimes desugaring to param-env bounds, sometimes desugaring to RPITs, etc). For example, in RPIT and TAIT position, `impl Foo<Bar: Baz>` currently desugars to `impl Foo<Bar = impl Baz>` because we do not currently take advantage of these nested item bounds if we desugared them into a single set of item bounds on the opaque. This is obviously both strange and unnecessary if we just take advantage of these bounds as we should.

## Approach

This PR repeatedly peels off each projection of a given goal's self type and tries to match its item bounds against a goal, repeating with the self type of the projection. This is pretty straightforward to implement in the new solver, only requiring us to loop on the self type of a rigid projection to discover inner rigid projections, and we also need to introduce an extra probe so we can normalize them.

In the old solver, we can do essentially the same thing, however we rely on the fact that projections *should* be normalized already. This is obviously not always the case -- however, in the case that they are not fully normalized, such as a projection which has both infer vars and, we bail out with ambiguity if we hit an infer var for the self type.

## Caveats

⚠️ In the old solver, this has the side-effect of actually stalling some higher-ranked trait goals of the form `for<'a> <?0 as Tr<'a>>: Tr2`. Because we stall them, they no longer are eagerly treated as error -- this cause some existing `known-bug` tests to go from fail -> pass.

I'm pretty unconvinced that this is a problem since we make code that we expect to pass in the *new* solver also pass in the *old* solver, though this obviously doesn't solve the *full* problem.

## And then also...

We also adjust the desugaring of ATB to always desugar to a regular associated bound, rather than sometimes to an impl Trait **except** for when the ATB is present in a `dyn Trait`. We need to lower `dyn Trait<Assoc: Bar>` to `dyn Trait<Assoc = impl Bar>` because object types need all of their associated types specified.

I would also be in favor of splitting out the ATB feature and/or removing support for object types in order to stabilize just the set of positions for which the ATB feature is consistent (i.e. always elaborates to a bound).
2024-02-10 00:58:36 +01:00
..
async-closures Rollup merge of #120844 - compiler-errors:async-di, r=oli-obk 2024-02-09 19:21:19 +01:00
async-fn Error on incorrect item kind in async bound 2024-01-31 16:59:19 +00:00
auxiliary Add test 2023-01-19 15:46:08 +00:00
await-keyword Show number in error message even for one error 2023-11-24 19:15:52 +01:00
drop-order
future-sizes Coroutine variant fields can be uninitialized 2023-12-12 00:00:00 +00:00
in-trait Rollup merge of #120103 - compiler-errors:concrete-afits, r=oli-obk 2024-02-08 09:06:32 +01:00
issues Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
multiple-lifetimes Adjust tests for new drop and forget lints 2023-05-10 19:36:02 +02:00
return-type-notation For a rigid projection, recursively look at the self type's item bounds 2024-02-09 00:13:51 +00:00
track-caller Bless tests 2024-01-13 12:46:58 -05:00
argument-patterns.rs
async-assoc-fn-anon-lifetimes.rs
async-await-let-else.rs Revert duplication of tests. 2023-09-23 13:34:07 +00:00
async-await-let-else.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
async-await.rs Remove revisions for THIR unsafeck 2024-01-05 09:30:27 +00:00
async-block-control-flow-static-semantics.rs
async-block-control-flow-static-semantics.stderr adjust how closure/generator types and rvalues are printed 2023-09-21 22:20:58 +02:00
async-borrowck-escaping-block-error.fixed
async-borrowck-escaping-block-error.rs
async-borrowck-escaping-block-error.stderr
async-borrowck-escaping-closure-error.rs Bless tests, add comments 2024-02-06 02:22:58 +00:00
async-borrowck-escaping-closure-error.stderr Bless tests, add comments 2024-02-06 02:22:58 +00:00
async-closure-matches-expr.rs
async-closure.rs
async-error-span.rs Bless tests. 2023-09-23 13:47:30 +00:00
async-error-span.stderr Bless tests. 2023-09-23 13:47:30 +00:00
async-fn-elided-impl-lifetime-parameter.rs
async-fn-nonsend.rs Bless tests. 2023-09-23 13:47:30 +00:00
async-fn-nonsend.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
async-fn-path-elision.rs
async-fn-path-elision.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
async-fn-send-uses-nonsend.rs
async-fn-size-moved-locals.rs Adjust compiler tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
async-fn-size-uninit-locals.rs Adjust compiler tests for unused_tuple_struct_fields -> dead_code 2024-01-02 15:34:37 -05:00
async-fn-size.rs
async-is-unwindsafe.rs
async-is-unwindsafe.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
async-matches-expr.rs
async-trait-fn.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
async-unsafe-fn-call-in-safe.rs Stabilize THIR unsafeck 2024-01-05 10:00:59 +00:00
async-unsafe-fn-call-in-safe.stderr Stabilize THIR unsafeck 2024-01-05 10:00:59 +00:00
async-with-closure.rs
await-into-future.rs
await-sequence.rs Bless tests. 2023-09-23 13:47:30 +00:00
await-unsize.rs
awaiting-unsized-param.rs Revert duplication of tests. 2023-09-23 13:34:07 +00:00
awaiting-unsized-param.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
bound-normalization.rs
clone-suggestion.fixed Tweak await span 2023-04-27 17:18:11 +00:00
clone-suggestion.rs Tweak await span 2023-04-27 17:18:11 +00:00
clone-suggestion.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
conditional-and-guaranteed-initialization.rs
const-async-fn-in-main.rs add test 2023-09-26 20:15:28 +00:00
const-async-fn-in-main.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
coroutine-desc.rs Rename lots of files that had generator in their name 2023-10-20 21:14:02 +00:00
coroutine-desc.stderr Rename lots of files that had generator in their name 2023-10-20 21:14:02 +00:00
coroutine-not-future.rs Rename lots of files that had generator in their name 2023-10-20 21:14:02 +00:00
coroutine-not-future.stderr Rename lots of files that had generator in their name 2023-10-20 21:14:02 +00:00
debug-ice-attempted-to-add-with-overflow.rs Add test for rust-lang#114912 2023-09-29 22:39:02 +10:00
debug-ice-attempted-to-add-with-overflow.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
deep-futures-are-freeze.rs Normalize before checking if local is freeze in deduced_param_attrs 2023-08-17 14:33:24 -07:00
default-struct-update.rs Bless tests. 2023-09-23 13:47:30 +00:00
dont-print-desugared-async.rs
dont-print-desugared-async.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
dont-suggest-await-on-method-return-mismatch.rs
dont-suggest-await-on-method-return-mismatch.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
dont-suggest-missing-await.rs
dont-suggest-missing-await.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
drop-and-assign.rs Bless tests. 2023-09-23 13:47:30 +00:00
drop-track-bad-field-in-fru.rs Bless tests. 2023-09-23 13:47:30 +00:00
drop-track-bad-field-in-fru.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
drop-track-field-assign-nonsend.rs Bless tests. 2023-09-23 13:47:30 +00:00
drop-track-field-assign-nonsend.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
drop-track-field-assign.rs Bless tests. 2023-09-23 13:47:30 +00:00
drop-tracking-unresolved-typeck-results.rs Bless tests. 2023-09-23 13:47:30 +00:00
drop-tracking-unresolved-typeck-results.stderr Add a note to duplicate diagnostics 2023-10-05 01:04:41 +00:00
edition-deny-async-fns-2015.rs Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
edition-deny-async-fns-2015.stderr Stabilize AFIT and RPITIT 2023-10-13 21:01:36 +00:00
expansion-in-attrs.rs
feature-async-closure.rs
feature-async-closure.stderr Bless tests 2024-01-13 12:46:58 -05:00
feature-async-for-loop.rs Add additional tests and update existing tests 2023-12-19 16:12:17 -08:00
feature-async-for-loop.stderr Bless tests 2024-01-13 12:46:58 -05:00
feature-self-return-type.rs Stabilize impl_trait_projections 2023-09-08 03:45:36 +00:00
feature-self-return-type.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
field-assign-nonsend.rs Revert duplication of tests. 2023-09-23 13:34:07 +00:00
field-assign-nonsend.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
field-assign.rs Revert duplication of tests. 2023-09-23 13:34:07 +00:00
for-await-2015.rs Add additional tests and update existing tests 2023-12-19 16:12:17 -08:00
for-await-consumes-iter.rs Add additional tests and update existing tests 2023-12-19 16:12:17 -08:00
for-await-consumes-iter.stderr Update test outputs 2023-12-22 11:01:07 -08:00
for-await-passthrough.rs Remove unnecessary lets and borrowing from Waker::noop() usage. 2024-01-17 12:00:27 -08:00
for-await.rs Remove unnecessary lets and borrowing from Waker::noop() usage. 2024-01-17 12:00:27 -08:00
future-contains-err-issue-115188.rs More precisely detect cycle errors from type_of on opaque 2023-08-27 22:03:16 +00:00
future-contains-err-issue-115188.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
futures-api.rs
generics-and-bounds.rs
incorrect-move-async-order-issue-79694.fixed
incorrect-move-async-order-issue-79694.rs
incorrect-move-async-order-issue-79694.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
inference_var_self_argument.rs Don't ICE when deducing future output if other errors already occurred 2024-01-17 16:27:57 +00:00
inference_var_self_argument.stderr Don't ICE when deducing future output if other errors already occurred 2024-01-17 16:27:57 +00:00
interior-with-const-generic-expr.rs
issue-54239-private-type-triggers-lint.rs
issue-60709.rs Remove asmjs from tests 2023-10-28 23:11:03 -07:00
issue-61076.rs tweak logic of "unknown field" label 2023-11-18 00:40:11 +00:00
issue-61076.stderr tweak logic of "unknown field" label 2023-11-18 00:40:11 +00:00
issue-61452.rs
issue-61452.stderr Do not set up wrong span for adjustments 2023-07-10 20:09:26 +00:00
issue-61793.rs s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
issue-62658.rs s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
issue-63832-await-short-temporary-lifetime-1.rs
issue-63832-await-short-temporary-lifetime.rs
issue-64130-1-sync.rs Bless tests. 2023-09-23 13:47:30 +00:00
issue-64130-1-sync.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
issue-64130-2-send.rs Bless tests. 2023-09-23 13:47:30 +00:00
issue-64130-2-send.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
issue-64130-3-other.rs Bless tests. 2023-09-23 13:47:30 +00:00
issue-64130-3-other.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
issue-64130-4-async-move.rs Bless tests. 2023-09-23 13:47:30 +00:00
issue-64130-non-send-future-diags.rs
issue-64130-non-send-future-diags.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
issue-64391.rs
issue-66312.rs Avoid a track_errors by bubbling up most errors from check_well_formed 2023-10-20 08:46:27 +00:00
issue-66312.stderr Reorder check_item_type diagnostics so they occur next to the corresponding check_well_formed diagnostics 2024-01-02 14:17:56 +00:00
issue-66387-if-without-else.rs
issue-66387-if-without-else.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-67252-unnamed-future.rs Bless tests. 2023-09-23 13:47:30 +00:00
issue-67252-unnamed-future.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
issue-67651.rs
issue-67651.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-67765-async-diagnostic.rs
issue-67765-async-diagnostic.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-68112.rs Bless tests. 2023-09-23 13:47:30 +00:00
issue-68112.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
issue-68523-start.rs Change start to #[start] in some diagnosis 2023-09-22 15:58:43 +02:00
issue-68523-start.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-68523.rs
issue-68523.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-69446-fnmut-capture.rs
issue-69446-fnmut-capture.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-70594.rs Eagerly return ExprKind::Err on yield/await in wrong coroutine context 2023-11-28 19:29:56 +00:00
issue-70594.stderr Fix spans for bad await in inline const 2023-11-28 19:29:56 +00:00
issue-70818.rs Revert duplication of tests. 2023-09-23 13:34:07 +00:00
issue-70818.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-70935-complex-spans.rs Continue to borrowck even if there were previous errors 2024-02-08 08:10:43 +00:00
issue-70935-complex-spans.stderr Continue to borrowck even if there were previous errors 2024-02-08 08:10:43 +00:00
issue-71137.rs
issue-71137.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
issue-72442.rs
issue-72442.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-72470-llvm-dominate.rs
issue-72590-type-error-sized.rs
issue-72590-type-error-sized.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
issue-73050.rs
issue-73137.rs s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
issue-73541-1.rs
issue-73541-1.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-73541-2.rs
issue-73541-2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-73541-3.rs
issue-73541-3.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-73541.rs
issue-73541.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-73741-type-err.rs
issue-73741-type-err.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-74047.rs
issue-74047.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-74072-lifetime-name-annotations.rs Bless tests, add comments 2024-02-06 02:22:58 +00:00
issue-74072-lifetime-name-annotations.stderr Bless tests, add comments 2024-02-06 02:22:58 +00:00
issue-74497-lifetime-in-opaque.rs
issue-74497-lifetime-in-opaque.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-75785-confusing-named-region.rs
issue-75785-confusing-named-region.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-76547.rs
issue-76547.stderr
issue-77993-2.rs
issue-77993-2.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-78115.rs Move tests 2023-05-24 19:35:59 -03:00
issue-84841.rs
issue-84841.stderr
issue-86507.rs Revert duplication of tests. 2023-09-23 13:34:07 +00:00
issue-86507.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
issue-93197.rs Bless tests. 2023-09-23 13:47:30 +00:00
issue-93648.rs Bless tests. 2023-09-23 13:47:30 +00:00
issue-98634.rs Tweak E0271 wording 2023-01-30 21:51:35 +00:00
issue-98634.stderr Tweak await span 2023-04-27 17:18:11 +00:00
issue-101715.rs
issue-101715.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
issue-105501.rs
issue-107036.rs Add test 2023-01-19 15:46:08 +00:00
issue-108572.fixed Suggest pin!() instead of Pin::new() when appropriate 2023-08-14 19:41:57 +00:00
issue-108572.rs Suggest pin!() instead of Pin::new() when appropriate 2023-08-14 19:41:57 +00:00
issue-108572.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
missed-capture-issue-107414.rs Add more if let guard tests 2023-09-19 12:48:40 +00:00
move-part-await-return-rest-struct.rs
move-part-await-return-rest-tuple.rs
mutually-recursive-async-impl-trait-type.rs Point out source of recursion 2024-01-08 20:30:24 +00:00
mutually-recursive-async-impl-trait-type.stderr Make cycle error more resilient to where it starts 2024-01-08 20:30:24 +00:00
nested-in-impl.rs
no-async-const.rs Recover from incorrectly ordered/duplicated function keywords 2023-10-27 18:29:43 +00:00
no-async-const.stderr Recover from incorrectly ordered/duplicated function keywords 2023-10-27 18:29:43 +00:00
no-const-async.rs Remove identity_future indirection 2023-03-08 15:37:14 +01:00
no-const-async.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
no-move-across-await-struct.rs
no-move-across-await-struct.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
no-move-across-await-tuple.rs
no-move-across-await-tuple.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
no-non-guaranteed-initialization.rs
no-non-guaranteed-initialization.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
no-params-non-move-async-closure.rs Async closures will move params into the future always 2024-01-16 17:12:10 +00:00
no-std.rs
no-unsafe-async.rs Recover from incorrectly ordered/duplicated function keywords 2023-10-27 18:29:43 +00:00
no-unsafe-async.stderr Recover from incorrectly ordered/duplicated function keywords 2023-10-27 18:29:43 +00:00
non-trivial-drop.rs s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
normalize-output-in-signature-deduction.rs update use of feature flags 2023-12-14 15:22:37 +01:00
partial-drop-partial-reinit.rs Rename in preparation for moving the async printing out of CoroutineSource 2023-10-25 16:37:14 +00:00
partial-drop-partial-reinit.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
partial-initialization-across-await.rs
partial-initialization-across-await.stderr
pin-needed-to-poll-2.rs
pin-needed-to-poll-2.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
pin-needed-to-poll.rs
pin-needed-to-poll.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
proper-span-for-type-error.fixed
proper-span-for-type-error.rs
proper-span-for-type-error.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
recursive-async-impl-trait-type.rs Point out source of recursion 2024-01-08 20:30:24 +00:00
recursive-async-impl-trait-type.stderr Make cycle error more resilient to where it starts 2024-01-08 20:30:24 +00:00
repeat_count_const_in_async_fn.rs
return-ty-raw-ptr-coercion.rs
return-ty-unsize-coercion.rs
send-bound-async-closure.rs s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
suggest-missing-await-closure.fixed
suggest-missing-await-closure.rs
suggest-missing-await-closure.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
suggest-missing-await.rs
suggest-missing-await.stderr fix: improve the suggestion on future not awaited 2023-02-13 16:23:23 +01:00
suggest-switching-edition-on-await-cargo.rs recover primary span label 2023-11-16 17:00:23 +00:00
suggest-switching-edition-on-await-cargo.stderr recover primary span label 2023-11-16 17:00:23 +00:00
suggest-switching-edition-on-await.rs recover primary span label 2023-11-16 17:00:23 +00:00
suggest-switching-edition-on-await.stderr recover primary span label 2023-11-16 17:00:23 +00:00
task-context-arg.rs s/generator/coroutine/ 2023-10-20 21:14:01 +00:00
try-on-option-in-async.rs
try-on-option-in-async.stderr
type-parameter-send.rs
unnecessary-await.rs fix spans for removing .await on for expressions 2023-10-21 13:18:00 +02:00
unnecessary-await.stderr Provide more context on derived obligation error primary label 2024-01-30 21:28:18 +00:00
unreachable-lint-1.rs
unreachable-lint-1.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
unreachable-lint.rs
unresolved_type_param.rs Bless tests. 2023-09-23 13:47:30 +00:00
unresolved_type_param.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
unsized-across-await.rs Revert duplication of tests. 2023-09-23 13:34:07 +00:00
unsized-across-await.stderr Show number in error message even for one error 2023-11-24 19:15:52 +01:00
unused-lifetime.rs
unused-lifetime.stderr