Description
rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)
0.3.1916-standalone
rustc version: (eg. output of rustc -V
)
rustc 1.77.1 (7cf61ebde 2024-03-27)
editor or extension: (eg. VSCode, Vim, Emacs, etc. For VSCode users, specify your extension version; for users of other editors, provide the distribution if applicable)
VSCode v0.3.1916
relevant settings: (eg. client settings, or environment variables like CARGO
, RUSTC
, RUSTUP_HOME
or CARGO_HOME
)
repository link (if public, optional): (eg. rust-analyzer)
sourcefrog/cargo-mutants@7901e6d
code snippet to reproduce:
/// Match known key-value maps that can be empty or constructed from pair of
/// recursively-generated values.
fn known_map(path: &Path) -> Option<(&Ident, &Type, &Type)> {
let last = path.segments.last()?;
if !["BTreeMap", "HashMap"].iter().any(|v| last.ident == v) {
return None;
}
if let PathArguments::AngleBracketed(AngleBracketedGenericArguments { args, .. }) =
&last.arguments
{
// TODO: Skip lifetime args.
// TODO: Return the path with args stripped out.
if let Some((GenericArgument::Type(key_type), GenericArgument::Type(value_type))) =
args.iter().collect_tuple()
{
return Some((&last.ident, key_type, value_type));
}
}
None
}
Apply this patch to the commit shown above:
diff --git a/src/fnvalue.rs b/src/fnvalue.rs
index 112afe9..0f00bd3 100644
--- a/src/fnvalue.rs
+++ b/src/fnvalue.rs
@@ -333,7 +333,7 @@ fn known_map(path: &Path) -> Option<(&Ident, &Type, &Type)> {
{
// TODO: Skip lifetime args.
// TODO: Return the path with args stripped out.
- if let Some((GenericArgument::Type(ref key_type), GenericArgument::Type(ref value_type))) =
+ if let Some((GenericArgument::Type(key_type), GenericArgument::Type(value_type))) =
args.iter().collect_tuple()
{
return Some((&last.ident, key_type, value_type));
What I would expect is that either rustc and rust-analyzer both accept this, or they both reject it.
What happens is that cargo build
passes (on today's stable, beta, and nightly), but rust-analyzer flags two errors:
[{
"resource": "/home/mbp/src/mutants/src/fnvalue.rs",
"owner": "rustc",
"code": {
"value": "E0308",
"target": {
"$mid": 1,
"path": "/stable/error_codes/E0308.html",
"scheme": "https",
"authority": "doc.rust-lang.org"
}
},
"severity": 8,
"message": "expected &Type, found Type",
"source": "rust-analyzer",
"startLineNumber": 339,
"startColumn": 39,
"endLineNumber": 339,
"endColumn": 47
},{
"resource": "/home/mbp/src/mutants/src/fnvalue.rs",
"owner": "rustc",
"code": {
"value": "E0308",
"target": {
"$mid": 1,
"path": "/stable/error_codes/E0308.html",
"scheme": "https",
"authority": "doc.rust-lang.org"
}
},
"severity": 8,
"message": "expected &Type, found Type",
"source": "rust-analyzer",
"startLineNumber": 339,
"startColumn": 49,
"endLineNumber": 339,
"endColumn": 59
}]