Move some common code into check_struct_path

This commit is contained in:
Vadim Petrochenkov 2016-06-11 18:47:47 +03:00
parent 2859f8bf39
commit 390b639e59
2 changed files with 12 additions and 12 deletions

View File

@ -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 {
@ -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.

View File

@ -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();
@ -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,
@ -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 {