fix [type error] for error E0029 and E0277
check explicitly for the type references error if ty.references_error() is true change the error to be err.delay_as_bug() and prevent the error E0029 and E0277 from emitting out this fix #105946
This commit is contained in:
parent
df756439df
commit
10dbcf0630
5 changed files with 75 additions and 4 deletions
|
@ -1387,7 +1387,6 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
self.note_obligation_cause(&mut err, &obligation);
|
||||
self.point_at_returns_when_relevant(&mut err, &obligation);
|
||||
|
||||
err.emit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -248,7 +248,7 @@ pub trait TypeErrCtxtExt<'tcx> {
|
|||
|
||||
fn point_at_returns_when_relevant(
|
||||
&self,
|
||||
err: &mut Diagnostic,
|
||||
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
);
|
||||
|
||||
|
@ -1686,7 +1686,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
|
||||
fn point_at_returns_when_relevant(
|
||||
&self,
|
||||
err: &mut Diagnostic,
|
||||
err: &mut DiagnosticBuilder<'tcx, ErrorGuaranteed>,
|
||||
obligation: &PredicateObligation<'tcx>,
|
||||
) {
|
||||
match obligation.cause.code().peel_derives() {
|
||||
|
@ -1708,7 +1708,15 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
for expr in &visitor.returns {
|
||||
if let Some(returned_ty) = typeck_results.node_type_opt(expr.hir_id) {
|
||||
let ty = self.resolve_vars_if_possible(returned_ty);
|
||||
err.span_label(expr.span, &format!("this returned value is of type `{}`", ty));
|
||||
if ty.references_error() {
|
||||
// don't print out the [type error] here
|
||||
err.delay_as_bug();
|
||||
} else {
|
||||
err.span_label(
|
||||
expr.span,
|
||||
&format!("this returned value is of type `{}`", ty),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue