Skip to content

Commit fc1c2f5

Browse files
committed
Auto merge of #4005 - phansch:rustfix_match_as_ref, r=flip1995
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` cc #3630 changelog: none
2 parents 7a6d5c0 + 9a6c820 commit fc1c2f5

File tree

5 files changed

+60
-38
lines changed

5 files changed

+60
-38
lines changed

tests/ui/match_as_ref.fixed

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// run-rustfix
2+
3+
#![allow(unused)]
4+
#![warn(clippy::match_as_ref)]
5+
6+
fn match_as_ref() {
7+
let owned: Option<()> = None;
8+
let borrowed: Option<&()> = owned.as_ref();
9+
10+
let mut mut_owned: Option<()> = None;
11+
let borrow_mut: Option<&mut ()> = mut_owned.as_mut();
12+
}
13+
14+
fn main() {}

tests/ui/match_as_ref.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// run-rustfix
2+
3+
#![allow(unused)]
4+
#![warn(clippy::match_as_ref)]
5+
6+
fn match_as_ref() {
7+
let owned: Option<()> = None;
8+
let borrowed: Option<&()> = match owned {
9+
None => None,
10+
Some(ref v) => Some(v),
11+
};
12+
13+
let mut mut_owned: Option<()> = None;
14+
let borrow_mut: Option<&mut ()> = match mut_owned {
15+
None => None,
16+
Some(ref mut v) => Some(v),
17+
};
18+
}
19+
20+
fn main() {}

tests/ui/match_as_ref.stderr

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error: use as_ref() instead
2+
--> $DIR/match_as_ref.rs:8:33
3+
|
4+
LL | let borrowed: Option<&()> = match owned {
5+
| _________________________________^
6+
LL | | None => None,
7+
LL | | Some(ref v) => Some(v),
8+
LL | | };
9+
| |_____^ help: try this: `owned.as_ref()`
10+
|
11+
= note: `-D clippy::match-as-ref` implied by `-D warnings`
12+
13+
error: use as_mut() instead
14+
--> $DIR/match_as_ref.rs:14:39
15+
|
16+
LL | let borrow_mut: Option<&mut ()> = match mut_owned {
17+
| _______________________________________^
18+
LL | | None => None,
19+
LL | | Some(ref mut v) => Some(v),
20+
LL | | };
21+
| |_____^ help: try this: `mut_owned.as_mut()`
22+
23+
error: aborting due to 2 previous errors
24+

tests/ui/matches.rs

-14
Original file line numberDiff line numberDiff line change
@@ -136,20 +136,6 @@ fn match_wild_err_arm() {
136136
}
137137
}
138138

139-
fn match_as_ref() {
140-
let owned: Option<()> = None;
141-
let borrowed: Option<&()> = match owned {
142-
None => None,
143-
Some(ref v) => Some(v),
144-
};
145-
146-
let mut mut_owned: Option<()> = None;
147-
let borrow_mut: Option<&mut ()> = match mut_owned {
148-
None => None,
149-
Some(ref mut v) => Some(v),
150-
};
151-
}
152-
153139
macro_rules! foo_variant(
154140
($idx:expr) => (Foo::get($idx).unwrap())
155141
);

tests/ui/matches.stderr

+2-24
Original file line numberDiff line numberDiff line change
@@ -256,30 +256,8 @@ LL | Ok(3) => println!("ok"),
256256
| ^^^^^^^^^^^^^^
257257
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
258258

259-
error: use as_ref() instead
260-
--> $DIR/matches.rs:141:33
261-
|
262-
LL | let borrowed: Option<&()> = match owned {
263-
| _________________________________^
264-
LL | | None => None,
265-
LL | | Some(ref v) => Some(v),
266-
LL | | };
267-
| |_____^ help: try this: `owned.as_ref()`
268-
|
269-
= note: `-D clippy::match-as-ref` implied by `-D warnings`
270-
271-
error: use as_mut() instead
272-
--> $DIR/matches.rs:147:39
273-
|
274-
LL | let borrow_mut: Option<&mut ()> = match mut_owned {
275-
| _______________________________________^
276-
LL | | None => None,
277-
LL | | Some(ref mut v) => Some(v),
278-
LL | | };
279-
| |_____^ help: try this: `mut_owned.as_mut()`
280-
281259
error: you don't need to add `&` to all patterns
282-
--> $DIR/matches.rs:174:5
260+
--> $DIR/matches.rs:160:5
283261
|
284262
LL | / match foo_variant!(0) {
285263
LL | | &Foo::A => println!("A"),
@@ -292,5 +270,5 @@ LL | match *foo_variant!(0) {
292270
LL | Foo::A => println!("A"),
293271
|
294272

295-
error: aborting due to 20 previous errors
273+
error: aborting due to 18 previous errors
296274

0 commit comments

Comments
 (0)