Skip to content

Commit 572cb75

Browse files
committed
Stop backends from needing to support nullary intrinsics
1 parent 2cf1d43 commit 572cb75

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

core/src/any.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ impl TypeId {
742742
#[stable(feature = "rust1", since = "1.0.0")]
743743
#[rustc_const_unstable(feature = "const_type_id", issue = "77125")]
744744
pub const fn of<T: ?Sized + 'static>() -> TypeId {
745-
let t: u128 = intrinsics::type_id::<T>();
745+
let t: u128 = const { intrinsics::type_id::<T>() };
746746
let t1 = (t >> 64) as u64;
747747
let t2 = t as u64;
748748

@@ -824,7 +824,7 @@ impl fmt::Debug for TypeId {
824824
#[stable(feature = "type_name", since = "1.38.0")]
825825
#[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
826826
pub const fn type_name<T: ?Sized>() -> &'static str {
827-
intrinsics::type_name::<T>()
827+
const { intrinsics::type_name::<T>() }
828828
}
829829

830830
/// Returns the type name of the pointed-to value as a string slice.

core/src/intrinsics/mod.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -839,10 +839,10 @@ pub const unsafe fn transmute_unchecked<Src, Dst>(src: Src) -> Dst;
839839
/// If the actual type neither requires drop glue nor implements
840840
/// `Copy`, then the return value of this function is unspecified.
841841
///
842-
/// Note that, unlike most intrinsics, this is safe to call;
843-
/// it does not require an `unsafe` block.
844-
/// Therefore, implementations must not require the user to uphold
845-
/// any safety invariants.
842+
/// Note that, unlike most intrinsics, this can only be called at compile-time
843+
/// as backends do not have an implementation for it. The only caller (its
844+
/// stable counterpart), wraps this intrinsic call in a `const` block so that
845+
/// backends only see an evaluated constant.
846846
///
847847
/// The stabilized version of this intrinsic is [`mem::needs_drop`](crate::mem::needs_drop).
848848
#[rustc_intrinsic_const_stable_indirect]
@@ -2655,10 +2655,10 @@ pub const fn align_of<T>() -> usize;
26552655
/// Returns the number of variants of the type `T` cast to a `usize`;
26562656
/// if `T` has no variants, returns `0`. Uninhabited variants will be counted.
26572657
///
2658-
/// Note that, unlike most intrinsics, this is safe to call;
2659-
/// it does not require an `unsafe` block.
2660-
/// Therefore, implementations must not require the user to uphold
2661-
/// any safety invariants.
2658+
/// Note that, unlike most intrinsics, this can only be called at compile-time
2659+
/// as backends do not have an implementation for it. The only caller (its
2660+
/// stable counterpart), wraps this intrinsic call in a `const` block so that
2661+
/// backends only see an evaluated constant.
26622662
///
26632663
/// The to-be-stabilized version of this intrinsic is [`crate::mem::variant_count`].
26642664
#[rustc_nounwind]
@@ -2694,10 +2694,10 @@ pub const unsafe fn align_of_val<T: ?Sized>(ptr: *const T) -> usize;
26942694

26952695
/// Gets a static string slice containing the name of a type.
26962696
///
2697-
/// Note that, unlike most intrinsics, this is safe to call;
2698-
/// it does not require an `unsafe` block.
2699-
/// Therefore, implementations must not require the user to uphold
2700-
/// any safety invariants.
2697+
/// Note that, unlike most intrinsics, this can only be called at compile-time
2698+
/// as backends do not have an implementation for it. The only caller (its
2699+
/// stable counterpart), wraps this intrinsic call in a `const` block so that
2700+
/// backends only see an evaluated constant.
27012701
///
27022702
/// The stabilized version of this intrinsic is [`core::any::type_name`].
27032703
#[rustc_nounwind]
@@ -2709,10 +2709,10 @@ pub const fn type_name<T: ?Sized>() -> &'static str;
27092709
/// function will return the same value for a type regardless of whichever
27102710
/// crate it is invoked in.
27112711
///
2712-
/// Note that, unlike most intrinsics, this is safe to call;
2713-
/// it does not require an `unsafe` block.
2714-
/// Therefore, implementations must not require the user to uphold
2715-
/// any safety invariants.
2712+
/// Note that, unlike most intrinsics, this can only be called at compile-time
2713+
/// as backends do not have an implementation for it. The only caller (its
2714+
/// stable counterpart), wraps this intrinsic call in a `const` block so that
2715+
/// backends only see an evaluated constant.
27162716
///
27172717
/// The stabilized version of this intrinsic is [`core::any::TypeId::of`].
27182718
#[rustc_nounwind]

core/src/mem/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ pub const unsafe fn align_of_val_raw<T: ?Sized>(val: *const T) -> usize {
616616
#[rustc_const_stable(feature = "const_mem_needs_drop", since = "1.36.0")]
617617
#[rustc_diagnostic_item = "needs_drop"]
618618
pub const fn needs_drop<T: ?Sized>() -> bool {
619-
intrinsics::needs_drop::<T>()
619+
const { intrinsics::needs_drop::<T>() }
620620
}
621621

622622
/// Returns the value of type `T` represented by the all-zero byte-pattern.
@@ -1215,7 +1215,7 @@ pub const fn discriminant<T>(v: &T) -> Discriminant<T> {
12151215
#[rustc_const_unstable(feature = "variant_count", issue = "73662")]
12161216
#[rustc_diagnostic_item = "mem_variant_count"]
12171217
pub const fn variant_count<T>() -> usize {
1218-
intrinsics::variant_count::<T>()
1218+
const { intrinsics::variant_count::<T>() }
12191219
}
12201220

12211221
/// Provides associated constants for various useful properties of types,

0 commit comments

Comments
 (0)