Skip to content

Add run-rustfix for match_as_ref lint #4005

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/ui/match_as_ref.fixed
Original file line number Diff line number Diff line change
@@ -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 changes: 20 additions & 0 deletions tests/ui/match_as_ref.rs
Original file line number Diff line number Diff line change
@@ -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() {}
24 changes: 24 additions & 0 deletions tests/ui/match_as_ref.stderr
Original file line number Diff line number Diff line change
@@ -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

14 changes: 0 additions & 14 deletions tests/ui/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
);
Expand Down
26 changes: 2 additions & 24 deletions tests/ui/matches.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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