Skip to content

Commit

Permalink
fix RUST_LOG ICE caused by printing a default impl's DefId
Browse files Browse the repository at this point in the history
  • Loading branch information
arielb1 committed May 28, 2017
1 parent 7b295ee commit 5576770
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 15 deletions.
2 changes: 0 additions & 2 deletions src/librustc/middle/cstore.rs
Expand Up @@ -245,7 +245,6 @@ pub trait CrateStore {

// flags
fn is_const_fn(&self, did: DefId) -> bool;
fn is_default_impl(&self, impl_did: DefId) -> bool;
fn is_dllimport_foreign_item(&self, def: DefId) -> bool;
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool;

Expand Down Expand Up @@ -364,7 +363,6 @@ impl CrateStore for DummyCrateStore {

// flags
fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false }
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false }

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/ty/item_path.rs
Expand Up @@ -218,15 +218,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {

// Always use types for non-local impls, where types are always
// available, and filename/line-number is mostly uninteresting.
let use_types = !impl_def_id.is_local() || {
let use_types = !self.is_default_impl(impl_def_id) && (!impl_def_id.is_local() || {
// Otherwise, use filename/line-number if forced.
let force_no_types = FORCE_IMPL_FILENAME_LINE.with(|f| f.get());
!force_no_types && {
// Otherwise, use types if we can query them without inducing a cycle.
ty::queries::impl_trait_ref::try_get(self, DUMMY_SP, impl_def_id).is_ok() &&
ty::queries::type_of::try_get(self, DUMMY_SP, impl_def_id).is_ok()
}
};
});

if !use_types {
return self.push_impl_path_fallback(buffer, impl_def_id);
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/ty/maps.rs
Expand Up @@ -774,6 +774,9 @@ define_maps! { <'tcx>
/// True if this is a foreign item (i.e., linked via `extern { ... }`).
[] is_foreign_item: IsForeignItem(DefId) -> bool,

/// True if this is a default impl (aka impl Foo for ..)
[] is_default_impl: ItemSignature(DefId) -> bool,

/// Get a map with the variance of every item; use `item_variance`
/// instead.
[] crate_variances: crate_variances(CrateNum) -> Rc<ty::CrateVariancesMap>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_borrowck/borrowck/mir/mod.rs
Expand Up @@ -59,7 +59,7 @@ pub fn borrowck_mir(bcx: &mut BorrowckCtxt,
attributes: &[ast::Attribute]) {
let tcx = bcx.tcx;
let def_id = tcx.hir.local_def_id(id);
debug!("borrowck_mir({}) UNIMPLEMENTED", tcx.item_path_str(def_id));
debug!("borrowck_mir({:?}) UNIMPLEMENTED", def_id);

// It is safe for us to borrow `mir_validated()`: `optimized_mir`
// steals it, but it forces the `borrowck` query.
Expand Down
10 changes: 3 additions & 7 deletions src/librustc_metadata/cstore_impl.rs
Expand Up @@ -106,6 +106,7 @@ provide! { <'tcx> tcx, def_id, cdata
closure_type => { cdata.closure_ty(def_id.index, tcx) }
inherent_impls => { Rc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
is_default_impl => { cdata.is_default_impl(def_id.index) }
describe_def => { cdata.get_def(def_id.index) }
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
stability => { cdata.get_stability(def_id.index) }
Expand Down Expand Up @@ -176,11 +177,6 @@ impl CrateStore for cstore::CStore {
self.get_crate_data(did.krate).is_const_fn(did.index)
}

fn is_default_impl(&self, impl_did: DefId) -> bool {
self.dep_graph.read(DepNode::MetaData(impl_did));
self.get_crate_data(impl_did.krate).is_default_impl(impl_did.index)
}

fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool
{
self.do_is_statically_included_foreign_item(def_id)
Expand Down Expand Up @@ -403,7 +399,7 @@ impl CrateStore for cstore::CStore {
}

self.dep_graph.read(DepNode::MetaData(def_id));
debug!("item_body({}): inlining item", tcx.item_path_str(def_id));
debug!("item_body({:?}): inlining item", def_id);

self.get_crate_data(def_id.krate).item_body(tcx, def_id.index)
}
Expand Down Expand Up @@ -515,4 +511,4 @@ impl CrateStore for cstore::CStore {
drop(visible_parent_map);
self.visible_parent_map.borrow()
}
}
}
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/qualify_consts.rs
Expand Up @@ -361,7 +361,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {

/// Qualify a whole const, static initializer or const fn.
fn qualify_const(&mut self) -> Qualif {
debug!("qualifying {} {}", self.mode, self.tcx.item_path_str(self.def_id));
debug!("qualifying {} {:?}", self.mode, self.def_id);

let mir = self.mir;

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/type_check.rs
Expand Up @@ -744,7 +744,7 @@ impl MirPass for TypeckMir {
mir: &mut Mir<'tcx>) {
let item_id = src.item_id();
let def_id = tcx.hir.local_def_id(item_id);
debug!("run_pass: {}", tcx.item_path_str(def_id));
debug!("run_pass: {:?}", def_id);

if tcx.sess.err_count() > 0 {
// compiling a broken program can obviously result in a
Expand Down
12 changes: 12 additions & 0 deletions src/librustc_typeck/collect.rs
Expand Up @@ -100,6 +100,7 @@ pub fn provide(providers: &mut Providers) {
impl_trait_ref,
impl_polarity,
is_foreign_item,
is_default_impl,
..*providers
};
}
Expand Down Expand Up @@ -1545,3 +1546,14 @@ fn is_foreign_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
_ => bug!("is_foreign_item applied to non-local def-id {:?}", def_id)
}
}

fn is_default_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId)
-> bool {
match tcx.hir.get_if_local(def_id) {
Some(hir_map::NodeItem(&hir::Item { node: hir::ItemDefaultImpl(..), .. }))
=> true,
Some(_) => false,
_ => bug!("is_default_impl applied to non-local def-id {:?}", def_id)
}
}
2 changes: 1 addition & 1 deletion src/librustdoc/clean/inline.rs
Expand Up @@ -290,7 +290,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
}

// If this is a defaulted impl, then bail out early here
if tcx.sess.cstore.is_default_impl(did) {
if tcx.is_default_impl(did) {
return ret.push(clean::Item {
inner: clean::DefaultImplItem(clean::DefaultImpl {
// FIXME: this should be decoded
Expand Down

0 comments on commit 5576770

Please sign in to comment.