errors: only eagerly translate subdiagnostics
Subdiagnostics don't need to be lazily translated, they can always be eagerly translated. Eager translation is slightly more complex as we need to have a `DiagCtxt` available to perform the translation, which involves slightly more threading of that context. This slight increase in complexity should enable later simplifications - like passing `DiagCtxt` into `AddToDiagnostic` and moving Fluent messages into the diagnostic structs rather than having them in separate files (working on that was what led to this change). Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
parent
bb89df6903
commit
b80fc5d4e8
43 changed files with 532 additions and 388 deletions
|
@ -846,7 +846,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
arm_ty,
|
||||
arm_span,
|
||||
) {
|
||||
err.subdiagnostic(subdiag);
|
||||
err.subdiagnostic(self.dcx(), subdiag);
|
||||
}
|
||||
if let hir::Node::Expr(m) = self.tcx.parent_hir_node(scrut_hir_id)
|
||||
&& let hir::Node::Stmt(stmt) = self.tcx.parent_hir_node(m.hir_id)
|
||||
|
@ -892,7 +892,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
else_ty,
|
||||
else_span,
|
||||
) {
|
||||
err.subdiagnostic(subdiag);
|
||||
err.subdiagnostic(self.dcx(), subdiag);
|
||||
}
|
||||
// don't suggest wrapping either blocks in `if .. {} else {}`
|
||||
let is_empty_arm = |id| {
|
||||
|
|
|
@ -342,7 +342,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
trait_predicates: trait_predicates.join(", "),
|
||||
}
|
||||
};
|
||||
err.subdiagnostic(suggestion);
|
||||
err.subdiagnostic(self.dcx(), suggestion);
|
||||
}
|
||||
|
||||
pub(super) fn report_placeholder_failure(
|
||||
|
|
|
@ -84,7 +84,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
start_sp: return_sp.with_hi(return_sp.lo() + BytePos(4)),
|
||||
end_sp: return_sp.shrink_to_hi(),
|
||||
};
|
||||
err.subdiagnostic(sugg);
|
||||
err.subdiagnostic(self.dcx(), sugg);
|
||||
|
||||
let mut starts = Vec::new();
|
||||
let mut ends = Vec::new();
|
||||
|
@ -93,7 +93,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
ends.push(span.shrink_to_hi());
|
||||
}
|
||||
let sugg = SuggestBoxingForReturnImplTrait::BoxReturnExpr { starts, ends };
|
||||
err.subdiagnostic(sugg);
|
||||
err.subdiagnostic(self.dcx(), sugg);
|
||||
}
|
||||
|
||||
pub(super) fn suggest_tuple_pattern(
|
||||
|
@ -138,7 +138,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
span_low: cause.span.shrink_to_lo(),
|
||||
span_high: cause.span.shrink_to_hi(),
|
||||
};
|
||||
diag.subdiagnostic(sugg);
|
||||
diag.subdiagnostic(self.dcx(), sugg);
|
||||
}
|
||||
_ => {
|
||||
// More than one matching variant.
|
||||
|
@ -147,7 +147,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
cause_span: cause.span,
|
||||
compatible_variants,
|
||||
};
|
||||
diag.subdiagnostic(sugg);
|
||||
diag.subdiagnostic(self.dcx(), sugg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -219,9 +219,10 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
},
|
||||
(_, Some(ty)) if self.same_type_modulo_infer(exp_found.expected, ty) => {
|
||||
// FIXME: Seems like we can't have a suggestion and a note with different spans in a single subdiagnostic
|
||||
diag.subdiagnostic(ConsiderAddingAwait::FutureSugg {
|
||||
span: exp_span.shrink_to_hi(),
|
||||
});
|
||||
diag.subdiagnostic(
|
||||
self.dcx(),
|
||||
ConsiderAddingAwait::FutureSugg { span: exp_span.shrink_to_hi() },
|
||||
);
|
||||
Some(ConsiderAddingAwait::FutureSuggNote { span: exp_span })
|
||||
}
|
||||
(Some(ty), _) if self.same_type_modulo_infer(ty, exp_found.found) => match cause.code()
|
||||
|
@ -246,7 +247,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
_ => None,
|
||||
};
|
||||
if let Some(subdiag) = subdiag {
|
||||
diag.subdiagnostic(subdiag);
|
||||
diag.subdiagnostic(self.dcx(), subdiag);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -282,7 +283,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
} else {
|
||||
return;
|
||||
};
|
||||
diag.subdiagnostic(suggestion);
|
||||
diag.subdiagnostic(self.dcx(), suggestion);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -322,15 +323,15 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
(true, false) => FunctionPointerSuggestion::UseRef { span, fn_name },
|
||||
(false, true) => FunctionPointerSuggestion::RemoveRef { span, fn_name },
|
||||
(true, true) => {
|
||||
diag.subdiagnostic(FnItemsAreDistinct);
|
||||
diag.subdiagnostic(self.dcx(), FnItemsAreDistinct);
|
||||
FunctionPointerSuggestion::CastRef { span, fn_name, sig: *sig }
|
||||
}
|
||||
(false, false) => {
|
||||
diag.subdiagnostic(FnItemsAreDistinct);
|
||||
diag.subdiagnostic(self.dcx(), FnItemsAreDistinct);
|
||||
FunctionPointerSuggestion::Cast { span, fn_name, sig: *sig }
|
||||
}
|
||||
};
|
||||
diag.subdiagnostic(sugg);
|
||||
diag.subdiagnostic(self.dcx(), sugg);
|
||||
}
|
||||
(ty::FnDef(did1, args1), ty::FnDef(did2, args2)) => {
|
||||
let expected_sig =
|
||||
|
@ -339,7 +340,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
&(self.normalize_fn_sig)(self.tcx.fn_sig(*did2).instantiate(self.tcx, args2));
|
||||
|
||||
if self.same_type_modulo_infer(*expected_sig, *found_sig) {
|
||||
diag.subdiagnostic(FnUniqTypes);
|
||||
diag.subdiagnostic(self.dcx(), FnUniqTypes);
|
||||
}
|
||||
|
||||
if !self.same_type_modulo_infer(*found_sig, *expected_sig)
|
||||
|
@ -368,7 +369,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
}
|
||||
};
|
||||
|
||||
diag.subdiagnostic(sug);
|
||||
diag.subdiagnostic(self.dcx(), sug);
|
||||
}
|
||||
(ty::FnDef(did, args), ty::FnPtr(sig)) => {
|
||||
let expected_sig =
|
||||
|
@ -387,7 +388,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
format!("{fn_name} as {found_sig}")
|
||||
};
|
||||
|
||||
diag.subdiagnostic(FnConsiderCasting { casting });
|
||||
diag.subdiagnostic(self.dcx(), FnConsiderCasting { casting });
|
||||
}
|
||||
_ => {
|
||||
return;
|
||||
|
@ -819,7 +820,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
let diag = self.consider_returning_binding_diag(blk, expected_ty);
|
||||
match diag {
|
||||
Some(diag) => {
|
||||
err.subdiagnostic(diag);
|
||||
err.subdiagnostic(self.dcx(), diag);
|
||||
true
|
||||
}
|
||||
None => false,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue