|
1 | 1 | use crate::def_id::{DefId, DefIndex, LocalDefId, CRATE_DEF_ID};
|
2 | 2 | use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableOrd, ToStableHashKey};
|
3 | 3 | use rustc_span::{def_id::DefPathHash, HashStableContext};
|
4 |
| -use std::fmt; |
| 4 | +use std::fmt::{self, Debug}; |
5 | 5 |
|
6 |
| -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] |
| 6 | +#[derive(Copy, Clone, PartialEq, Eq, Hash)] |
7 | 7 | #[derive(Encodable, Decodable)]
|
8 | 8 | pub struct OwnerId {
|
9 | 9 | pub def_id: LocalDefId,
|
10 | 10 | }
|
11 | 11 |
|
| 12 | +impl Debug for OwnerId { |
| 13 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 14 | + // Example: DefId(0:1 ~ aa[7697]::{use#0}) |
| 15 | + Debug::fmt(&self.def_id, f) |
| 16 | + } |
| 17 | +} |
| 18 | + |
12 | 19 | impl From<OwnerId> for HirId {
|
13 | 20 | fn from(owner: OwnerId) -> HirId {
|
14 | 21 | HirId { owner, local_id: ItemLocalId::from_u32(0) }
|
@@ -60,14 +67,22 @@ impl<CTX: HashStableContext> ToStableHashKey<CTX> for OwnerId {
|
60 | 67 | /// the `local_id` part of the `HirId` changing, which is a very useful property in
|
61 | 68 | /// incremental compilation where we have to persist things through changes to
|
62 | 69 | /// the code base.
|
63 |
| -#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)] |
| 70 | +#[derive(Copy, Clone, PartialEq, Eq, Hash)] |
64 | 71 | #[derive(Encodable, Decodable, HashStable_Generic)]
|
65 | 72 | #[rustc_pass_by_value]
|
66 | 73 | pub struct HirId {
|
67 | 74 | pub owner: OwnerId,
|
68 | 75 | pub local_id: ItemLocalId,
|
69 | 76 | }
|
70 | 77 |
|
| 78 | +impl Debug for HirId { |
| 79 | + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 80 | + // Example: HirId(DefId(0:1 ~ aa[7697]::{use#0}).10) |
| 81 | + // Don't use debug_tuple to always keep this on one line. |
| 82 | + write!(f, "HirId({:?}.{:?})", self.owner, self.local_id) |
| 83 | + } |
| 84 | +} |
| 85 | + |
71 | 86 | impl HirId {
|
72 | 87 | /// Signal local id which should never be used.
|
73 | 88 | pub const INVALID: HirId =
|
|
0 commit comments