Skip to content
This repository was archived by the owner on Apr 28, 2025. It is now read-only.

Commit c0b4628

Browse files
committed
Resolve monomorphization errors in compiler-builtins
`compiler-builtins` is not allowed to call anything from `core`; however, there are a couple of cases where we do so in `libm` for debug output. Gate relevant locations behind the `compiler-builtins` Cargo feature.
1 parent 514d2f0 commit c0b4628

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

libm/Cargo.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ exclude = [
6161
[dev-dependencies]
6262
no-panic = "0.1.33"
6363

64+
65+
[lints.rust]
66+
unexpected_cfgs = { level = "warn", check-cfg = [
67+
# compiler-builtins sets this feature, but we use it in `libm`
68+
'cfg(feature, values("compiler-builtins"))',
69+
] }
70+
6471
# The default release profile is unchanged.
6572

6673
# Release mode with debug assertions

libm/crates/compiler-builtins-smoke-test/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ unexpected_cfgs = { level = "warn", check-cfg = [
2222
"cfg(arch_enabled)",
2323
"cfg(assert_no_panic)",
2424
"cfg(intrinsics_enabled)",
25+
'cfg(feature, values("compiler-builtins"))',
2526
'cfg(feature, values("force-soft-floats"))',
2627
'cfg(feature, values("unstable"))',
2728
'cfg(feature, values("unstable-intrinsics"))',

libm/crates/compiler-builtins-smoke-test/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
//! Additionally, it provides a `#[no_mangle]` C API that can be easier to inspect than the
55
//! default `.rlib`.
66
7+
#![compiler_builtins]
78
#![feature(core_intrinsics)]
9+
#![feature(compiler_builtins)]
810
#![feature(f16)]
911
#![feature(f128)]
1012
#![allow(internal_features)]

libm/src/math/support/hex_float.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,13 @@ fn fmt_any_hex<F: Float>(x: &F, f: &mut fmt::Formatter<'_>) -> fmt::Result {
246246

247247
impl<F: Float> fmt::LowerHex for Hexf<F> {
248248
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
249-
fmt_any_hex(&self.0, f)
249+
cfg_if! {
250+
if #[cfg(feature = "compiler-builtins")] {
251+
unreachable!()
252+
} else {
253+
fmt_any_hex(&self.0, f)
254+
}
255+
}
250256
}
251257
}
252258

@@ -264,7 +270,13 @@ impl<F: Float> fmt::LowerHex for Hexf<(F, i32)> {
264270

265271
impl fmt::LowerHex for Hexf<i32> {
266272
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
267-
fmt::LowerHex::fmt(&self.0, f)
273+
cfg_if! {
274+
if #[cfg(feature = "compiler-builtins")] {
275+
unreachable!()
276+
} else {
277+
fmt::LowerHex::fmt(&self.0, f)
278+
}
279+
}
268280
}
269281
}
270282

libm/src/math/support/int_traits.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ macro_rules! cast_into_float {
418418
($ty:ty; $($into:ty),*) => {$(
419419
impl CastInto<$into> for $ty {
420420
fn cast(self) -> $into {
421+
#[cfg(not(feature = "compiler-builtins"))]
421422
debug_assert_eq!(self as $into as $ty, self, "inexact float cast");
422423
self as $into
423424
}

0 commit comments

Comments
 (0)