Skip to content

Commit 7182683

Browse files
committed
Rebasing and bug fixing
1 parent 92d6676 commit 7182683

File tree

2 files changed

+45
-39
lines changed

2 files changed

+45
-39
lines changed

src/librustc_trans/save/dump_csv.rs

+31-29
Original file line numberDiff line numberDiff line change
@@ -873,30 +873,31 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
873873

874874
self.write_sub_paths_truncated(path, false);
875875

876-
let struct_lit_data = self.save_ctxt.get_expr_data(ex);
877-
down_cast_data!(struct_lit_data, TypeRefData, self, ex.span);
878-
self.fmt.ref_str(recorder::TypeRef,
879-
ex.span,
880-
Some(struct_lit_data.span),
881-
struct_lit_data.ref_id,
882-
struct_lit_data.scope);
883-
let struct_def = struct_lit_data.ref_id;
884-
885-
for field in fields {
886-
if generated_code(field.ident.span) {
887-
continue;
888-
}
876+
if let Some(struct_lit_data) = self.save_ctxt.get_expr_data(ex) {
877+
down_cast_data!(struct_lit_data, TypeRefData, self, ex.span);
878+
self.fmt.ref_str(recorder::TypeRef,
879+
ex.span,
880+
Some(struct_lit_data.span),
881+
struct_lit_data.ref_id,
882+
struct_lit_data.scope);
883+
let struct_def = struct_lit_data.ref_id;
884+
885+
for field in fields {
886+
if generated_code(field.ident.span) {
887+
continue;
888+
}
889889

890-
let field_data = self.save_ctxt.get_field_ref_data(field,
891-
struct_def,
892-
self.cur_scope);
893-
self.fmt.ref_str(recorder::VarRef,
894-
field.ident.span,
895-
Some(field_data.span),
896-
field_data.ref_id,
897-
field_data.scope);
890+
let field_data = self.save_ctxt.get_field_ref_data(field,
891+
struct_def,
892+
self.cur_scope);
893+
self.fmt.ref_str(recorder::VarRef,
894+
field.ident.span,
895+
Some(field_data.span),
896+
field_data.ref_id,
897+
field_data.scope);
898898

899-
self.visit_expr(&field.expr)
899+
self.visit_expr(&field.expr)
900+
}
900901
}
901902

902903
visit::walk_expr_opt(self, base)
@@ -1256,13 +1257,14 @@ impl<'l, 'tcx, 'v> Visitor<'v> for DumpCsvVisitor<'l, 'tcx> {
12561257

12571258
self.visit_expr(&sub_ex);
12581259

1259-
let field_data = self.save_ctxt.get_expr_data(ex);
1260-
down_cast_data!(field_data, VariableRefData, self, ex.span);
1261-
self.fmt.ref_str(recorder::VarRef,
1262-
ex.span,
1263-
Some(field_data.span),
1264-
field_data.ref_id,
1265-
field_data.scope);
1260+
if let Some(field_data) = self.save_ctxt.get_expr_data(ex) {
1261+
down_cast_data!(field_data, VariableRefData, self, ex.span);
1262+
self.fmt.ref_str(recorder::VarRef,
1263+
ex.span,
1264+
Some(field_data.span),
1265+
field_data.ref_id,
1266+
field_data.scope);
1267+
}
12661268
},
12671269
ast::ExprTupField(ref sub_ex, idx) => {
12681270
if generated_code(sub_ex.span) {

src/librustc_trans/save/mod.rs

+14-10
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
329329
})
330330
}
331331

332-
pub fn get_expr_data(&self, expr: &ast::Expr) -> Data {
332+
pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
333333
match expr.node {
334334
ast::ExprField(ref sub_ex, ident) => {
335335
let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, &sub_ex).sty;
@@ -339,12 +339,12 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
339339
for f in &fields {
340340
if f.name == ident.node.name {
341341
let sub_span = self.span_utils.span_for_last_ident(expr.span);
342-
return Data::VariableRefData(VariableRefData {
342+
return Some(Data::VariableRefData(VariableRefData {
343343
name: get_ident(ident.node).to_string(),
344344
span: sub_span.unwrap(),
345345
scope: self.analysis.ty_cx.map.get_parent(expr.id),
346346
ref_id: f.id,
347-
});
347+
}));
348348
}
349349
}
350350

@@ -353,24 +353,28 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
353353
&get_ident(ident.node),
354354
ty))
355355
}
356-
_ => self.sess.span_bug(expr.span,
357-
&format!("Expected struct type, found {:?}", ty)),
356+
_ => {
357+
debug!("Expected struct type, found {:?}", ty);
358+
None
359+
}
358360
}
359361
}
360362
ast::ExprStruct(ref path, _, _) => {
361363
let ty = &ty::expr_ty_adjusted(&self.analysis.ty_cx, expr).sty;
362364
match *ty {
363-
ty::ty_struct(def_id, _) => {
365+
ty::TyStruct(def_id, _) => {
364366
let sub_span = self.span_utils.span_for_last_ident(path.span);
365-
Data::TypeRefData(TypeRefData {
367+
Some(Data::TypeRefData(TypeRefData {
366368
span: sub_span.unwrap(),
367369
scope: self.analysis.ty_cx.map.get_parent(expr.id),
368370
ref_id: def_id,
369-
})
371+
}))
370372
}
371373
_ => {
372-
self.sess.span_bug(expr.span,
373-
&format!("expected ty_struct, found {:?}", ty));
374+
// FIXME ty could legitimately be a TyEnum, but then we will fail
375+
// later if we try to look up the fields.
376+
debug!("expected TyStruct, found {:?}", ty);
377+
None
374378
}
375379
}
376380
}

0 commit comments

Comments
 (0)