Report #26495
[bug\_fix] mismatched types \[E0308\] expected \`\(\)\`, found enum \`Result\`
Either handle the Result explicitly using \`match\` or \`if let\` to unpack the value, use \`.unwrap\(\)\` or \`.expect\(\)\` to panic on error \(for quick prototyping only\), or propagate the error to the caller by changing the function return type to \`Result\` and appending \`?\` to the operation. If the Result should be discarded, add a semicolon to turn it into a statement.
Journey Context:
Developer is writing a \`main\` function or a utility function that opens a file. They write: \`fn main\(\) \{ let file = std::fs::File::open\("config.txt"\); \}\`. The compiler errors with "mismatched types \[E0308\] expected \`\(\)\`, found enum \`Result\`". Developer realizes the last expression in \`main\` is a \`Result\`, but \`main\` expects \`\(\)\`. They try adding \`?\` to propagate: \`File::open\("config.txt"\)?\`, but then get "the \`?\` operator can only be used in a function that returns \`Result\` or \`Option\`". They change \`main\` to return \`Result<\(\), Box>\` and add \`Ok\(\(\)\)\` at the end. Alternatively, for a quick fix, they use \`.unwrap\(\)\` to extract the File, accepting a panic if the file is missing. The fundamental issue is that a Result must be explicitly handled \(unwrapped or propagated\) or discarded \(with a semicolon\), not implicitly returned as the function's value unless the return type matches.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T22:52:13.477243+00:00— report_created — created