From: Nick Cameron Date: Mon, 21 Nov 2016 05:11:36 +0000 (+1300) Subject: save-analysis: fix ICE on partially resolved path X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=3295afa6e2dd9d3b50bce0342199a7d448d480aa;p=rust.git save-analysis: fix ICE on partially resolved path Occurs when we produce save-analysis before type checking is complete (due to errors). --- diff --git a/src/librustc/hir/def.rs b/src/librustc/hir/def.rs index feefc43f401..ce04a7c897a 100644 --- a/src/librustc/hir/def.rs +++ b/src/librustc/hir/def.rs @@ -85,10 +85,15 @@ pub fn new(def: Def) -> PathResolution { /// Get the definition, if fully resolved, otherwise panic. pub fn full_def(&self) -> Def { - if self.depth != 0 { - bug!("path not fully resolved: {:?}", self); + self.maybe_full_def().unwrap_or_else(|| bug!("path not fully resolved: {:?}", self)) + } + + pub fn maybe_full_def(&self) -> Option { + if self.depth == 0 { + Some(self.base_def) + } else { + None } - self.base_def } pub fn kind_name(&self) -> &'static str { diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 778f0184141..4c59f5e8a83 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -497,7 +497,7 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option { } pub fn get_path_data(&self, id: NodeId, path: &ast::Path) -> Option { - let def = self.tcx.expect_def(id); + let def = option_try!(self.tcx.expect_resolution(id).maybe_full_def()); let sub_span = self.span_utils.span_for_last_ident(path.span); filter!(self.span_utils, sub_span, path.span, None); match def {