Skip to content

Commit 3074f38

Browse files
committed
Auto merge of rust-lang#120675 - oli-obk:intrinsics3.0, r=pnkfelix
Add a scheme for moving away from `extern "rust-intrinsic"` entirely All `rust-intrinsic`s can become free functions now, either with a fallback body, or with a dummy body and an attribute, requiring backends to actually implement the intrinsic. This PR demonstrates the dummy-body scheme with the `vtable_size` intrinsic. cc rust-lang#63585 follow-up to rust-lang#120500 MCP at rust-lang/compiler-team#720
2 parents b37daad + 8430ecb commit 3074f38

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

core/src/intrinsics.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -2499,9 +2499,8 @@ extern "rust-intrinsic" {
24992499
#[rustc_nounwind]
25002500
pub fn black_box<T>(dummy: T) -> T;
25012501

2502-
/// `ptr` must point to a vtable.
2503-
/// The intrinsic will return the size stored in that vtable.
25042502
#[rustc_nounwind]
2503+
#[cfg(bootstrap)]
25052504
pub fn vtable_size(ptr: *const ()) -> usize;
25062505

25072506
/// `ptr` must point to a vtable.
@@ -2681,6 +2680,17 @@ pub const unsafe fn const_allocate(_size: usize, _align: usize) -> *mut u8 {
26812680
#[cfg_attr(bootstrap, inline)]
26822681
pub const unsafe fn const_deallocate(_ptr: *mut u8, _size: usize, _align: usize) {}
26832682

2683+
/// `ptr` must point to a vtable.
2684+
/// The intrinsic will return the size stored in that vtable.
2685+
#[rustc_nounwind]
2686+
#[unstable(feature = "core_intrinsics", issue = "none")]
2687+
#[cfg_attr(not(bootstrap), rustc_intrinsic)]
2688+
#[cfg_attr(not(bootstrap), rustc_intrinsic_must_be_overridden)]
2689+
#[cfg(not(bootstrap))]
2690+
pub unsafe fn vtable_size(_ptr: *const ()) -> usize {
2691+
unreachable!()
2692+
}
2693+
26842694
// Some functions are defined here because they accidentally got made
26852695
// available in this module on stable. See <https://github.com/rust-lang/rust/issues/15702>.
26862696
// (`transmute` also falls into this category, but it cannot be wrapped due to the

0 commit comments

Comments
 (0)