Skip to content

-Znext-solver ambiguous opaque types in HIR typeck result in poor errors #146231

@lcnr

Description

@lcnr
fn foo() -> impl Sized {
    foo()
}

results in

error[E0282]: type annotations needed
 --> src/main.rs:2:5
  |
2 |     foo()
  |     ^^^^^ cannot infer type

error: aborting due to 1 previous error

we should mention that this ambiguity is in the hidden type of an opaque

let infer_var = hidden_type
.ty
.walk()
.filter_map(ty::GenericArg::as_term)
.find(|term| term.is_infer())
.unwrap_or_else(|| hidden_type.ty.into());
self.err_ctxt()
.emit_inference_failure_err(
self.body_id,
hidden_type.span,
infer_var,
TypeAnnotationNeeded::E0282,
false,
)
.emit()

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-impl-traitArea: `impl Trait`. Universally / existentially quantified anonymous types with static dispatch.D-terseDiagnostics: An error or lint that doesn't give enough information about the problem at hand.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.WG-trait-system-refactorThe Rustc Trait System Refactor Initiative (-Znext-solver)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions