Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_hir_typeck/src/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<A, B, O>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ error[E0282]: type annotations needed for `<X as Trait<'static>>::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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T, U>(foo()) } else { Default::default() }
Expand Down
1 change: 1 addition & 0 deletions tests/ui/impl-trait/auto-trait-selection.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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::<T, U>(foo()) } else { Default::default() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error[E0282]: type annotations needed
|
LL | fn create_complex_future() -> impl Future<Output = impl ReturnsSend> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot infer type
|
= note: cannot infer type of hidden type of opaque

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -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`.
Original file line number Diff line number Diff line change
@@ -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() {}
4 changes: 4 additions & 0 deletions tests/ui/impl-trait/recursive-in-exhaustiveness.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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),);
Expand All @@ -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),);
Expand All @@ -25,6 +27,8 @@ error[E0282]: type annotations needed
|
LL | fn build3<T>(x: T) -> impl Sized {
| ^^^^^^^^^^ cannot infer type
|
= note: cannot infer type of hidden type of opaque

error: aborting due to 3 previous errors

Expand Down
2 changes: 2 additions & 0 deletions tests/ui/impl-trait/two_tait_defining_each_other2.next.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error[E0282]: type annotations needed
|
LL | needs_send::<Foo>();
| ^^^^^^^^^^^^^^^^^ 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error[E0282]: type annotations needed
|
LL | needs_send::<Foo>();
| ^^^^^^^^^^^^^^^^^ 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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error[E0282]: type annotations needed
|
LL | let x = <Foo as Trait<Bar>>::Assoc::default();
| ^^^ cannot infer type
|
= note: cannot infer type of hidden type of opaque

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ error[E0282]: type annotations needed
|
LL | fn foo() -> impl Foo<FooX> {
| ^^^^^^^^^^^^^^ cannot infer type
|
= note: cannot infer type of hidden type of opaque

error: aborting due to 1 previous error

Expand Down
Loading