about summary refs log tree commit diff
path: root/library/sysroot
diff options
context:
space:
mode:
authorKevin Reid <kpreid@switchb.org>2025-01-27 09:34:56 -0800
committerKevin Reid <kpreid@switchb.org>2025-02-11 18:42:19 -0800
commitd2ed8cf6619764e2a0af8a691c4ccb8c034b1e57 (patch)
tree1742dfa7c896a1b5a0eb792b4a014a01cf0870c6 /library/sysroot
parent0cffe5cb95e36d45a3e61f7b1f5a9b21eddd77b4 (diff)
downloadrust-d2ed8cf6619764e2a0af8a691c4ccb8c034b1e57.tar.gz
rust-d2ed8cf6619764e2a0af8a691c4ccb8c034b1e57.zip
Optionally add type names to `TypeId`s.
This feature is intended to provide expensive but thorough help for
developers who have an unexpected `TypeId` value and need to determine
what type it actually is. It causes `impl Debug for TypeId` to print
the type name in addition to the opaque ID hash, and in order to do so,
adds a name field to `TypeId`. The cost of this is the increased size of
`TypeId` and the need to store type names in the binary; therefore, it
is an optional feature.

It may be enabled via `cargo -Zbuild-std -Zbuild-std-features=debug_typeid`.
(Note that `-Zbuild-std-features` disables default features which you
may wish to reenable in addition; see
<https://doc.rust-lang.org/cargo/reference/unstable.html#build-std-features>.)

Example usage and output:

```
fn main() {
    use std::any::{Any, TypeId};
    dbg!(TypeId::of::<usize>(), drop::<usize>.type_id());
}
```

```
TypeId::of::<usize>() = TypeId(0x763d199bccd319899208909ed1a860c6 = usize)
drop::<usize>.type_id() = TypeId(0xe6a34bd13f8c92dd47806da07b8cca9a = core::mem::drop<usize>)
```

Also added feature declarations for the existing `debug_refcell` feature
so it is usable from the `rust.std-features` option of `config.toml`.
Diffstat (limited to 'library/sysroot')
-rw-r--r--library/sysroot/Cargo.toml4
1 files changed, 3 insertions, 1 deletions
diff --git a/library/sysroot/Cargo.toml b/library/sysroot/Cargo.toml
index aa6c3dc32e2..6ed2756e526 100644
--- a/library/sysroot/Cargo.toml
+++ b/library/sysroot/Cargo.toml
@@ -19,11 +19,13 @@ compiler-builtins-mem = ["std/compiler-builtins-mem"]
 compiler-builtins-no-asm = ["std/compiler-builtins-no-asm"]
 compiler-builtins-no-f16-f128 = ["std/compiler-builtins-no-f16-f128"]
 compiler-builtins-mangled-names = ["std/compiler-builtins-mangled-names"]
+debug_refcell = ["std/debug_refcell"]
+debug_typeid = ["std/debug_typeid"]
 llvm-libunwind = ["std/llvm-libunwind"]
 system-llvm-libunwind = ["std/system-llvm-libunwind"]
+optimize_for_size = ["std/optimize_for_size"]
 panic-unwind = ["std/panic_unwind"]
 panic_immediate_abort = ["std/panic_immediate_abort"]
-optimize_for_size = ["std/optimize_for_size"]
 profiler = ["dep:profiler_builtins"]
 std_detect_file_io = ["std/std_detect_file_io"]
 std_detect_dlsym_getauxval = ["std/std_detect_dlsym_getauxval"]