Curiosity: Why `TypeId::of` has a `cfg(bootstrap)`?


#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
pub const fn of<T: ?Sized + 'static>() -> TypeId {
    let t = intrinsics::type_id::<T>() as u128;
    let t: u128 = intrinsics::type_id::<T>();
    TypeId { t }

In some stage TypeId is not a u128 internally?

btw: Why it's marked by a #[must_use]? Does not using it lead to anything bad?

Since it's an intrinsic, it depends on the compiler, and it used to be returned as u64. The cfg(bootstrap) deals with the difference between the former and current behavior.

#[must_use] is advisory -- nothing bad will happen, but there's no point in calling this if you don't use the value, so the attribute raises a warning that you might have done this by mistake.

Look at beta or nightly and the cfg is gone. This is simply because the current stable, 1.72, is exactly when the change to 128 bit representation landed. The standard library is used to build rustc itself, too, and rustc 1.72 is first built using a rustc 1.71 binary (but already the 1.72 standard library) during bootstrap, then re-built using the rustc 1.72 from the first step to make 1.72 "build itself". The first step (aka first "stage" of bootstrap) is thus using a typeid intrinsic that is returning 64 bit values with rustc 1.71, the next step uses the proper new 128 bit returning one from rust 1.72 itself. See the "Milestone 1.72" tag on the relevant PR, indicating in what stable version it first landed:

See also: