Skip to content

Commit 278e079

Browse files
authored
Rollup merge of #148118 - saethlin:nullary-intrinsic-check-bug-msg, r=Noratrieb,dianqk
Improve the ICE message for invalid nullary intrinsic calls In #148104, we found the panic message here rather confusing, and (if I'm reading the tea leaves right) that's because the intended audience for either side of the phrase is very different. I think this is more clear if/when this is encountered by users. I expect this ICE to be hit in practice by people calling the `size_of` and `align_of` intrinsics, so it's now _kind of_ helpful for those users too. The original effort to stop backends from needing to support nullary intrinsics added a note to all these const-only intrinsics, but when #147793 ported two more the paragraph wasn't added. I've added it.
2 parents c7ebf73 + 7a0d9c8 commit 278e079

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

compiler/rustc_codegen_ssa/src/mir/intrinsic.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,15 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
120120
| sym::atomic_singlethreadfence
121121
| sym::caller_location => {}
122122
_ => {
123-
span_bug!(span, "nullary intrinsic {name} must either be in a const block or explicitly opted out because it is inherently a runtime intrinsic
124-
");
123+
span_bug!(
124+
span,
125+
"Nullary intrinsic {name} must be called in a const block. \
126+
If you are seeing this message from code outside the standard library, the \
127+
unstable implementation details of the relevant intrinsic may have changed. \
128+
Consider using stable APIs instead. \
129+
If you are adding a new nullary intrinsic that is inherently a runtime \
130+
intrinsic, update this check."
131+
);
125132
}
126133
}
127134
}

library/core/src/intrinsics/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2728,6 +2728,11 @@ pub unsafe fn vtable_align(ptr: *const ()) -> usize;
27282728
/// More specifically, this is the offset in bytes between successive
27292729
/// items of the same type, including alignment padding.
27302730
///
2731+
/// Note that, unlike most intrinsics, this can only be called at compile-time
2732+
/// as backends do not have an implementation for it. The only caller (its
2733+
/// stable counterpart) wraps this intrinsic call in a `const` block so that
2734+
/// backends only see an evaluated constant.
2735+
///
27312736
/// The stabilized version of this intrinsic is [`core::mem::size_of`].
27322737
#[rustc_nounwind]
27332738
#[unstable(feature = "core_intrinsics", issue = "none")]
@@ -2742,6 +2747,11 @@ pub const fn size_of<T>() -> usize;
27422747
/// Therefore, implementations must not require the user to uphold
27432748
/// any safety invariants.
27442749
///
2750+
/// Note that, unlike most intrinsics, this can only be called at compile-time
2751+
/// as backends do not have an implementation for it. The only caller (its
2752+
/// stable counterpart) wraps this intrinsic call in a `const` block so that
2753+
/// backends only see an evaluated constant.
2754+
///
27452755
/// The stabilized version of this intrinsic is [`core::mem::align_of`].
27462756
#[rustc_nounwind]
27472757
#[unstable(feature = "core_intrinsics", issue = "none")]

0 commit comments

Comments
 (0)