Skip to content

Commit 3bc77fb

Browse files
committed
XXX: avoid transmute for Span
XXX: It's causing problems on aarch64-gnu-llvm-21-1 on CI.
1 parent ef444d3 commit 3bc77fb

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

compiler/rustc_data_structures/src/stable_hasher.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ pub trait HashStableContext {
3434
fn assert_default_hashing_controls(&self, msg: &str);
3535
}
3636

37-
// A type used to work around `Span` not being visible in this crate. It is the same size as
37+
// A type used to work around `Span` not being visible in this crate. It is the same layout as
3838
// `Span`.
39-
pub struct RawSpan {
40-
_data: u64,
41-
}
39+
pub struct RawSpan(pub u32, pub u16, pub u16);
4240

4341
// A type used to work around `DefId` not being visible in this crate. It is the same size as
4442
// `DefId`.

compiler/rustc_span/src/span_encoding.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,15 +445,12 @@ impl Span {
445445

446446
#[inline]
447447
pub(crate) fn to_raw_span(self) -> RawSpan {
448-
// SAFETY: we call `to_raw_span` and then `from_raw_span` immediately after, only when
449-
// calling `HashStableContext::span_hash_stable`.
450-
unsafe { std::mem::transmute::<Span, RawSpan>(self) }
448+
RawSpan(self.lo_or_index, self.len_with_tag_or_marker, self.ctxt_or_parent_or_marker)
451449
}
452450

453451
#[inline]
454-
pub fn from_raw_span(raw_span: RawSpan) -> Span {
455-
// SAFETY: see the comment in `to_raw_span`.
456-
unsafe { std::mem::transmute::<RawSpan, Span>(raw_span) }
452+
pub fn from_raw_span(RawSpan(x, y, z): RawSpan) -> Span {
453+
Span { lo_or_index: x, len_with_tag_or_marker: y, ctxt_or_parent_or_marker: z }
457454
}
458455
}
459456

0 commit comments

Comments
 (0)