{"record":{"id":"60ab0f76ef7796d7","repo":"rust-lang/rust","slug":"requires-target-has-reliable-f16","errorCode":null,"errorMessage":"requires target_has_reliable_f16","messagePattern":"requires target_has_reliable_f16","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"library/core/src/num/float_parse.rs","lineNumber":91,"sourceCode":"}\n\n#[cfg(target_has_reliable_f16)]\nfrom_str_float_impl!(f16);\nfrom_str_float_impl!(f32);\nfrom_str_float_impl!(f64);\n\n// FIXME(f16): A fallback is used when the backend+target does not support f16 well, in order\n// to avoid ICEs.\n\n#[cfg(not(target_has_reliable_f16))]\n#[expect(ineffective_unstable_trait_impl, reason = \"stable trait on unstable type\")]\n#[unstable(feature = \"f16\", issue = \"116909\")]\nimpl FromStr for f16 {\n    type Err = ParseFloatError;\n\n    #[inline]\n    fn from_str(_src: &str) -> Result<Self, ParseFloatError> {\n        unimplemented!(\"requires target_has_reliable_f16\")\n    }\n}\n\n/// An error which can be returned when parsing a float.\n///\n/// This error is used as the error type for the [`FromStr`] implementation\n/// for [`f32`] and [`f64`].\n///\n/// # Example\n///\n/// ```\n/// use std::str::FromStr;\n///\n/// if let Err(e) = f64::from_str(\"a.12\") {\n///     println!(\"Failed conversion to f64: {e}\");\n/// }\n/// ```\n#[derive(Debug, Clone, PartialEq, Eq)]","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/library/core/src/num/float_parse.rs#L73-L109","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Compile/run for a target that sets target_has_reliable_f16 (e.g. aarch64/x86_64 with recent LLVM).","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;","Gate your f16 parsing code behind #[cfg(target_has_reliable_f16)] and provide a fallback for other targets.","Track the f16 stabilization issue (#116909) and upgrade nightly once reliable f16 reaches your target."],"exampleFix":"// before\nlet v: f16 = \"1.5\".parse().unwrap(); // panics on unreliable-f16 targets\n\n// after\n#[cfg(target_has_reliable_f16)]\nlet v: f16 = \"1.5\".parse().unwrap();\n#[cfg(not(target_has_reliable_f16))]\nlet v: f16 = \"1.5\".parse::<f32>().unwrap() as f16;","handlingStrategy":"validation","validationCode":"// Validate at compile time that f16 parsing is available on this target:\n#[cfg(not(target_has_reliable_f16))]\ncompile_error!(\"f16 parsing is unavailable on this target; parse via f32 and narrow\");","typeGuard":null,"tryCatchPattern":"// f16::from_str panics rather than returning Err, so a plain try/catch will not work.\n// Guard with cfg and provide a non-panicking fallback:\nfn parse_f16(s: &str) -> Result<f16, std::num::ParseFloatError> {\n    #[cfg(target_has_reliable_f16)]\n    { s.parse::<f16>() }\n    #[cfg(not(target_has_reliable_f16))]\n    { Ok(s.parse::<f32>()? as f16) }\n}","preventionTips":["Gate f16 parsing behind #[cfg(target_has_reliable_f16)].","Parse to f32 then cast to f16 on unsupported targets.","Check the target triple's f16 support before depending on f16 parsing."],"tags":["stdlib","f16","parsing","target-cfg","nightly"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}