Skip to content

Commit 3295afa

Browse files
committed
save-analysis: fix ICE on partially resolved path
Occurs when we produce save-analysis before type checking is complete (due to errors).
1 parent 4bc9290 commit 3295afa

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/librustc/hir/def.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,15 @@ impl PathResolution {
8585

8686
/// Get the definition, if fully resolved, otherwise panic.
8787
pub fn full_def(&self) -> Def {
88-
if self.depth != 0 {
89-
bug!("path not fully resolved: {:?}", self);
88+
self.maybe_full_def().unwrap_or_else(|| bug!("path not fully resolved: {:?}", self))
89+
}
90+
91+
pub fn maybe_full_def(&self) -> Option<Def> {
92+
if self.depth == 0 {
93+
Some(self.base_def)
94+
} else {
95+
None
9096
}
91-
self.base_def
9297
}
9398

9499
pub fn kind_name(&self) -> &'static str {

src/librustc_save_analysis/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> {
497497
}
498498

499499
pub fn get_path_data(&self, id: NodeId, path: &ast::Path) -> Option<Data> {
500-
let def = self.tcx.expect_def(id);
500+
let def = option_try!(self.tcx.expect_resolution(id).maybe_full_def());
501501
let sub_span = self.span_utils.span_for_last_ident(path.span);
502502
filter!(self.span_utils, sub_span, path.span, None);
503503
match def {

0 commit comments

Comments
 (0)