Looking at this convert function, I was surprised that it doesn’t have a hint::cold_path. IMHO both consuming and producing an error, doubly make the second branch a candidate. OTOH, if it didn’t have the const-hack, a ? would offer no place to put the hint. That makes me wonder, whether just like for panic!() that happens automatically.
pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error> {
// FIXME(const-hack): This should use `?` again, once it's `const`
match run_utf8_validation(v) {
Ok(_) => {
// SAFETY: validation succeeded.
Ok(unsafe { from_utf8_unchecked(v) })
}
Err(err) => Err(err),
}
}
That raises the question: what about None. That might be more common than Err. But is it common enough to make an automatically inserted hint::cold_path counterproductive?