about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorYuki Okushi <huyuumi.dev@gmail.com>2019-12-22 07:59:38 +0900
committerYuki Okushi <huyuumi.dev@gmail.com>2019-12-22 08:21:36 +0900
commit30e84b02446e9906595e3053f537162c96fc7722 (patch)
treea61bf3970c8357772fabd77ffcddf57a4645c5ba /src/test
parentfc5deca2143a448d10a1241a777275e59448c94d (diff)
Tweak non_shorthand_field_patterns' suggestion
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/lint/lint-shorthand-field.fixed70
-rw-r--r--src/test/ui/lint/lint-shorthand-field.rs18
-rw-r--r--src/test/ui/lint/lint-shorthand-field.stderr34
-rw-r--r--src/test/ui/lint/suggestions.rs2
-rw-r--r--src/test/ui/lint/suggestions.stderr4
5 files changed, 113 insertions, 15 deletions
diff --git a/src/test/ui/lint/lint-shorthand-field.fixed b/src/test/ui/lint/lint-shorthand-field.fixed
new file mode 100644
index 00000000000..7cd5717bc5a
--- /dev/null
+++ b/src/test/ui/lint/lint-shorthand-field.fixed
@@ -0,0 +1,70 @@
+// run-rustfix
+
+#![allow(nonstandard_style, unused_variables, unused_mut)]
+#![deny(non_shorthand_field_patterns)]
+
+struct Foo {
+    x: isize,
+    y: isize,
+}
+
+fn main() {
+    {
+        let Foo {
+            x, //~ ERROR the `x:` in this pattern is redundant
+            ref y, //~ ERROR the `y:` in this pattern is redundant
+        } = Foo { x: 0, y: 0 };
+
+        let Foo {
+            x,
+            ref y,
+        } = Foo { x: 0, y: 0 };
+    }
+
+    {
+        const x: isize = 1;
+
+        match (Foo { x: 1, y: 1 }) {
+            Foo { x: x, ..} => {},
+            _ => {},
+        }
+    }
+
+    {
+        struct Bar {
+            x: x,
+        }
+
+        struct x;
+
+        match (Bar { x: x }) {
+            Bar { x: x } => {},
+        }
+    }
+
+    {
+        struct Bar {
+            x: Foo,
+        }
+
+        enum Foo { x }
+
+        match (Bar { x: Foo::x }) {
+            Bar { x: Foo::x } => {},
+        }
+    }
+
+    {
+        struct Baz {
+            x: isize,
+            y: isize,
+            z: isize,
+        }
+
+        let Baz {
+            mut x, //~ ERROR the `x:` in this pattern is redundant
+            ref y, //~ ERROR the `y:` in this pattern is redundant
+            ref mut z, //~ ERROR the `z:` in this pattern is redundant
+        } = Baz { x: 0, y: 0, z: 0 };
+    }
+}
diff --git a/src/test/ui/lint/lint-shorthand-field.rs b/src/test/ui/lint/lint-shorthand-field.rs
index 5e756d14dc8..22de9c32545 100644
--- a/src/test/ui/lint/lint-shorthand-field.rs
+++ b/src/test/ui/lint/lint-shorthand-field.rs
@@ -1,4 +1,6 @@
-#![allow(nonstandard_style, unused_variables)]
+// run-rustfix
+
+#![allow(nonstandard_style, unused_variables, unused_mut)]
 #![deny(non_shorthand_field_patterns)]
 
 struct Foo {
@@ -51,4 +53,18 @@ fn main() {
             Bar { x: Foo::x } => {},
         }
     }
+
+    {
+        struct Baz {
+            x: isize,
+            y: isize,
+            z: isize,
+        }
+
+        let Baz {
+            x: mut x, //~ ERROR the `x:` in this pattern is redundant
+            y: ref y, //~ ERROR the `y:` in this pattern is redundant
+            z: ref mut z, //~ ERROR the `z:` in this pattern is redundant
+        } = Baz { x: 0, y: 0, z: 0 };
+    }
 }
diff --git a/src/test/ui/lint/lint-shorthand-field.stderr b/src/test/ui/lint/lint-shorthand-field.stderr
index 366ab55d7d4..5c9b21ffdc7 100644
--- a/src/test/ui/lint/lint-shorthand-field.stderr
+++ b/src/test/ui/lint/lint-shorthand-field.stderr
@@ -1,24 +1,38 @@
 error: the `x:` in this pattern is redundant
-  --> $DIR/lint-shorthand-field.rs:12:13
+  --> $DIR/lint-shorthand-field.rs:14:13
    |
 LL |             x: x,
-   |             --^^
-   |             |
-   |             help: remove this
+   |             ^^^^ help: use shorthand field pattern: `x`
    |
 note: lint level defined here
-  --> $DIR/lint-shorthand-field.rs:2:9
+  --> $DIR/lint-shorthand-field.rs:4:9
    |
 LL | #![deny(non_shorthand_field_patterns)]
    |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 error: the `y:` in this pattern is redundant
-  --> $DIR/lint-shorthand-field.rs:13:13
+  --> $DIR/lint-shorthand-field.rs:15:13
    |
 LL |             y: ref y,
-   |             --^^^^^^
-   |             |
-   |             help: remove this
+   |             ^^^^^^^^ help: use shorthand field pattern: `ref y`
 
-error: aborting due to 2 previous errors
+error: the `x:` in this pattern is redundant
+  --> $DIR/lint-shorthand-field.rs:65:13
+   |
+LL |             x: mut x,
+   |             ^^^^^^^^ help: use shorthand field pattern: `mut x`
+
+error: the `y:` in this pattern is redundant
+  --> $DIR/lint-shorthand-field.rs:66:13
+   |
+LL |             y: ref y,
+   |             ^^^^^^^^ help: use shorthand field pattern: `ref y`
+
+error: the `z:` in this pattern is redundant
+  --> $DIR/lint-shorthand-field.rs:67:13
+   |
+LL |             z: ref mut z,
+   |             ^^^^^^^^^^^^ help: use shorthand field pattern: `ref mut z`
+
+error: aborting due to 5 previous errors
 
diff --git a/src/test/ui/lint/suggestions.rs b/src/test/ui/lint/suggestions.rs
index aa5518d1a7a..29297d08dca 100644
--- a/src/test/ui/lint/suggestions.rs
+++ b/src/test/ui/lint/suggestions.rs
@@ -60,7 +60,7 @@ fn main() {
         match d {
             Equinox { warp_factor: warp_factor } => {}
             //~^ WARN this pattern is redundant
-            //~| HELP remove this
+            //~| HELP use shorthand field pattern
         }
         println!("{} {}", registry_no, b);
     }
diff --git a/src/test/ui/lint/suggestions.stderr b/src/test/ui/lint/suggestions.stderr
index 2042ed75537..e42ee0fa640 100644
--- a/src/test/ui/lint/suggestions.stderr
+++ b/src/test/ui/lint/suggestions.stderr
@@ -77,9 +77,7 @@ warning: the `warp_factor:` in this pattern is redundant
   --> $DIR/suggestions.rs:61:23
    |
 LL |             Equinox { warp_factor: warp_factor } => {}
-   |                       ------------^^^^^^^^^^^^
-   |                       |
-   |                       help: remove this
+   |                       ^^^^^^^^^^^^^^^^^^^^^^^^ help: use shorthand field pattern: `warp_factor`
    |
    = note: `#[warn(non_shorthand_field_patterns)]` on by default