diff options
| author | marmeladema <xademax@gmail.com> | 2020-06-11 19:08:33 +0100 |
|---|---|---|
| committer | marmeladema <xademax@gmail.com> | 2020-06-19 10:35:44 +0100 |
| commit | 0e31380f42165f79c54261c5a94f4bc54831ee52 (patch) | |
| tree | 177fc62026f055597ecf640ec63ba5c90ed9fc9d | |
| parent | a39c7787ba246353178e099373b9240be0d9e603 (diff) | |
| download | rust-0e31380f42165f79c54261c5a94f4bc54831ee52.tar.gz rust-0e31380f42165f79c54261c5a94f4bc54831ee52.zip | |
save_analysis: improve handling of enum struct variant
Fixes #61385
| -rw-r--r-- | src/librustc_save_analysis/lib.rs | 25 |
1 files changed, 6 insertions, 19 deletions
diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index cae501e942b..f5c3e84c624 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -518,24 +518,13 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { } pub fn get_expr_data(&self, expr: &hir::Expr<'_>) -> Option<Data> { - let hir_node = self.tcx.hir().expect_expr(expr.hir_id); - let ty = self.tables.expr_ty_adjusted_opt(&hir_node); - if ty.is_none() || matches!(ty.unwrap().kind, ty::Error(_)) { + let ty = self.tables.expr_ty_adjusted_opt(expr)?; + if matches!(ty.kind, ty::Error(_)) { return None; } match expr.kind { hir::ExprKind::Field(ref sub_ex, ident) => { - let hir_node = match self.tcx.hir().find(sub_ex.hir_id) { - Some(Node::Expr(expr)) => expr, - _ => { - debug!( - "Missing or weird node for sub-expression {} in {:?}", - sub_ex.hir_id, expr - ); - return None; - } - }; - match self.tables.expr_ty_adjusted(&hir_node).kind { + match self.tables.expr_ty_adjusted(&sub_ex).kind { ty::Adt(def, _) if !def.is_enum() => { let variant = &def.non_enum_variant(); filter!(self.span_utils, ident.span); @@ -562,8 +551,8 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { hir::QPath::Resolved(_, path) => path.segments.last().unwrap(), hir::QPath::TypeRelative(_, segment) => segment, }; - match self.tables.expr_ty_adjusted(&hir_node).kind { - ty::Adt(def, _) if !def.is_enum() => { + match ty.kind { + ty::Adt(def, _) => { let sub_span = segment.ident.span; filter!(self.span_utils, sub_span); let span = self.span_from_span(sub_span); @@ -574,9 +563,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> { })) } _ => { - // FIXME ty could legitimately be an enum, but then we will fail - // later if we try to look up the fields. - debug!("expected struct or union, found {:?}", ty); + debug!("expected adt, found {:?}", ty); None } } |
