I tried this code:
use std::collections::HashMap;
fn what() {
let descr = String::new();
let mut opts = HashMap::new();
let opt = String::new();
// To fix the error, `as_ref` should be replaced with `as_str`
if let None = opts.get(opt.as_ref()) {
opts.insert(opt, ());
}
}
(playground)
I expected to see this happen: error pointing to opt.as_ref()
Instead, this happened: error points to descr which is unrelated to the error
error[E0283]: type annotations needed for `String`
--> src/lib.rs:8:24
|
4 | let descr = String::new();
| ----- consider giving `descr` a type
...
8 | if let None = opts.get(opt.as_ref()) {
| ^^^ cannot infer type for struct `String`
|
= note: cannot satisfy `String: Borrow<_>`
Meta
Tested with rustc 1.47.0 (18bf6b4f0 2020-10-07) and rustc 1.49.0-nightly (2020-10-14 e160e5cb80652bc2afe7)
I tried this code:
(playground)
I expected to see this happen: error pointing to
opt.as_ref()Instead, this happened: error points to
descrwhich is unrelated to the errorMeta
Tested with
rustc 1.47.0 (18bf6b4f0 2020-10-07)andrustc 1.49.0-nightly (2020-10-14 e160e5cb80652bc2afe7)