Skip to content

Commit 24d0a01

Browse files
committed
review comment
1 parent 21e7e3f commit 24d0a01

File tree

1 file changed

+27
-11
lines changed
  • src/librustc_typeck/check

1 file changed

+27
-11
lines changed

src/librustc_typeck/check/pat.rs

+27-11
Original file line numberDiff line numberDiff line change
@@ -675,23 +675,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
675675
self.tcx.check_stability(variant.fields[i].did, Some(pat.hir_id), subpat.span);
676676
}
677677
} else {
678-
let subpats_ending = if subpats.len() == 1 { "" } else { "s" };
679-
let fields_ending = if variant.fields.len() == 1 { "" } else { "s" };
680-
let span = tcx.def_span(res.def_id());
681-
struct_span_err!(tcx.sess, pat.span, E0023,
682-
"this pattern has {} field{}, but the corresponding {} has {} field{}",
683-
subpats.len(), subpats_ending, res.descr(),
684-
variant.fields.len(), fields_ending)
685-
.span_label(pat.span, format!("expected {} field{}, found {}",
686-
variant.fields.len(), fields_ending, subpats.len()))
687-
.span_label(span, format!("{} defined here", res.descr()))
688-
.emit();
678+
// Pattern has wrong number of fields.
679+
self.e0023(pat.span, res, &subpats, &variant.fields);
689680
on_error();
690681
return tcx.types.err;
691682
}
692683
pat_ty
693684
}
694685

686+
fn e0023(&self, pat_span: Span, res: Res, subpats: &'tcx [P<Pat>], fields: &[ty::FieldDef]) {
687+
let subpats_ending = if subpats.len() == 1 { "" } else { "s" };
688+
let fields_ending = if fields.len() == 1 { "" } else { "s" };
689+
let res_span = self.tcx.def_span(res.def_id());
690+
struct_span_err!(
691+
self.tcx.sess,
692+
pat_span,
693+
E0023,
694+
"this pattern has {} field{}, but the corresponding {} has {} field{}",
695+
subpats.len(),
696+
subpats_ending,
697+
res.descr(),
698+
fields.len(),
699+
fields_ending,
700+
)
701+
.span_label(pat_span, format!(
702+
"expected {} field{}, found {}",
703+
fields.len(),
704+
fields_ending,
705+
subpats.len(),
706+
))
707+
.span_label(res_span, format!("{} defined here", res.descr()))
708+
.emit();
709+
}
710+
695711
fn check_pat_tuple(
696712
&self,
697713
span: Span,

0 commit comments

Comments
 (0)