Skip to content

Commit f91a20b

Browse files
committed
save-analysis: return an Option from get_path_data
1 parent 52fd69c commit f91a20b

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

src/librustc_trans/save/dump_csv.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,15 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
671671
}
672672

673673
let path_data = self.save_ctxt.get_path_data(id, path);
674+
let path_data = match path_data {
675+
Some(pd) => pd,
676+
None => {
677+
self.tcx.sess.span_bug(path.span,
678+
&format!("Unexpected def kind while looking \
679+
up path in `{}`",
680+
self.span.snippet(path.span)))
681+
}
682+
};
674683
match path_data {
675684
Data::VariableRefData(ref vrd) => {
676685
self.fmt.ref_str(ref_kind.unwrap_or(recorder::VarRef),

src/librustc_trans/save/mod.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
508508
}))
509509
}
510510
ast::ExprPath(_, ref path) => {
511-
Some(self.get_path_data(expr.id, path))
511+
self.get_path_data(expr.id, path)
512512
}
513513
_ => {
514514
// FIXME
@@ -520,7 +520,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
520520
pub fn get_path_data(&self,
521521
id: NodeId,
522522
path: &ast::Path)
523-
-> Data {
523+
-> Option<Data> {
524524
let def_map = self.tcx.def_map.borrow();
525525
if !def_map.contains_key(&id) {
526526
self.tcx.sess.span_bug(path.span,
@@ -535,22 +535,22 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
535535
def::DefConst(..) |
536536
def::DefAssociatedConst(..) |
537537
def::DefVariant(..) => {
538-
Data::VariableRefData(VariableRefData {
538+
Some(Data::VariableRefData(VariableRefData {
539539
name: self.span_utils.snippet(sub_span.unwrap()),
540540
span: sub_span.unwrap(),
541541
scope: self.enclosing_scope(id),
542542
ref_id: def.def_id(),
543-
})
543+
}))
544544
}
545545
def::DefStruct(def_id) |
546546
def::DefTy(def_id, _) |
547547
def::DefTrait(def_id) |
548548
def::DefTyParam(_, _, def_id, _) => {
549-
Data::TypeRefData(TypeRefData {
549+
Some(Data::TypeRefData(TypeRefData {
550550
span: sub_span.unwrap(),
551551
ref_id: def_id,
552552
scope: self.enclosing_scope(id),
553-
})
553+
}))
554554
}
555555
def::DefMethod(decl_id, provenence) => {
556556
let sub_span = self.span_utils.sub_span_for_meth_name(path.span);
@@ -581,32 +581,28 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
581581
} else {
582582
None
583583
};
584-
Data::MethodCallData(MethodCallData {
584+
Some(Data::MethodCallData(MethodCallData {
585585
span: sub_span.unwrap(),
586586
scope: self.enclosing_scope(id),
587587
ref_id: def_id,
588588
decl_id: Some(decl_id),
589-
})
589+
}))
590590
},
591591
def::DefFn(def_id, _) => {
592-
Data::FunctionCallData(FunctionCallData {
592+
Some(Data::FunctionCallData(FunctionCallData {
593593
ref_id: def_id,
594594
span: sub_span.unwrap(),
595595
scope: self.enclosing_scope(id),
596-
})
596+
}))
597597
}
598598
def::DefMod(def_id) => {
599-
Data::ModRefData(ModRefData {
599+
Some(Data::ModRefData(ModRefData {
600600
ref_id: def_id,
601601
span: sub_span.unwrap(),
602602
scope: self.enclosing_scope(id),
603-
})
603+
}))
604604
}
605-
_ => self.tcx.sess.span_bug(path.span,
606-
&format!("Unexpected def kind while looking \
607-
up path in `{}`: `{:?}`",
608-
self.span_utils.snippet(path.span),
609-
def)),
605+
_ => None,
610606
}
611607
}
612608

0 commit comments

Comments
 (0)