Skip to content

Commit

Permalink
Improve the DefId: Debug impl when rustc is available
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadrieril committed Aug 13, 2024
1 parent effb76c commit 6ce4344
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion frontend/exporter/src/types/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub struct DisambiguatedDefPathItem {

/// Reflects [`rustc_hir::def_id::DefId`]
#[derive_group(Serializers)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord)]
#[cfg_attr(not(feature = "extract_names_mode"), derive(JsonSchema))]
pub struct DefId {
pub krate: String,
Expand All @@ -49,6 +49,24 @@ pub struct DefId {
pub is_local: bool,
}

#[cfg(not(feature = "rustc"))]
impl std::fmt::Debug for DefId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("DefId")
.field("krate", &self.krate)
.field("path", &self.path)
.finish()
}
}

#[cfg(feature = "rustc")]
impl std::fmt::Debug for DefId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Use the more legible rustc debug implementation.
write!(f, "{:?}", rustc_span::def_id::DefId::from(self))
}
}

/// Reflects [`rustc_hir::definitions::DefPathData`]
#[derive_group(Serializers)]
#[derive(Clone, Debug, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down

0 comments on commit 6ce4344

Please sign in to comment.