Incorrect slicing suggestion for pattern matching against a Vec
inside a Result
or Option
#91328
Labels
A-diagnostics
Area: Messages for errors, warnings, and lints
D-invalid-suggestion
Diagnostics: A structured suggestion resulting in incorrect code.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
When trying to pattern match against a
Vec
inside aResult
orOption
, an incorrect suggestion is given, that says to append[..]
to the variable to slice it, which won't work since the variable is of typeResult
/Option
rather than being aVec
itself.Instead one option is to use
.as_deref()
on theResult
:https://doc.rust-lang.org/std/result/enum.Result.html#method.as_deref
Given the following code:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1e834c61673228c36f08e8c294efc68d
The current output is:
Ideally the output should look like:
The text was updated successfully, but these errors were encountered: