Move some common code into check_struct_path
This commit is contained in:
parent
2859f8bf39
commit
390b639e59
|
@ -495,9 +495,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
expected: Ty<'tcx>)
|
expected: Ty<'tcx>)
|
||||||
{
|
{
|
||||||
// Resolve the path and check the definition for errors.
|
// Resolve the path and check the definition for errors.
|
||||||
let def = self.finish_resolving_struct_path(path, pat.id, pat.span);
|
let (variant, pat_ty) = if let Some(variant_ty) = self.check_struct_path(path, pat.id,
|
||||||
let variant = if let Some(variant) = self.check_struct_path(def, path, pat.span) {
|
pat.span) {
|
||||||
variant
|
variant_ty
|
||||||
} else {
|
} else {
|
||||||
self.write_error(pat.id);
|
self.write_error(pat.id);
|
||||||
for field in fields {
|
for field in fields {
|
||||||
|
@ -507,7 +507,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Type check the path.
|
// 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);
|
self.demand_eqtype(pat.span, expected, pat_ty);
|
||||||
|
|
||||||
// Type check subpatterns.
|
// Type check subpatterns.
|
||||||
|
|
|
@ -3122,10 +3122,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_struct_path(&self,
|
pub fn check_struct_path(&self,
|
||||||
def: Def,
|
|
||||||
path: &hir::Path,
|
path: &hir::Path,
|
||||||
|
node_id: ast::NodeId,
|
||||||
span: Span)
|
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 {
|
let variant = match def {
|
||||||
Def::Err => {
|
Def::Err => {
|
||||||
self.set_tainted_by_errors();
|
self.set_tainted_by_errors();
|
||||||
|
@ -3151,7 +3152,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
pprust::path_to_string(path));
|
pprust::path_to_string(path));
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
variant
|
|
||||||
|
let ty = self.instantiate_type_path(def.def_id(), path, node_id);
|
||||||
|
Some((variant.unwrap(), ty))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_expr_struct(&self,
|
fn check_expr_struct(&self,
|
||||||
|
@ -3161,16 +3164,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
|
||||||
base_expr: &'gcx Option<P<hir::Expr>>)
|
base_expr: &'gcx Option<P<hir::Expr>>)
|
||||||
{
|
{
|
||||||
// Find the relevant variant
|
// Find the relevant variant
|
||||||
let def = self.finish_resolving_struct_path(path, expr.id, expr.span);
|
let (variant, expr_ty) = if let Some(variant_ty) = self.check_struct_path(path, expr.id,
|
||||||
let variant = if let Some(variant) = self.check_struct_path(def, path, expr.span) {
|
expr.span) {
|
||||||
variant
|
variant_ty
|
||||||
} else {
|
} else {
|
||||||
self.check_struct_fields_on_error(expr.id, fields, base_expr);
|
self.check_struct_fields_on_error(expr.id, fields, base_expr);
|
||||||
return;
|
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,
|
self.check_expr_struct_fields(expr_ty, path.span, variant, fields,
|
||||||
base_expr.is_none());
|
base_expr.is_none());
|
||||||
if let &Some(ref base_expr) = base_expr {
|
if let &Some(ref base_expr) = base_expr {
|
||||||
|
|
Loading…
Reference in New Issue