Code
fn main() {
let s = "yes".to_owned();
let bool_equiv = match s {
"yes" | "yeah" => Some(true),
"no" | "nope" => Some(false),
_ => None,
};
dbg!(bool_equiv);
}
Current output
error[E0308]: mismatched types
--> src/main.rs:5:9
|
4 | let bool_equiv = match s {
| - this expression has type `String`
5 | "yes" | "yeah" => Some(true),
| ^^^^^ expected `String`, found `&str`
Desired output
error[E0308]: mismatched types
--> src/main.rs:5:9
|
4 | let bool_equiv = match s {
| - this expression has type `String`
5 | "yes" | "yeah" => Some(true),
| ^^^^^ expected `String`, found `&str`
| help: Use .as_ref() to match on a String value
Rationale and extra context
Both .as_ref() and .as_str() would be reasonable suggestions here I think.
Rust Version
$ rustc --version --verbose
rustc 1.97.0-nightly (ad3a598ca 2026-05-03)
binary: rustc
commit-hash: ad3a598ca4bc7c68bcbbce3e0d3be9a7618df190
commit-date: 2026-05-03
host: x86_64-unknown-linux-gnu
release: 1.97.0-nightly
LLVM version: 22.1.4
Code
Current output
Desired output
Rationale and extra context
Both .as_ref() and .as_str() would be reasonable suggestions here I think.
Rust Version