Skip to content

Commit 390b639

Browse files
committed
Move some common code into check_struct_path
1 parent 2859f8b commit 390b639

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

src/librustc_typeck/check/_match.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
495495
expected: Ty<'tcx>)
496496
{
497497
// Resolve the path and check the definition for errors.
498-
let def = self.finish_resolving_struct_path(path, pat.id, pat.span);
499-
let variant = if let Some(variant) = self.check_struct_path(def, path, pat.span) {
500-
variant
498+
let (variant, pat_ty) = if let Some(variant_ty) = self.check_struct_path(path, pat.id,
499+
pat.span) {
500+
variant_ty
501501
} else {
502502
self.write_error(pat.id);
503503
for field in fields {
@@ -507,7 +507,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
507507
};
508508

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

513512
// Type check subpatterns.

src/librustc_typeck/check/mod.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -3122,10 +3122,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
31223122
}
31233123

31243124
pub fn check_struct_path(&self,
3125-
def: Def,
31263125
path: &hir::Path,
3126+
node_id: ast::NodeId,
31273127
span: Span)
3128-
-> Option<ty::VariantDef<'tcx>> {
3128+
-> Option<(ty::VariantDef<'tcx>, Ty<'tcx>)> {
3129+
let def = self.finish_resolving_struct_path(path, node_id, span);
31293130
let variant = match def {
31303131
Def::Err => {
31313132
self.set_tainted_by_errors();
@@ -3151,7 +3152,9 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
31513152
pprust::path_to_string(path));
31523153
return None;
31533154
}
3154-
variant
3155+
3156+
let ty = self.instantiate_type_path(def.def_id(), path, node_id);
3157+
Some((variant.unwrap(), ty))
31553158
}
31563159

31573160
fn check_expr_struct(&self,
@@ -3161,16 +3164,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
31613164
base_expr: &'gcx Option<P<hir::Expr>>)
31623165
{
31633166
// Find the relevant variant
3164-
let def = self.finish_resolving_struct_path(path, expr.id, expr.span);
3165-
let variant = if let Some(variant) = self.check_struct_path(def, path, expr.span) {
3166-
variant
3167+
let (variant, expr_ty) = if let Some(variant_ty) = self.check_struct_path(path, expr.id,
3168+
expr.span) {
3169+
variant_ty
31673170
} else {
31683171
self.check_struct_fields_on_error(expr.id, fields, base_expr);
31693172
return;
31703173
};
31713174

3172-
let expr_ty = self.instantiate_type_path(def.def_id(), path, expr.id);
3173-
31743175
self.check_expr_struct_fields(expr_ty, path.span, variant, fields,
31753176
base_expr.is_none());
31763177
if let &Some(ref base_expr) = base_expr {

0 commit comments

Comments
 (0)