Description
rust-analyzer version: 0.3.1309-standalone (a2beeb8 2022-12-04); also affects pre-release v0.4.1314.
rustc version: rustc 1.65.0 (897e37553 2022-11-02)
relevant settings: None - I've used VSCode's rust-analyzer extension defaults everywhere, except for
{"rust-analyzer.inlayHints.typeHints.enable": false, "rust-analyzer.checkOnSave.command": "clippy"}
I've found a reproducible case where rust-analyzer returns a type mismatch error on code that compiles and runs correctly. (Caveat: I'm relatively new to the Rust ecosystem; equally, I can't see a case in which rustc and RA disagreeing about the type system isn't a bug!)
The offending code below is based on the example given in scan_fmt.
#[macro_use]
extern crate scan_fmt;
fn main() {
let word = scan_fmt!("hello", "{}", String).unwrap();
println!("{}", word);
}
The "problems" tab in VS Code contains the following:
expected String, found &str rust-analyzer(type-mismatch) [Ln 5, Col 16]
expected String, found &str rust-analyzer(type-mismatch) [Ln 5, Col 16]
expected String, found &str rust-analyzer(type-mismatch) [Ln 5, Col 16]
By comparison, clippy doesn't raise any errors, and compiling and running the example works fine:
PS C:\[...]\ra-bug-report> cargo run --bin repro
Finished dev [unoptimized + debuginfo] target(s) in 0.02s
Running `target\debug\repro.exe`
hello
The RA error has the following verbose result:
[{
"resource": "/c:/[...]/ra-bug-report/src/bin/repro.rs",
"owner": "rustc",
"code": {
"value": "type-mismatch",
"target": {
"$mid": 1,
"external": "https://rust-analyzer.github.io/manual.html#type-mismatch",
"path": "/manual.html",
"scheme": "https",
"authority": "rust-analyzer.github.io",
"fragment": "type-mismatch"
}
},
"severity": 8,
"message": "expected String, found &str",
"source": "rust-analyzer",
"startLineNumber": 5,
"startColumn": 16,
"endLineNumber": 5,
"endColumn": 48
}]