rust-lang/rust · error

requires target_has_reliable_f16

Error message

requires target_has_reliable_f16

What it means

In library/core/src/num/float_parse.rs the FromStr impl for f16 is a stub guarded by #[cfg(not(target_has_reliable_f16))]. On targets whose backend does not reliably support f16 operations, parsing an f16 from a string deliberately panics rather than producing a wrong value; the comment notes this avoids ICEs. The real parsing impl is only compiled when target_has_reliable_f16 is set.

Source

Thrown at library/core/src/num/float_parse.rs:91

}

#[cfg(target_has_reliable_f16)]
from_str_float_impl!(f16);
from_str_float_impl!(f32);
from_str_float_impl!(f64);

// FIXME(f16): A fallback is used when the backend+target does not support f16 well, in order
// to avoid ICEs.

#[cfg(not(target_has_reliable_f16))]
#[expect(ineffective_unstable_trait_impl, reason = "stable trait on unstable type")]
#[unstable(feature = "f16", issue = "116909")]
impl FromStr for f16 {
    type Err = ParseFloatError;

    #[inline]
    fn from_str(_src: &str) -> Result<Self, ParseFloatError> {
        unimplemented!("requires target_has_reliable_f16")
    }
}

/// An error which can be returned when parsing a float.
///
/// This error is used as the error type for the [`FromStr`] implementation
/// for [`f32`] and [`f64`].
///
/// # Example
///
/// ```
/// use std::str::FromStr;
///
/// if let Err(e) = f64::from_str("a.12") {
///     println!("Failed conversion to f64: {e}");
/// }
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]

View on GitHub (pinned to 7088e4b63a)

Solutions

  1. Compile/run for a target that sets target_has_reliable_f16 (e.g. aarch64/x86_64 with recent LLVM).
  2. Parse as f32 first then narrow with 'as f16' if your target supports the f16 type but not parsing: let v = "1.5".parse::<f32>()? as f16;
  3. Gate your f16 parsing code behind #[cfg(target_has_reliable_f16)] and provide a fallback for other targets.
  4. Track the f16 stabilization issue (#116909) and upgrade nightly once reliable f16 reaches your target.

Example fix

// before
let v: f16 = "1.5".parse().unwrap(); // panics on unreliable-f16 targets

// after
#[cfg(target_has_reliable_f16)]
let v: f16 = "1.5".parse().unwrap();
#[cfg(not(target_has_reliable_f16))]
let v: f16 = "1.5".parse::<f32>().unwrap() as f16;
Defensive patterns

Strategy: validation

Validate before calling

// Validate at compile time that f16 parsing is available on this target:
#[cfg(not(target_has_reliable_f16))]
compile_error!("f16 parsing is unavailable on this target; parse via f32 and narrow");

Try / catch

// f16::from_str panics rather than returning Err, so a plain try/catch will not work.
// Guard with cfg and provide a non-panicking fallback:
fn parse_f16(s: &str) -> Result<f16, std::num::ParseFloatError> {
    #[cfg(target_has_reliable_f16)]
    { s.parse::<f16>() }
    #[cfg(not(target_has_reliable_f16))]
    { Ok(s.parse::<f32>()? as f16) }
}

Prevention

When it happens

Trigger: Calling "3.14".parse::<f16>() or f16::from_str("1.5") on a target where cfg!(target_has_reliable_f16) is false (e.g. many 32-bit / non-x86_64 targets or older LLVM-backed builds). The stub at float_parse.rs:91 is selected and panics.

Common situations: Cross-compiling or running on a tier-2/tier-3 target whose f16 ABI or LLVM support is incomplete; using f16 in firmware/embedded targets; a recent nightly where f16 parsing has not yet been enabled for your target triple.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/60ab0f76ef7796d7. Report an issue: GitHub.