diff --git a/compiler/rustc_hir_typeck/src/opaque_types.rs b/compiler/rustc_hir_typeck/src/opaque_types.rs index 17e193d7f44ab..ae46378cd8241 100644 --- a/compiler/rustc_hir_typeck/src/opaque_types.rs +++ b/compiler/rustc_hir_typeck/src/opaque_types.rs @@ -198,6 +198,10 @@ impl<'tcx> FnCtxt<'_, 'tcx> { TypeAnnotationNeeded::E0282, false, ) + // The shared E0282 label only says "cannot infer type", which gives no + // hint that the ambiguity is in an opaque's hidden type rather than an + // ordinary local inference failure. + .with_note("cannot infer type of hidden type of opaque") .emit() } } diff --git a/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.next.stderr b/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.next.stderr index d6294efbd2803..d2ed88c1125ba 100644 --- a/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.next.stderr +++ b/tests/ui/generic-associated-types/ambig-hr-projection-issue-93340.next.stderr @@ -4,6 +4,7 @@ error[E0282]: type annotations needed LL | cmp_eq | ^^^^^^ cannot infer type of the type parameter `A` declared on the function `cmp_eq` | + = note: cannot infer type of hidden type of opaque help: consider specifying the generic arguments | LL | cmp_eq:: diff --git a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr index 723dd097f9b97..dd8375c8b9409 100644 --- a/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr +++ b/tests/ui/higher-ranked/trait-bounds/normalize-under-binder/norm-before-method-resolution-opaque-type.next.stderr @@ -4,6 +4,7 @@ error[E0282]: type annotations needed for `>::Out<_>` LL | let x = *x; | ^ | + = note: cannot infer type of hidden type of opaque help: consider giving `x` an explicit type, where the placeholders `_` are specified | LL | let x: <_ as Trait<'static>>::Out<_> = *x; diff --git a/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr b/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr index 7170efc863870..d52cd6833c342 100644 --- a/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr +++ b/tests/ui/impl-trait/auto-trait-selection-freeze.next.stderr @@ -4,6 +4,7 @@ error[E0282]: type annotations needed LL | if false { is_trait(foo()) } else { Default::default() } | ^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `is_trait` | + = note: cannot infer type of hidden type of opaque help: consider specifying the generic arguments | LL | if false { is_trait::(foo()) } else { Default::default() } diff --git a/tests/ui/impl-trait/auto-trait-selection.next.stderr b/tests/ui/impl-trait/auto-trait-selection.next.stderr index 0f33aca301914..ec65bdc48a089 100644 --- a/tests/ui/impl-trait/auto-trait-selection.next.stderr +++ b/tests/ui/impl-trait/auto-trait-selection.next.stderr @@ -4,6 +4,7 @@ error[E0282]: type annotations needed LL | if false { is_trait(foo()) } else { Default::default() } | ^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `is_trait` | + = note: cannot infer type of hidden type of opaque help: consider specifying the generic arguments | LL | if false { is_trait::(foo()) } else { Default::default() } diff --git a/tests/ui/impl-trait/non-defining-uses/ice-issue-146191.next.stderr b/tests/ui/impl-trait/non-defining-uses/ice-issue-146191.next.stderr index e146d492155f0..b6a953d218be4 100644 --- a/tests/ui/impl-trait/non-defining-uses/ice-issue-146191.next.stderr +++ b/tests/ui/impl-trait/non-defining-uses/ice-issue-146191.next.stderr @@ -3,6 +3,8 @@ error[E0282]: type annotations needed | LL | fn create_complex_future() -> impl Future { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type + | + = note: cannot infer type of hidden type of opaque error: aborting due to 1 previous error diff --git a/tests/ui/impl-trait/non-defining-uses/unconstrained-hidden-type-issue-146231.next.stderr b/tests/ui/impl-trait/non-defining-uses/unconstrained-hidden-type-issue-146231.next.stderr new file mode 100644 index 0000000000000..39900da55df78 --- /dev/null +++ b/tests/ui/impl-trait/non-defining-uses/unconstrained-hidden-type-issue-146231.next.stderr @@ -0,0 +1,11 @@ +error[E0282]: type annotations needed + --> $DIR/unconstrained-hidden-type-issue-146231.rs:15:24 + | +LL | fn recursive_rpit() -> impl Sized { + | ^^^^^^^^^^ cannot infer type + | + = note: cannot infer type of hidden type of opaque + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0282`. diff --git a/tests/ui/impl-trait/non-defining-uses/unconstrained-hidden-type-issue-146231.rs b/tests/ui/impl-trait/non-defining-uses/unconstrained-hidden-type-issue-146231.rs new file mode 100644 index 0000000000000..a60fe5a20eaca --- /dev/null +++ b/tests/ui/impl-trait/non-defining-uses/unconstrained-hidden-type-issue-146231.rs @@ -0,0 +1,20 @@ +//@ revisions: current next +//@[current] check-pass +//@[next] compile-flags: -Znext-solver +//@ ignore-compare-mode-next-solver (explicit revisions) + +// The only use of the opaque below is the recursive call, so nothing ever +// constrains its hidden type. The error has to say that the ambiguity is in +// the opaque's hidden type, otherwise it reads as an ordinary inference +// failure and gives no hint that an opaque is involved at all. +// +// Only the next solver reports this; the old solver accepts the item. + +#![allow(unconditional_recursion)] + +fn recursive_rpit() -> impl Sized { + //[next]~^ ERROR type annotations needed + recursive_rpit() +} + +fn main() {} diff --git a/tests/ui/impl-trait/recursive-in-exhaustiveness.next.stderr b/tests/ui/impl-trait/recursive-in-exhaustiveness.next.stderr index 59bcdd9f3cea2..878e10557f26a 100644 --- a/tests/ui/impl-trait/recursive-in-exhaustiveness.next.stderr +++ b/tests/ui/impl-trait/recursive-in-exhaustiveness.next.stderr @@ -4,6 +4,7 @@ error[E0282]: type annotations needed for `(_,)` LL | let (x,) = (build(x),); | ^^^^ | + = note: cannot infer type of hidden type of opaque help: consider giving this pattern a type, where the placeholder `_` is specified | LL | let (x,): (_,) = (build(x),); @@ -15,6 +16,7 @@ error[E0282]: type annotations needed for `((_,),)` LL | let (x,) = (build2(x),); | ^^^^ | + = note: cannot infer type of hidden type of opaque help: consider giving this pattern a type, where the placeholder `_` is specified | LL | let (x,): ((_,),) = (build2(x),); @@ -25,6 +27,8 @@ error[E0282]: type annotations needed | LL | fn build3(x: T) -> impl Sized { | ^^^^^^^^^^ cannot infer type + | + = note: cannot infer type of hidden type of opaque error: aborting due to 3 previous errors diff --git a/tests/ui/impl-trait/two_tait_defining_each_other2.next.stderr b/tests/ui/impl-trait/two_tait_defining_each_other2.next.stderr index fac4776905d06..a2d25fafb2a0b 100644 --- a/tests/ui/impl-trait/two_tait_defining_each_other2.next.stderr +++ b/tests/ui/impl-trait/two_tait_defining_each_other2.next.stderr @@ -3,6 +3,8 @@ error[E0282]: type annotations needed | LL | fn muh(x: A) -> B { | ^ cannot infer type + | + = note: cannot infer type of hidden type of opaque error: aborting due to 1 previous error diff --git a/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.is_send.stderr b/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.is_send.stderr index 84f9d784b042c..fc285abc9fe40 100644 --- a/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.is_send.stderr +++ b/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.is_send.stderr @@ -3,6 +3,8 @@ error[E0282]: type annotations needed | LL | needs_send::(); | ^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `needs_send` + | + = note: cannot infer type of hidden type of opaque error: aborting due to 1 previous error diff --git a/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.not_send.stderr b/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.not_send.stderr index 84f9d784b042c..fc285abc9fe40 100644 --- a/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.not_send.stderr +++ b/tests/ui/traits/next-solver/opaques/dont-type_of-tait-in-defining-scope.not_send.stderr @@ -3,6 +3,8 @@ error[E0282]: type annotations needed | LL | needs_send::(); | ^^^^^^^^^^^^^^^^^ cannot infer type of the type parameter `T` declared on the function `needs_send` + | + = note: cannot infer type of hidden type of opaque error: aborting due to 1 previous error diff --git a/tests/ui/traits/next-solver/opaques/recursive-hidden-type-canonicalization.stderr b/tests/ui/traits/next-solver/opaques/recursive-hidden-type-canonicalization.stderr index b3b173def6a01..d6fc9584ef516 100644 --- a/tests/ui/traits/next-solver/opaques/recursive-hidden-type-canonicalization.stderr +++ b/tests/ui/traits/next-solver/opaques/recursive-hidden-type-canonicalization.stderr @@ -4,6 +4,7 @@ error[E0282]: type annotations needed for `*mut _` LL | let r = random_paulis().unwrap(); | ^ | + = note: cannot infer type of hidden type of opaque help: consider giving `r` an explicit type, where the placeholder `_` is specified | LL | let r: *mut _ = random_paulis().unwrap(); diff --git a/tests/ui/type-alias-impl-trait/constrain_in_projection2.next.stderr b/tests/ui/type-alias-impl-trait/constrain_in_projection2.next.stderr index b8fe2f8e35628..3862479fee380 100644 --- a/tests/ui/type-alias-impl-trait/constrain_in_projection2.next.stderr +++ b/tests/ui/type-alias-impl-trait/constrain_in_projection2.next.stderr @@ -3,6 +3,8 @@ error[E0282]: type annotations needed | LL | let x = >::Assoc::default(); | ^^^ cannot infer type + | + = note: cannot infer type of hidden type of opaque error: aborting due to 1 previous error diff --git a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr index 3399c85a3034e..d025a821d1b45 100644 --- a/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr +++ b/tests/ui/type-alias-impl-trait/issue-84660-unsoundness.next.stderr @@ -12,6 +12,8 @@ error[E0282]: type annotations needed | LL | fn convert(_i: In) -> Self::Out { | ^^^^^^^^^ cannot infer type + | + = note: cannot infer type of hidden type of opaque error: aborting due to 2 previous errors diff --git a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr index 37bde4b18a45b..0c1e6a997ffec 100644 --- a/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr +++ b/tests/ui/type-alias-impl-trait/method_resolution_trait_method_from_opaque.next.stderr @@ -4,6 +4,7 @@ error[E0282]: type annotations needed LL | self.bar.next().unwrap(); | ^^^^ | + = note: cannot infer type of hidden type of opaque help: try using a fully qualified path to specify the expected types | LL - self.bar.next().unwrap(); diff --git a/tests/ui/type-alias-impl-trait/nested-tait-inference2.next.stderr b/tests/ui/type-alias-impl-trait/nested-tait-inference2.next.stderr index f70e4d4cae29e..9e8857201e72c 100644 --- a/tests/ui/type-alias-impl-trait/nested-tait-inference2.next.stderr +++ b/tests/ui/type-alias-impl-trait/nested-tait-inference2.next.stderr @@ -3,6 +3,8 @@ error[E0282]: type annotations needed | LL | fn foo() -> impl Foo { | ^^^^^^^^^^^^^^ cannot infer type + | + = note: cannot infer type of hidden type of opaque error: aborting due to 1 previous error