rust/src/test/ui/impl-trait
Mazdak Farrokhzad ee535a0f95
Rollup merge of #66431 - Aaron1011:fix/opaque-type-infer, r=varkor
Fix 'type annotations needed' error with opaque types

Related: #66426

This commit adds handling for opaque types during inference variable
fallback. Type variables generated from the instantiation of opaque
types now fallback to the opaque type itself.

Normally, the type variable for an instantiated opaque type is either
unified with the concrete type, or with the opaque type itself (e.g when
a function returns an opaque type by calling another function).

However, it's possible for the type variable to be left completely
unconstrained. This can occur in code like this:

```rust
pub type Foo = impl Copy;
fn produce() -> Option<Foo> {
    None
}
```

Here, we'll instantatiate the `Foo` in `Option<Foo>` to a fresh type
variable, but we will never unify it with anything due to the fact
that we return a `None`.

This results in the error message:
```
type annotations needed: cannot resolve `_: std::marker::Copy
```

pointing at `pub type Foo = impl Copy`.

This message is not only confusing, it's incorrect. When an opaque type
inference variable is completely unconstrained, we can always fall back
to using the opaque type itself. This effectively turns that particular
use of the opaque type into a non-defining use, even if it appears in a
defining scope.
2019-11-19 13:10:17 +01:00
..
auxiliary tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
issues Rollup merge of #65785 - Centril:compat-to-error-2, r=oli-obk 2019-11-08 16:50:33 +01:00
multiple-lifetimes update tests 2019-10-27 09:39:14 -05:00
associated-impl-trait-type-generic-trait.rs Replace "existential" by "opaque" 2019-08-02 02:44:36 +01:00
associated-impl-trait-type-trivial.rs Replace "existential" by "opaque" 2019-08-02 02:44:36 +01:00
associated-impl-trait-type.rs Replace "existential" by "opaque" 2019-08-02 02:44:36 +01:00
auto-trait-leak-rpass.rs tests: Move run-pass tests with naming conflicts to ui 2019-07-27 18:56:17 +03:00
auto-trait-leak.rs Remove unnecessary ignore-tidy-linelength 2019-04-23 11:42:14 +01:00
auto-trait-leak.stderr On obligation errors point at the unfulfilled binding when possible 2019-09-22 11:33:12 -07:00
auto-trait-leak2.rs Remove unnecessary ignore-tidy-linelength 2019-04-23 11:42:14 +01:00
auto-trait-leak2.stderr On obligation errors point at the unfulfilled binding when possible 2019-09-22 11:33:12 -07:00
auto-trait.rs Add additional tests for type alias impl trait coherence 2019-09-24 15:59:02 -04:00
auto-trait.stderr Add additional tests for type alias impl trait coherence 2019-09-24 15:59:02 -04:00
bindings-opaque.rs add impl_trait_in_bindings to INCOMPLETE_FEATURES 2019-05-13 18:45:20 +03:00
bindings-opaque.stderr Give method not found a primary span label 2019-09-08 18:27:02 -07:00
bindings.rs add impl_trait_in_bindings to INCOMPLETE_FEATURES 2019-05-13 18:45:20 +03:00
bindings.stderr --bless tests due to INCOMPLETE_FEATURES being a lint. 2019-07-30 10:43:32 +02:00
bound-normalization-fail.rs Remove async_await gates from tests. 2019-08-20 03:08:42 +02:00
bound-normalization-fail.stderr Add explanation to type mismatch involving type params and assoc types 2019-09-18 17:30:35 -07:00
bound-normalization-pass.rs Remove async_await gates from tests. 2019-08-20 03:08:42 +02:00
bound-normalization-pass.stderr --bless post no async_await gates in tests. 2019-08-20 03:08:42 +02:00
bounds_regression.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
can-return-unconstrained-closure.rs Migrate compile-pass annotations to build-pass 2019-07-03 06:30:28 +09:00
closure-calling-parent-fn.rs Update test stderr with results of enabling unused lints 2019-09-08 11:32:28 -04:00
deprecated_annotation.rs Migrate compile-pass annotations to build-pass 2019-07-03 06:30:28 +09:00
dyn-trait-elided-two-inputs-assoc.rs distinguish object-lifetime-default elision from other elision 2019-08-19 13:50:42 -04:00
dyn-trait-elided-two-inputs-param.rs distinguish object-lifetime-default elision from other elision 2019-08-19 13:50:42 -04:00
dyn-trait-elided-two-inputs-ref-assoc.rs use static as object-lifetime default for type XX in Foo<Item=XX> 2019-08-19 13:50:44 -04:00
dyn-trait-elided-two-inputs-ref-param.rs distinguish object-lifetime-default elision from other elision 2019-08-19 13:50:42 -04:00
equality-rpass.rs tests: Move run-pass tests with naming conflicts to ui 2019-07-27 18:56:17 +03:00
equality.rs Remove licenses 2018-12-25 21:08:33 -07:00
equality.stderr hide --explain hint if error has no extended info 2019-04-18 13:29:28 -04:00
equality2.rs Remove licenses 2018-12-25 21:08:33 -07:00
equality2.stderr Add explanation to type mismatch involving type params and assoc types 2019-09-18 17:30:35 -07:00
example-calendar.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
example-st.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
extra-item.rs resolve: Do not skip extern prelude during speculative resolution 2018-10-17 10:31:37 +03:00
extra-item.stderr Update tests 2019-03-11 23:10:26 +03:00
hidden-lifetimes.rs Add better tests for hidden lifetimes in impl trait 2019-05-18 13:16:45 +01:00
hidden-lifetimes.stderr Print lifetimes with backticks 2019-10-11 16:08:53 +09:00
impl-generic-mismatch-ab.rs Remove licenses 2018-12-25 21:08:33 -07:00
impl-generic-mismatch-ab.stderr Prettify mismatched types error message in a special case 2019-11-02 14:55:03 +07:00
impl-generic-mismatch.rs consistent handling of missing sysroot spans 2019-11-02 23:15:45 +01:00
impl-generic-mismatch.stderr consistent handling of missing sysroot spans 2019-11-02 23:15:45 +01:00
impl-trait-plus-priority.rs Remove unecessary -Z continue-parse-after-error from tests 2019-05-30 18:57:17 -07:00
impl-trait-plus-priority.stderr Remove licenses 2018-12-25 21:08:33 -07:00
impl_trait_projections.rs Remove licenses 2018-12-25 21:08:33 -07:00
impl_trait_projections.stderr hide --explain hint if error has no extended info 2019-04-18 13:29:28 -04:00
issue-55872-1.rs Replace "existential" by "opaque" 2019-08-02 02:44:36 +01:00
issue-55872-1.stderr Handle more cases involving impl and trait 2019-10-15 13:55:43 -07:00
issue-55872-2.rs Remove async_await gates from tests. 2019-08-20 03:08:42 +02:00
issue-55872-2.stderr --bless post no async_await gates in tests. 2019-08-20 03:08:42 +02:00
issue-55872.rs Replace "existential" by "opaque" 2019-08-02 02:44:36 +01:00
issue-55872.stderr Replace "existential" by "opaque" 2019-08-02 02:44:36 +01:00
lifetimes.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
method-suggestion-no-duplication.rs Remove unnecessary ignore-tidy-linelength 2019-04-23 11:42:14 +01:00
method-suggestion-no-duplication.stderr Give method not found a primary span label 2019-09-08 18:27:02 -07:00
multiple-lifetimes.rs Migrate compile-pass annotations to build-pass 2019-07-03 06:30:28 +09:00
must_outlive_least_region_or_bound.nll.stderr update tests 2019-10-27 09:39:14 -05:00
must_outlive_least_region_or_bound.rs Suggest using anonymous lifetime in impl Trait return without hacks 2019-03-31 09:11:47 -07:00
must_outlive_least_region_or_bound.stderr Update ui tests 2019-11-07 13:02:34 +01:00
needs_least_region_or_bound.rs Update test stderr with results of enabling unused lints 2019-09-08 11:32:28 -04:00
negative-reasoning.rs Add additional tests for type alias impl trait coherence 2019-09-24 15:59:02 -04:00
negative-reasoning.stderr Add additional tests for type alias impl trait coherence 2019-09-24 15:59:02 -04:00
nesting.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
no-method-suggested-traits.rs Remove licenses 2018-12-25 21:08:33 -07:00
no-method-suggested-traits.stderr Fixed grammar in one diagnostic and blessed tests. 2019-09-30 01:15:25 +01:00
no-trait.rs Remove licenses 2018-12-25 21:08:33 -07:00
no-trait.stderr Update tests 2019-03-11 23:10:26 +03:00
recursive-impl-trait-type-direct.rs Apply suggestions from code review 2019-10-25 18:50:40 +01:00
recursive-impl-trait-type-direct.stderr Don't ICE for completely unexpandable impl Trait types 2019-10-24 21:33:09 +01:00
recursive-impl-trait-type-indirect.rs Don't ICE for completely unexpandable impl Trait types 2019-10-24 21:33:09 +01:00
recursive-impl-trait-type-indirect.stderr Don't ICE for completely unexpandable impl Trait types 2019-10-24 21:33:09 +01:00
recursive-impl-trait-type-through-non-recursive.rs Don't ICE for completely unexpandable impl Trait types 2019-10-24 21:33:09 +01:00
recursive-impl-trait-type-through-non-recursive.stderr Don't ICE for completely unexpandable impl Trait types 2019-10-24 21:33:09 +01:00
region-escape-via-bound-contravariant-closure.rs Remove feature(nll) when compare mode is sufficient 2019-05-12 18:46:43 +01:00
region-escape-via-bound-contravariant.rs Remove feature(nll) when compare mode is sufficient 2019-05-12 18:46:43 +01:00
region-escape-via-bound.rs Remove feature(nll) when compare mode is sufficient 2019-05-12 18:46:43 +01:00
region-escape-via-bound.stderr Print lifetimes with backticks 2019-10-11 16:08:53 +09:00
return-position-impl-trait-minimal.rs Replace "existential" by "opaque" 2019-08-02 02:44:36 +01:00
static-return-lifetime-infered.nll.stderr update tests 2019-10-27 09:39:14 -05:00
static-return-lifetime-infered.rs Remove licenses 2018-12-25 21:08:33 -07:00
static-return-lifetime-infered.stderr Print lifetimes with backticks 2019-10-11 16:08:53 +09:00
trait_type.rs Remove licenses 2018-12-25 21:08:33 -07:00
trait_type.stderr Suggest missing item from trait in impl 2019-11-06 10:00:59 -08:00
type-alias-impl-trait-in-fn-body.rs Replace "existential" by "opaque" 2019-08-02 02:44:36 +01:00
type_parameters_captured.nll.stderr Change compare mode to use -Zborrowck=mir 2019-05-12 18:46:43 +01:00
type_parameters_captured.rs Remove licenses 2018-12-25 21:08:33 -07:00
type_parameters_captured.stderr Remove licenses 2018-12-25 21:08:33 -07:00
universal-mismatched-type.rs Remove licenses 2018-12-25 21:08:33 -07:00
universal-mismatched-type.stderr Update tests 2019-11-02 13:23:28 +07:00
universal-two-impl-traits.rs Remove licenses 2018-12-25 21:08:33 -07:00
universal-two-impl-traits.stderr Update tests 2019-11-02 13:23:28 +07:00
universal_hrtb_anon.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
universal_hrtb_named.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
universal_in_adt_in_parameters.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
universal_in_impl_trait_in_parameters.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
universal_in_trait_defn_parameters.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
universal_multiple_bounds.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
universal_wrong_bounds.rs resolve: Attempt to resolve unresolved paths in macro namespace 2019-07-18 13:42:45 +03:00
universal_wrong_bounds.stderr Increase spacing for suggestions in diagnostics 2019-10-24 12:26:01 -07:00
where-allowed-2.rs Fix 'type annotations needed' error with opaque types 2019-11-18 14:01:36 -05:00
where-allowed-2.stderr Fix 'type annotations needed' error with opaque types 2019-11-18 14:01:36 -05:00
where-allowed.rs Fix 'type annotations needed' error with opaque types 2019-11-18 14:01:36 -05:00
where-allowed.stderr Update test output 2019-11-18 14:01:37 -05:00
xcrate.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00
xcrate_simple.rs tests: Move run-pass tests without naming conflicts to ui 2019-07-27 18:56:16 +03:00