Consider these codes:
let x = "hello".to_string();
match &x {
"hello" => {println!("{}", x)},
_ => {}
}
The compiler would throw error::
6 | match &x {
| -- this expression has type `&String`
7 | "hello" => {println!("{}", x)},
| ^^^^^^^ expected struct `String`, found `str`
Why it failed to do auto deref to &str? When I replace match &x with match &*s, it would ok then.