Skip to content

Commit 5576770

Browse files
committed
fix RUST_LOG ICE caused by printing a default impl's DefId
1 parent 7b295ee commit 5576770

File tree

9 files changed

+24
-15
lines changed

9 files changed

+24
-15
lines changed

src/librustc/middle/cstore.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,6 @@ pub trait CrateStore {
245245

246246
// flags
247247
fn is_const_fn(&self, did: DefId) -> bool;
248-
fn is_default_impl(&self, impl_did: DefId) -> bool;
249248
fn is_dllimport_foreign_item(&self, def: DefId) -> bool;
250249
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool;
251250

@@ -364,7 +363,6 @@ impl CrateStore for DummyCrateStore {
364363

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

src/librustc/ty/item_path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,15 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
218218

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

231231
if !use_types {
232232
return self.push_impl_path_fallback(buffer, impl_def_id);

src/librustc/ty/maps.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ define_maps! { <'tcx>
774774
/// True if this is a foreign item (i.e., linked via `extern { ... }`).
775775
[] is_foreign_item: IsForeignItem(DefId) -> bool,
776776

777+
/// True if this is a default impl (aka impl Foo for ..)
778+
[] is_default_impl: ItemSignature(DefId) -> bool,
779+
777780
/// Get a map with the variance of every item; use `item_variance`
778781
/// instead.
779782
[] crate_variances: crate_variances(CrateNum) -> Rc<ty::CrateVariancesMap>,

src/librustc_borrowck/borrowck/mir/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ pub fn borrowck_mir(bcx: &mut BorrowckCtxt,
5959
attributes: &[ast::Attribute]) {
6060
let tcx = bcx.tcx;
6161
let def_id = tcx.hir.local_def_id(id);
62-
debug!("borrowck_mir({}) UNIMPLEMENTED", tcx.item_path_str(def_id));
62+
debug!("borrowck_mir({:?}) UNIMPLEMENTED", def_id);
6363

6464
// It is safe for us to borrow `mir_validated()`: `optimized_mir`
6565
// steals it, but it forces the `borrowck` query.

src/librustc_metadata/cstore_impl.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ provide! { <'tcx> tcx, def_id, cdata
106106
closure_type => { cdata.closure_ty(def_id.index, tcx) }
107107
inherent_impls => { Rc::new(cdata.get_inherent_implementations_for_type(def_id.index)) }
108108
is_foreign_item => { cdata.is_foreign_item(def_id.index) }
109+
is_default_impl => { cdata.is_default_impl(def_id.index) }
109110
describe_def => { cdata.get_def(def_id.index) }
110111
def_span => { cdata.get_span(def_id.index, &tcx.sess) }
111112
stability => { cdata.get_stability(def_id.index) }
@@ -176,11 +177,6 @@ impl CrateStore for cstore::CStore {
176177
self.get_crate_data(did.krate).is_const_fn(did.index)
177178
}
178179

179-
fn is_default_impl(&self, impl_did: DefId) -> bool {
180-
self.dep_graph.read(DepNode::MetaData(impl_did));
181-
self.get_crate_data(impl_did.krate).is_default_impl(impl_did.index)
182-
}
183-
184180
fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool
185181
{
186182
self.do_is_statically_included_foreign_item(def_id)
@@ -403,7 +399,7 @@ impl CrateStore for cstore::CStore {
403399
}
404400

405401
self.dep_graph.read(DepNode::MetaData(def_id));
406-
debug!("item_body({}): inlining item", tcx.item_path_str(def_id));
402+
debug!("item_body({:?}): inlining item", def_id);
407403

408404
self.get_crate_data(def_id.krate).item_body(tcx, def_id.index)
409405
}
@@ -515,4 +511,4 @@ impl CrateStore for cstore::CStore {
515511
drop(visible_parent_map);
516512
self.visible_parent_map.borrow()
517513
}
518-
}
514+
}

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ impl<'a, 'tcx> Qualifier<'a, 'tcx, 'tcx> {
361361

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

366366
let mir = self.mir;
367367

src/librustc_mir/transform/type_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ impl MirPass for TypeckMir {
744744
mir: &mut Mir<'tcx>) {
745745
let item_id = src.item_id();
746746
let def_id = tcx.hir.local_def_id(item_id);
747-
debug!("run_pass: {}", tcx.item_path_str(def_id));
747+
debug!("run_pass: {:?}", def_id);
748748

749749
if tcx.sess.err_count() > 0 {
750750
// compiling a broken program can obviously result in a

src/librustc_typeck/collect.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ pub fn provide(providers: &mut Providers) {
100100
impl_trait_ref,
101101
impl_polarity,
102102
is_foreign_item,
103+
is_default_impl,
103104
..*providers
104105
};
105106
}
@@ -1545,3 +1546,14 @@ fn is_foreign_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
15451546
_ => bug!("is_foreign_item applied to non-local def-id {:?}", def_id)
15461547
}
15471548
}
1549+
1550+
fn is_default_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1551+
def_id: DefId)
1552+
-> bool {
1553+
match tcx.hir.get_if_local(def_id) {
1554+
Some(hir_map::NodeItem(&hir::Item { node: hir::ItemDefaultImpl(..), .. }))
1555+
=> true,
1556+
Some(_) => false,
1557+
_ => bug!("is_default_impl applied to non-local def-id {:?}", def_id)
1558+
}
1559+
}

src/librustdoc/clean/inline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
290290
}
291291

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

0 commit comments

Comments
 (0)