Skip to content

Commit 186640a

Browse files
authored
Rollup merge of #73248 - marmeladema:save-analysis-various-fixes, r=Xanewok
save_analysis: improve handling of enum struct variant Fixes #61385
2 parents bc773fe + 0e31380 commit 186640a

File tree

1 file changed

+6
-19
lines changed
  • src/librustc_save_analysis

1 file changed

+6
-19
lines changed

src/librustc_save_analysis/lib.rs

+6-19
Original file line numberDiff line numberDiff line change
@@ -518,24 +518,13 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
518518
}
519519

520520
pub fn get_expr_data(&self, expr: &hir::Expr<'_>) -> Option<Data> {
521-
let hir_node = self.tcx.hir().expect_expr(expr.hir_id);
522-
let ty = self.tables.expr_ty_adjusted_opt(&hir_node);
523-
if ty.is_none() || matches!(ty.unwrap().kind, ty::Error(_)) {
521+
let ty = self.tables.expr_ty_adjusted_opt(expr)?;
522+
if matches!(ty.kind, ty::Error(_)) {
524523
return None;
525524
}
526525
match expr.kind {
527526
hir::ExprKind::Field(ref sub_ex, ident) => {
528-
let hir_node = match self.tcx.hir().find(sub_ex.hir_id) {
529-
Some(Node::Expr(expr)) => expr,
530-
_ => {
531-
debug!(
532-
"Missing or weird node for sub-expression {} in {:?}",
533-
sub_ex.hir_id, expr
534-
);
535-
return None;
536-
}
537-
};
538-
match self.tables.expr_ty_adjusted(&hir_node).kind {
527+
match self.tables.expr_ty_adjusted(&sub_ex).kind {
539528
ty::Adt(def, _) if !def.is_enum() => {
540529
let variant = &def.non_enum_variant();
541530
filter!(self.span_utils, ident.span);
@@ -562,8 +551,8 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
562551
hir::QPath::Resolved(_, path) => path.segments.last().unwrap(),
563552
hir::QPath::TypeRelative(_, segment) => segment,
564553
};
565-
match self.tables.expr_ty_adjusted(&hir_node).kind {
566-
ty::Adt(def, _) if !def.is_enum() => {
554+
match ty.kind {
555+
ty::Adt(def, _) => {
567556
let sub_span = segment.ident.span;
568557
filter!(self.span_utils, sub_span);
569558
let span = self.span_from_span(sub_span);
@@ -574,9 +563,7 @@ impl<'l, 'tcx> SaveContext<'l, 'tcx> {
574563
}))
575564
}
576565
_ => {
577-
// FIXME ty could legitimately be an enum, but then we will fail
578-
// later if we try to look up the fields.
579-
debug!("expected struct or union, found {:?}", ty);
566+
debug!("expected adt, found {:?}", ty);
580567
None
581568
}
582569
}

0 commit comments

Comments
 (0)