Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/core/src/intrinsics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2887,7 +2887,7 @@ pub const fn type_name<T: ?Sized>() -> &'static str;
#[rustc_nounwind]
#[unstable(feature = "core_intrinsics", issue = "none")]
#[rustc_intrinsic]
pub const fn type_id<T: ?Sized + 'static>() -> crate::any::TypeId;
pub const fn type_id<T: ?Sized>() -> crate::any::TypeId;

/// Tests (at compile-time) if two [`crate::any::TypeId`] instances identify the
/// same type. This is necessary because at const-eval time the actual discriminating
Expand Down
14 changes: 10 additions & 4 deletions library/core/src/mem/type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! runtime or const-eval processable way.

use crate::any::TypeId;
use crate::intrinsics::type_of;
use crate::intrinsics::{type_id, type_of};

/// Compile-time type information.
#[derive(Debug)]
Expand All @@ -28,11 +28,17 @@ impl TypeId {

impl Type {
/// Returns the type information of the generic type parameter.
///
/// Note: Unlike `TypeId`s obtained via `TypeId::of`, the `Type`
/// struct and its fields contain `TypeId`s that are not necessarily
/// derived from types that outlive `'static`. This means that using
/// the `TypeId`s (transitively) obtained from this function will
/// be able to break invariants that other `TypeId` consuming crates
/// may have assumed to hold.
#[unstable(feature = "type_info", issue = "146922")]
#[rustc_const_unstable(feature = "type_info", issue = "146922")]
// FIXME(reflection): don't require the 'static bound
pub const fn of<T: ?Sized + 'static>() -> Self {
const { TypeId::of::<T>().info() }
pub const fn of<T: ?Sized>() -> Self {
const { type_id::<T>().info() }
}
}

Expand Down
Loading