Skip to content

Commit 0d60777

Browse files
committed
Some simplifications
1 parent ad5cbd7 commit 0d60777

File tree

5 files changed

+18
-32
lines changed

5 files changed

+18
-32
lines changed

library/core/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ optimize_for_size = []
2323
# Make `RefCell` store additional debugging information, which is printed out when
2424
# a borrow error occurs
2525
debug_refcell = []
26-
# Make `TypeId` store a reference to the name of the type, so that it can print that name.
27-
debug_typeid = []
2826

2927
[lints.rust.unexpected_cfgs]
3028
level = "warn"

library/core/src/any.rs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -711,14 +711,23 @@ pub struct TypeId {
711711
/// Quick accept: if pointers are the same, the ids are the same
712712
data: &'static TypeIdData,
713713
/// Quick reject: if hashes are different, the ids are different
714-
partial_hash: usize,
714+
/// We use a raw pointer instead of a `usize`, because const eval
715+
/// will be storing this as a fake pointer that will turn into the
716+
/// appropriate bits at codegen time. This prevents users from inspecting
717+
/// these bits at compile time.
718+
partial_hash: *const (),
715719
}
716720

721+
// SAFETY: the raw pointer is always an integer
722+
#[stable(feature = "rust1", since = "1.0.0")]
723+
unsafe impl Send for TypeId {}
724+
// SAFETY: the raw pointer is always an integer
725+
#[stable(feature = "rust1", since = "1.0.0")]
726+
unsafe impl Sync for TypeId {}
727+
717728
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
718729
struct TypeIdData {
719730
full_hash: [u8; 16],
720-
#[cfg(feature = "debug_typeid")]
721-
name: &'static str,
722731
}
723732

724733
#[stable(feature = "rust1", since = "1.0.0")]
@@ -759,15 +768,13 @@ impl TypeId {
759768
pub const fn of<T: ?Sized + 'static>() -> TypeId {
760769
let data = &const {
761770
let t: u128 = intrinsics::type_id::<T>();
762-
TypeIdData {
763-
full_hash: t.to_ne_bytes(),
764-
765-
#[cfg(feature = "debug_typeid")]
766-
name: type_name::<T>(),
767-
}
771+
TypeIdData { full_hash: t.to_ne_bytes() }
768772
};
769773

770-
TypeId { data, partial_hash: intrinsics::type_id::<T>() as usize }
774+
TypeId {
775+
data,
776+
partial_hash: crate::ptr::without_provenance(intrinsics::type_id::<T>() as usize),
777+
}
771778
}
772779

773780
fn as_u128(self) -> u128 {
@@ -798,15 +805,7 @@ impl hash::Hash for TypeId {
798805
#[stable(feature = "rust1", since = "1.0.0")]
799806
impl fmt::Debug for TypeId {
800807
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
801-
#[cfg(feature = "debug_typeid")]
802-
{
803-
write!(f, "TypeId({:#034x} = {})", self.as_u128(), self.name)?;
804-
}
805-
#[cfg(not(feature = "debug_typeid"))]
806-
{
807-
write!(f, "TypeId({:#034x})", self.as_u128())?;
808-
}
809-
Ok(())
808+
write!(f, "TypeId({:#034x})", self.as_u128())
810809
}
811810
}
812811

library/coretests/tests/any.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,6 @@ fn any_unsized() {
118118
is_any::<[i32]>();
119119
}
120120

121-
#[cfg(feature = "debug_typeid")]
122-
#[test]
123-
fn debug_typeid_includes_name() {
124-
let type_id = TypeId::of::<[usize; 2]>();
125-
let debug_str = format!("{type_id:?}");
126-
assert!(debug_str.ends_with("= [usize; 2])"), "{debug_str:?} did not match");
127-
}
128-
129121
#[test]
130122
fn distinct_type_names() {
131123
// https://github.com/rust-lang/rust/issues/84666

library/std/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,6 @@ optimize_for_size = ["core/optimize_for_size", "alloc/optimize_for_size"]
113113
# Make `RefCell` store additional debugging information, which is printed out when
114114
# a borrow error occurs
115115
debug_refcell = ["core/debug_refcell"]
116-
# Make `TypeId` store a reference to the name of the type, so that it can print that name.
117-
debug_typeid = ["core/debug_typeid"]
118116

119117

120118
# Enable std_detect default features for stdarch/crates/std_detect:

library/sysroot/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ compiler-builtins-no-asm = ["std/compiler-builtins-no-asm"]
2222
compiler-builtins-no-f16-f128 = ["std/compiler-builtins-no-f16-f128"]
2323
compiler-builtins-mangled-names = ["std/compiler-builtins-mangled-names"]
2424
debug_refcell = ["std/debug_refcell"]
25-
debug_typeid = ["std/debug_typeid"]
2625
llvm-libunwind = ["std/llvm-libunwind"]
2726
system-llvm-libunwind = ["std/system-llvm-libunwind"]
2827
optimize_for_size = ["std/optimize_for_size"]

0 commit comments

Comments
 (0)