Skip to content

Commit

Permalink
Rollup merge of #73248 - marmeladema:save-analysis-various-fixes, r=X…
Browse files Browse the repository at this point in the history
…anewok

save_analysis: improve handling of enum struct variant

Fixes #61385
  • Loading branch information
Manishearth committed Jun 19, 2020
2 parents bc773fe + 0e31380 commit 186640a
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/librustc_save_analysis/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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
}
}
Expand Down

0 comments on commit 186640a

Please sign in to comment.