1
Fork 0

Silence unecessary !Sized binding error

When gathering locals, we introduce a `Sized` obligation for each
binding in the pattern. *After* doing so, we typecheck the init
expression. If this has a type failure, we store `{type error}`, for
both the expression and the pattern. But later we store an inference
variable for the pattern.

We now avoid any override of an existing type on a hir node when they've
already been marked as `{type error}`, and on E0277, when it comes from
`VariableType` we silence the error in support of the type error.

Fix #117846.
This commit is contained in:
Esteban Küber 2024-03-07 00:08:56 +00:00
parent 3f2159fda5
commit b1575b71d4
6 changed files with 56 additions and 15 deletions

View file

@ -2954,6 +2954,16 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
}
ObligationCauseCode::VariableType(hir_id) => {
if let Some(typeck_results) = &self.typeck_results
&& let Some(ty) = typeck_results.node_type_opt(hir_id)
&& let ty::Error(_) = ty.kind()
{
err.note(format!(
"`{predicate}` isn't satisfied, but the type of this pattern is \
`{{type error}}`",
));
err.downgrade_to_delayed_bug();
}
match tcx.parent_hir_node(hir_id) {
Node::Local(hir::Local { ty: Some(ty), .. }) => {
err.span_suggestion_verbose(