Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

save_analysis: improve handling of enum struct variant #73248

Merged
merged 1 commit into from
Jun 20, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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