Add run-rustfix for match_as_ref lint

* Extracts `match_as_ref` into separate file
* Adds `// run-rustfix` to `tests/ui/match_as_ref.rs`
This commit is contained in:
Philipp Hansch 2019-04-19 12:08:00 +02:00
parent 0d9ef393b8
commit 9a6c82094f
No known key found for this signature in database
GPG Key ID: 82AA61CAA11397E6
5 changed files with 60 additions and 38 deletions

View File

@ -0,0 +1,14 @@
// run-rustfix
#![allow(unused)]
#![warn(clippy::match_as_ref)]
fn match_as_ref() {
let owned: Option<()> = None;
let borrowed: Option<&()> = owned.as_ref();
let mut mut_owned: Option<()> = None;
let borrow_mut: Option<&mut ()> = mut_owned.as_mut();
}
fn main() {}

20
tests/ui/match_as_ref.rs Normal file
View File

@ -0,0 +1,20 @@
// run-rustfix
#![allow(unused)]
#![warn(clippy::match_as_ref)]
fn match_as_ref() {
let owned: Option<()> = None;
let borrowed: Option<&()> = match owned {
None => None,
Some(ref v) => Some(v),
};
let mut mut_owned: Option<()> = None;
let borrow_mut: Option<&mut ()> = match mut_owned {
None => None,
Some(ref mut v) => Some(v),
};
}
fn main() {}

View File

@ -0,0 +1,24 @@
error: use as_ref() instead
--> $DIR/match_as_ref.rs:8:33
|
LL | let borrowed: Option<&()> = match owned {
| _________________________________^
LL | | None => None,
LL | | Some(ref v) => Some(v),
LL | | };
| |_____^ help: try this: `owned.as_ref()`
|
= note: `-D clippy::match-as-ref` implied by `-D warnings`
error: use as_mut() instead
--> $DIR/match_as_ref.rs:14:39
|
LL | let borrow_mut: Option<&mut ()> = match mut_owned {
| _______________________________________^
LL | | None => None,
LL | | Some(ref mut v) => Some(v),
LL | | };
| |_____^ help: try this: `mut_owned.as_mut()`
error: aborting due to 2 previous errors

View File

@ -136,20 +136,6 @@ fn match_wild_err_arm() {
}
}
fn match_as_ref() {
let owned: Option<()> = None;
let borrowed: Option<&()> = match owned {
None => None,
Some(ref v) => Some(v),
};
let mut mut_owned: Option<()> = None;
let borrow_mut: Option<&mut ()> = match mut_owned {
None => None,
Some(ref mut v) => Some(v),
};
}
macro_rules! foo_variant(
($idx:expr) => (Foo::get($idx).unwrap())
);

View File

@ -256,30 +256,8 @@ LL | Ok(3) => println!("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:141:33
|
LL | let borrowed: Option<&()> = match owned {
| _________________________________^
LL | | None => None,
LL | | Some(ref v) => Some(v),
LL | | };
| |_____^ help: try this: `owned.as_ref()`
|
= note: `-D clippy::match-as-ref` implied by `-D warnings`
error: use as_mut() instead
--> $DIR/matches.rs:147:39
|
LL | let borrow_mut: Option<&mut ()> = match mut_owned {
| _______________________________________^
LL | | None => None,
LL | | Some(ref mut v) => Some(v),
LL | | };
| |_____^ help: try this: `mut_owned.as_mut()`
error: you don't need to add `&` to all patterns
--> $DIR/matches.rs:174:5
--> $DIR/matches.rs:160:5
|
LL | / match foo_variant!(0) {
LL | | &Foo::A => println!("A"),
@ -292,5 +270,5 @@ LL | match *foo_variant!(0) {
LL | Foo::A => println!("A"),
|
error: aborting due to 20 previous errors
error: aborting due to 18 previous errors