The unstable likely/unlikely intrinsics, which can be used to hint the compiler and CPU branch prediction heuristics, may currently only be easily used on “raw” if statements that use a boolean condition.
However, refutable patterns such as
match arms or
if let are effectively branches too, and I cannot think of a fundamental reason why the developer shouldn’t be able to let rustc and LLVM know that some of these branches are more likely than others, so that they can optimize accordingly.
Has this matter been discussed in the past?