Skip to content

Resolve issue #22187 (ICE compiling libcore with RUST_LOG=debug). #22376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 35 additions & 10 deletions src/librustc/util/ppaux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -674,12 +674,16 @@ impl<'tcx> UserString<'tcx> for TraitAndProjections<'tcx> {
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
let &(ref trait_ref, ref projection_bounds) = self;
let base = ty::item_path_str(tcx, trait_ref.def_id);
parameterized(tcx,
&base,
trait_ref.substs,
trait_ref.def_id,
&projection_bounds[..],
|| ty::lookup_trait_def(tcx, trait_ref.def_id).generics.clone())
if let Some(trait_def) = try_lookup_trait_def(tcx, trait_ref.def_id) {
parameterized(tcx,
&base,
trait_ref.substs,
trait_ref.def_id,
&projection_bounds[..],
|| trait_def.generics.clone())
} else {
format!("local_trait_not_ready({:?})", trait_ref.def_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The user_string trait is supposed to eschew printing compiler internal details (e.g. def id numbers)... I know this is an rare error conditon, so it might be acceptable here... but isn't the set of cases where this can arise limited to a small group (currently just Send)? I wonder if we can leverage that somehow ; in any case I would use "{}" so that other people do not accidentally put "{:?}" in other user_string impls

}
}
}

Expand Down Expand Up @@ -807,8 +811,12 @@ impl<'tcx> Repr<'tcx> for ty::TraitRef<'tcx> {
// to enumerate the `for<...>` etc because the debruijn index
// tells you everything you need to know.
let base = ty::item_path_str(tcx, self.def_id);
parameterized(tcx, &base, self.substs, self.def_id, &[],
|| ty::lookup_trait_def(tcx, self.def_id).generics.clone())
if let Some(trait_def) = try_lookup_trait_def(tcx, self.def_id) {
parameterized(tcx, &base, self.substs, self.def_id, &[],
|| trait_def.generics.clone())
} else {
format!("local_trait_not_ready({:?})", self.def_id)
}
}
}

Expand Down Expand Up @@ -1275,8 +1283,12 @@ impl<'tcx, T> UserString<'tcx> for ty::Binder<T>
impl<'tcx> UserString<'tcx> for ty::TraitRef<'tcx> {
fn user_string(&self, tcx: &ctxt<'tcx>) -> String {
let path_str = ty::item_path_str(tcx, self.def_id);
parameterized(tcx, &path_str, self.substs, self.def_id, &[],
|| ty::lookup_trait_def(tcx, self.def_id).generics.clone())
if let Some(trait_def) = try_lookup_trait_def(tcx, self.def_id) {
parameterized(tcx, &path_str, self.substs, self.def_id, &[],
|| trait_def.generics.clone())
} else {
format!("local_trait_not_ready({:?})", self.def_id)
}
}
}

Expand Down Expand Up @@ -1532,3 +1544,16 @@ impl<'tcx> Repr<'tcx> for ast::Unsafety {
format!("{:?}", *self)
}
}

// Wrapper around lookup_trait_def that can handle when the trait is
// defined in the local crate. Returns Option<_> because this function
// can be called while the trait_defs map is being built, so that
// looking up the trait_def in the local crate can sometimes fail.
fn try_lookup_trait_def<'tcx>(tcx: &ctxt<'tcx>, did: ast::DefId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh I totally overlooked the fact that you seem to have defined the same function twice here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, that was probably a rebase problem, i'll fix and update.

-> Option<Rc<ty::TraitDef<'tcx>>> {
if did.krate == ast::LOCAL_CRATE {
tcx.trait_defs.borrow().get(&did).map(|r| r.clone())
} else {
Some(ty::lookup_trait_def(tcx, did))
}
}