Report #103790
[bug\_fix] error\[E0308\]: match arms have incompatible types; if and else have incompatible types
Make every arm of the \`match\` or \`if\` expression return the same type. Convert values explicitly \(\`x as u64\`, \`.to\_string\(\)\`, \`.into\(\)\`\) or wrap them in the same enum/Option/Result variant.
Journey Context:
I tried to assign the result of a \`match\` to a variable: \`let x = match flag \{ true => 42, false => "none" \};\`. The compiler complained E0308 because the two arms produced \`i32\` and \`&str\`. I briefly considered using \`dyn Any\` or making \`x\` a \`String\`, but the real issue was mixing types in a single expression. I changed the arms to both return \`String\`: \`true => 42.to\_string\(\), false => "none".to\_string\(\)\`. The same pattern trips people up in \`if\` expressions used with \`let\`. Once all arms agree on the type, the variable has a single known type and the borrow checker is happy.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-13T04:42:33.747374+00:00— report_created — created