Skip to content

Commit 68312e3

Browse files
committed
Fix a bunch of bugs shown by the test
1 parent 9ea1544 commit 68312e3

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

src/librustc_save_analysis/dump_visitor.rs

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
275275
fn lookup_def_id(&self, ref_id: NodeId) -> Option<DefId> {
276276
self.tcx.expect_def_or_none(ref_id).and_then(|def| {
277277
match def {
278-
Def::PrimTy(..) | Def::SelfTy(..) => None,
278+
Def::Label(..) | Def::PrimTy(..) | Def::SelfTy(..) | Def::Err => None,
279279
def => Some(def.def_id()),
280280
}
281281
})
@@ -357,7 +357,10 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
357357
collector.visit_pat(&arg.pat);
358358
let span_utils = self.span.clone();
359359
for &(id, ref p, ..) in &collector.collected_paths {
360-
let typ = self.tcx.tables().node_types.get(&id).unwrap().to_string();
360+
let typ = match self.tcx.tables().node_types.get(&id) {
361+
Some(s) => s.to_string(),
362+
None => continue,
363+
};
361364
// get the span only for the name of the variable (I hope the path is only ever a
362365
// variable name, but who knows?)
363366
let sub_span = span_utils.span_for_last_ident(p.span);
@@ -987,7 +990,13 @@ impl<'l, 'tcx: 'l, 'll, D: Dump + 'll> DumpVisitor<'l, 'tcx, 'll, D> {
987990
match p.node {
988991
PatKind::Struct(ref path, ref fields, _) => {
989992
visit::walk_path(self, path);
990-
let adt = self.tcx.tables().node_id_to_type(p.id).ty_adt_def().unwrap();
993+
let adt = match self.tcx.tables().node_id_to_type_opt(p.id) {
994+
Some(ty) => ty.ty_adt_def().unwrap(),
995+
None => {
996+
visit::walk_pat(self, p);
997+
return;
998+
}
999+
};
9911000
let variant = adt.variant_of_def(self.tcx.expect_def(p.id));
9921001

9931002
for &Spanned { node: ref field, span } in fields {
@@ -1353,7 +1362,13 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
13531362
}
13541363
ast::ExprKind::Struct(ref path, ref fields, ref base) => {
13551364
let hir_expr = self.save_ctxt.tcx.map.expect_expr(ex.id);
1356-
let adt = self.tcx.tables().expr_ty(&hir_expr).ty_adt_def().unwrap();
1365+
let adt = match self.tcx.tables().expr_ty_opt(&hir_expr) {
1366+
Some(ty) => ty.ty_adt_def().unwrap(),
1367+
None => {
1368+
visit::walk_expr(self, ex);
1369+
return;
1370+
}
1371+
};
13571372
let def = self.tcx.expect_def(hir_expr.id);
13581373
self.process_struct_lit(ex, path, fields, adt.variant_of_def(def), base)
13591374
}
@@ -1379,7 +1394,13 @@ impl<'l, 'tcx: 'l, 'll, D: Dump +'ll> Visitor for DumpVisitor<'l, 'tcx, 'll, D>
13791394
return;
13801395
}
13811396
};
1382-
let ty = &self.tcx.tables().expr_ty_adjusted(&hir_node).sty;
1397+
let ty = match self.tcx.tables().expr_ty_adjusted_opt(&hir_node) {
1398+
Some(ty) => &ty.sty,
1399+
None => {
1400+
visit::walk_expr(self, ex);
1401+
return;
1402+
}
1403+
};
13831404
match *ty {
13841405
ty::TyAdt(def, _) => {
13851406
let sub_span = self.span.sub_span_after_token(ex.span, token::Dot);

src/test/run-make/save-analysis-fail/Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,4 @@ all: code
33
krate2: krate2.rs
44
$(RUSTC) $<
55
code: foo.rs krate2
6-
$(RUSTC) foo.rs -Zsave-analysis-csv
7-
$(RUSTC) foo.rs -Zsave-analysis
8-
$(RUSTC) foo.rs -Zsave-analysis-api
6+
$(RUSTC) foo.rs -Zsave-analysis || exit 0

0 commit comments

Comments
 (0)