about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPhilipp Hansch <dev@phansch.net>2019-04-19 12:08:00 +0200
committerPhilipp Hansch <dev@phansch.net>2019-04-19 12:08:34 +0200
commit9a6c82094fb6d26084d641696873bb55f9e61cc8 (patch)
tree28f5936485f2bbae3e4232b30211331c53bbd42b
parent0d9ef393b8c2596aca6a037d3efb513afdf17875 (diff)
downloadrust-9a6c82094fb6d26084d641696873bb55f9e61cc8.tar.gz
rust-9a6c82094fb6d26084d641696873bb55f9e61cc8.zip
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`
-rw-r--r--tests/ui/match_as_ref.fixed14
-rw-r--r--tests/ui/match_as_ref.rs20
-rw-r--r--tests/ui/match_as_ref.stderr24
-rw-r--r--tests/ui/matches.rs14
-rw-r--r--tests/ui/matches.stderr26
5 files changed, 60 insertions, 38 deletions
diff --git a/tests/ui/match_as_ref.fixed b/tests/ui/match_as_ref.fixed
new file mode 100644
index 00000000000..75085367f96
--- /dev/null
+++ b/tests/ui/match_as_ref.fixed
@@ -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() {}
diff --git a/tests/ui/match_as_ref.rs b/tests/ui/match_as_ref.rs
new file mode 100644
index 00000000000..62c06f35251
--- /dev/null
+++ b/tests/ui/match_as_ref.rs
@@ -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() {}
diff --git a/tests/ui/match_as_ref.stderr b/tests/ui/match_as_ref.stderr
new file mode 100644
index 00000000000..09115b85d35
--- /dev/null
+++ b/tests/ui/match_as_ref.stderr
@@ -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
+
diff --git a/tests/ui/matches.rs b/tests/ui/matches.rs
index b711367d123..0360cc739c8 100644
--- a/tests/ui/matches.rs
+++ b/tests/ui/matches.rs
@@ -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())
 );
diff --git a/tests/ui/matches.stderr b/tests/ui/matches.stderr
index b4159f7a68d..27438258d23 100644
--- a/tests/ui/matches.stderr
+++ b/tests/ui/matches.stderr
@@ -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