1
Fork 0

On unsized locals with explicit types suggest &

Fix #72742.
This commit is contained in:
Esteban Küber 2022-12-28 09:26:30 -08:00
parent 92c1937a90
commit 083eb936ec
5 changed files with 96 additions and 0 deletions

View file

@ -2514,6 +2514,15 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
ObligationCauseCode::VariableType(hir_id) => {
let parent_node = self.tcx.hir().get_parent_node(hir_id);
match self.tcx.hir().find(parent_node) {
Some(Node::Local(hir::Local { ty: Some(ty), .. })) => {
err.span_suggestion_verbose(
ty.span.shrink_to_lo(),
"consider borrowing here",
"&",
Applicability::MachineApplicable,
);
err.note("all local variables must have a statically known size");
}
Some(Node::Local(hir::Local {
init: Some(hir::Expr { kind: hir::ExprKind::Index(_, _), span, .. }),
..