Skip to content

Commit

Permalink
review comment
Browse files Browse the repository at this point in the history
  • Loading branch information
estebank committed Sep 5, 2019
1 parent 21e7e3f commit 24d0a01
Showing 1 changed file with 27 additions and 11 deletions.
38 changes: 27 additions & 11 deletions src/librustc_typeck/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -675,23 +675,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
self.tcx.check_stability(variant.fields[i].did, Some(pat.hir_id), subpat.span);
}
} else {
let subpats_ending = if subpats.len() == 1 { "" } else { "s" };
let fields_ending = if variant.fields.len() == 1 { "" } else { "s" };
let span = tcx.def_span(res.def_id());
struct_span_err!(tcx.sess, pat.span, E0023,
"this pattern has {} field{}, but the corresponding {} has {} field{}",
subpats.len(), subpats_ending, res.descr(),
variant.fields.len(), fields_ending)
.span_label(pat.span, format!("expected {} field{}, found {}",
variant.fields.len(), fields_ending, subpats.len()))
.span_label(span, format!("{} defined here", res.descr()))
.emit();
// Pattern has wrong number of fields.
self.e0023(pat.span, res, &subpats, &variant.fields);
on_error();
return tcx.types.err;
}
pat_ty
}

fn e0023(&self, pat_span: Span, res: Res, subpats: &'tcx [P<Pat>], fields: &[ty::FieldDef]) {
let subpats_ending = if subpats.len() == 1 { "" } else { "s" };
let fields_ending = if fields.len() == 1 { "" } else { "s" };
let res_span = self.tcx.def_span(res.def_id());
struct_span_err!(
self.tcx.sess,
pat_span,
E0023,
"this pattern has {} field{}, but the corresponding {} has {} field{}",
subpats.len(),
subpats_ending,
res.descr(),
fields.len(),
fields_ending,
)
.span_label(pat_span, format!(
"expected {} field{}, found {}",
fields.len(),
fields_ending,
subpats.len(),
))
.span_label(res_span, format!("{} defined here", res.descr()))
.emit();
}

fn check_pat_tuple(
&self,
span: Span,
Expand Down

0 comments on commit 24d0a01

Please sign in to comment.