Lint for matching option as ref
This commit is contained in:
parent
cf58e1c672
commit
919601bc51
4 changed files with 110 additions and 3 deletions
|
|
@ -315,5 +315,20 @@ fn match_wild_err_arm() {
|
|||
}
|
||||
}
|
||||
|
||||
fn match_as_ref() {
|
||||
let owned : Option<()> = None;
|
||||
let borrowed = match owned {
|
||||
None => None,
|
||||
Some(ref v) => Some(v),
|
||||
};
|
||||
|
||||
let mut mut_owned : Option<()> = None;
|
||||
let mut mut_borrowed = match mut_owned {
|
||||
None => None,
|
||||
Some(ref mut v) => Some(v),
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -426,3 +426,25 @@ note: consider refactoring into `Ok(3) | Ok(_)`
|
|||
| ^^^^^^^^^^^^^^
|
||||
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
|
||||
|
||||
error: use as_ref() instead
|
||||
--> $DIR/matches.rs:320:20
|
||||
|
|
||||
320 | let borrowed = match owned {
|
||||
| ____________________^
|
||||
321 | | None => None,
|
||||
322 | | Some(ref v) => Some(v),
|
||||
323 | | };
|
||||
| |_____^ help: try this: `owned.as_ref()`
|
||||
|
|
||||
= note: `-D match-as-ref` implied by `-D warnings`
|
||||
|
||||
error: use as_ref() instead
|
||||
--> $DIR/matches.rs:326:28
|
||||
|
|
||||
326 | let mut mut_borrowed = match mut_owned {
|
||||
| ____________________________^
|
||||
327 | | None => None,
|
||||
328 | | Some(ref mut v) => Some(v),
|
||||
329 | | };
|
||||
| |_____^ help: try this: `mut_owned.as_ref()`
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue