Skip to content

Commit

Permalink
Move some common code into check_struct_path
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Jul 8, 2016
1 parent 2859f8b commit 390b639
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
7 changes: 3 additions & 4 deletions src/librustc_typeck/check/_match.rs
Expand Up @@ -495,9 +495,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
expected: Ty<'tcx>)
{
// Resolve the path and check the definition for errors.
let def = self.finish_resolving_struct_path(path, pat.id, pat.span);
let variant = if let Some(variant) = self.check_struct_path(def, path, pat.span) {
variant
let (variant, pat_ty) = if let Some(variant_ty) = self.check_struct_path(path, pat.id,
pat.span) {
variant_ty
} else {
self.write_error(pat.id);
for field in fields {
Expand All @@ -507,7 +507,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
};

// Type check the path.
let pat_ty = self.instantiate_type_path(def.def_id(), path, pat.id);
self.demand_eqtype(pat.span, expected, pat_ty);

// Type check subpatterns.
Expand Down
17 changes: 9 additions & 8 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -3122,10 +3122,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
}

pub fn check_struct_path(&self,
def: Def,
path: &hir::Path,
node_id: ast::NodeId,
span: Span)
-> Option<ty::VariantDef<'tcx>> {
-> Option<(ty::VariantDef<'tcx>, Ty<'tcx>)> {
let def = self.finish_resolving_struct_path(path, node_id, span);
let variant = match def {
Def::Err => {
self.set_tainted_by_errors();
Expand All @@ -3151,7 +3152,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
pprust::path_to_string(path));
return None;
}
variant

let ty = self.instantiate_type_path(def.def_id(), path, node_id);
Some((variant.unwrap(), ty))
}

fn check_expr_struct(&self,
Expand All @@ -3161,16 +3164,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
base_expr: &'gcx Option<P<hir::Expr>>)
{
// Find the relevant variant
let def = self.finish_resolving_struct_path(path, expr.id, expr.span);
let variant = if let Some(variant) = self.check_struct_path(def, path, expr.span) {
variant
let (variant, expr_ty) = if let Some(variant_ty) = self.check_struct_path(path, expr.id,
expr.span) {
variant_ty
} else {
self.check_struct_fields_on_error(expr.id, fields, base_expr);
return;
};

let expr_ty = self.instantiate_type_path(def.def_id(), path, expr.id);

self.check_expr_struct_fields(expr_ty, path.span, variant, fields,
base_expr.is_none());
if let &Some(ref base_expr) = base_expr {
Expand Down

0 comments on commit 390b639

Please sign in to comment.