about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/test/ui/lint/unused_parens_json_suggestion.fixed27
-rw-r--r--src/test/ui/lint/unused_parens_json_suggestion.rs2
-rw-r--r--src/test/ui/lint/unused_parens_json_suggestion.stderr28
-rw-r--r--src/test/ui/lint/unused_parens_remove_json_suggestion.fixed62
-rw-r--r--src/test/ui/lint/unused_parens_remove_json_suggestion.rs (renamed from src/test/ui/lint/used_parens_remove_json_suggestion.rs)6
-rw-r--r--src/test/ui/lint/unused_parens_remove_json_suggestion.stderr (renamed from src/test/ui/lint/used_parens_remove_json_suggestion.stderr)222
6 files changed, 220 insertions, 127 deletions
diff --git a/src/test/ui/lint/unused_parens_json_suggestion.fixed b/src/test/ui/lint/unused_parens_json_suggestion.fixed
new file mode 100644
index 00000000000..42740711910
--- /dev/null
+++ b/src/test/ui/lint/unused_parens_json_suggestion.fixed
@@ -0,0 +1,27 @@
+// compile-flags: --error-format pretty-json -Zunstable-options
+// build-pass (FIXME(62277): could be check-pass?)
+// run-rustfix
+
+// The output for humans should just highlight the whole span without showing
+// the suggested replacement, but we also want to test that suggested
+// replacement only removes one set of parentheses, rather than naïvely
+// stripping away any starting or ending parenthesis characters—hence this
+// test of the JSON error format.
+
+#![warn(unused_parens)]
+#![allow(unreachable_code)]
+
+fn main() {
+    // We want to suggest the properly-balanced expression `1 / (2 + 3)`, not
+    // the malformed `1 / (2 + 3`
+    let _a = 1 / (2 + 3);
+    f();
+}
+
+fn f() -> bool {
+    loop {
+        if (break { return true }) {
+        }
+    }
+    false
+}
diff --git a/src/test/ui/lint/unused_parens_json_suggestion.rs b/src/test/ui/lint/unused_parens_json_suggestion.rs
index 185bfacea80..87192503986 100644
--- a/src/test/ui/lint/unused_parens_json_suggestion.rs
+++ b/src/test/ui/lint/unused_parens_json_suggestion.rs
@@ -1,5 +1,6 @@
 // compile-flags: --error-format pretty-json -Zunstable-options
 // build-pass (FIXME(62277): could be check-pass?)
+// run-rustfix
 
 // The output for humans should just highlight the whole span without showing
 // the suggested replacement, but we also want to test that suggested
@@ -8,6 +9,7 @@
 // test of the JSON error format.
 
 #![warn(unused_parens)]
+#![allow(unreachable_code)]
 
 fn main() {
     // We want to suggest the properly-balanced expression `1 / (2 + 3)`, not
diff --git a/src/test/ui/lint/unused_parens_json_suggestion.stderr b/src/test/ui/lint/unused_parens_json_suggestion.stderr
index 396395a17f7..256c7555c90 100644
--- a/src/test/ui/lint/unused_parens_json_suggestion.stderr
+++ b/src/test/ui/lint/unused_parens_json_suggestion.stderr
@@ -8,10 +8,10 @@
   "spans": [
     {
       "file_name": "$DIR/unused_parens_json_suggestion.rs",
-      "byte_start": 611,
-      "byte_end": 624,
-      "line_start": 15,
-      "line_end": 15,
+      "byte_start": 654,
+      "byte_end": 667,
+      "line_start": 17,
+      "line_end": 17,
       "column_start": 14,
       "column_end": 27,
       "is_primary": true,
@@ -36,10 +36,10 @@
       "spans": [
         {
           "file_name": "$DIR/unused_parens_json_suggestion.rs",
-          "byte_start": 457,
-          "byte_end": 470,
-          "line_start": 10,
-          "line_end": 10,
+          "byte_start": 472,
+          "byte_end": 485,
+          "line_start": 11,
+          "line_end": 11,
           "column_start": 9,
           "column_end": 22,
           "is_primary": true,
@@ -66,10 +66,10 @@
       "spans": [
         {
           "file_name": "$DIR/unused_parens_json_suggestion.rs",
-          "byte_start": 611,
-          "byte_end": 624,
-          "line_start": 15,
-          "line_end": 15,
+          "byte_start": 654,
+          "byte_end": 667,
+          "line_start": 17,
+          "line_end": 17,
           "column_start": 14,
           "column_end": 27,
           "is_primary": true,
@@ -91,13 +91,13 @@
     }
   ],
   "rendered": "warning: unnecessary parentheses around assigned value
-  --> $DIR/unused_parens_json_suggestion.rs:15:14
+  --> $DIR/unused_parens_json_suggestion.rs:17:14
    |
 LL |     let _a = (1 / (2 + 3));
    |              ^^^^^^^^^^^^^ help: remove these parentheses
    |
 note: lint level defined here
-  --> $DIR/unused_parens_json_suggestion.rs:10:9
+  --> $DIR/unused_parens_json_suggestion.rs:11:9
    |
 LL | #![warn(unused_parens)]
    |         ^^^^^^^^^^^^^
diff --git a/src/test/ui/lint/unused_parens_remove_json_suggestion.fixed b/src/test/ui/lint/unused_parens_remove_json_suggestion.fixed
new file mode 100644
index 00000000000..2459eb1ac5c
--- /dev/null
+++ b/src/test/ui/lint/unused_parens_remove_json_suggestion.fixed
@@ -0,0 +1,62 @@
+// compile-flags: --error-format pretty-json -Zunstable-options
+// build-pass
+// run-rustfix
+
+// The output for humans should just highlight the whole span without showing
+// the suggested replacement, but we also want to test that suggested
+// replacement only removes one set of parentheses, rather than naïvely
+// stripping away any starting or ending parenthesis characters—hence this
+// test of the JSON error format.
+
+#![warn(unused_parens)]
+#![allow(unreachable_code)]
+
+fn main() {
+
+    let _b = false;
+
+    if _b {
+        println!("hello");
+    }
+
+    f();
+
+}
+
+fn f() -> bool {
+    let c = false;
+
+    if c {
+        println!("next");
+    }
+
+    if c {
+        println!("prev");
+    }
+
+    while false && true {
+        if c {
+            println!("norm");
+        }
+
+    }
+
+    while true && false {
+        for _ in 0 .. 3 {
+            println!("e~")
+        }
+    }
+
+    for _ in 0 .. 3 {
+        while true && false {
+            println!("e~")
+        }
+    }
+
+
+    loop {
+        if (break { return true }) {
+        }
+    }
+    false
+}
diff --git a/src/test/ui/lint/used_parens_remove_json_suggestion.rs b/src/test/ui/lint/unused_parens_remove_json_suggestion.rs
index 3af11428b95..0e9869b67d5 100644
--- a/src/test/ui/lint/used_parens_remove_json_suggestion.rs
+++ b/src/test/ui/lint/unused_parens_remove_json_suggestion.rs
@@ -1,5 +1,6 @@
 // compile-flags: --error-format pretty-json -Zunstable-options
 // build-pass
+// run-rustfix
 
 // The output for humans should just highlight the whole span without showing
 // the suggested replacement, but we also want to test that suggested
@@ -8,6 +9,7 @@
 // test of the JSON error format.
 
 #![warn(unused_parens)]
+#![allow(unreachable_code)]
 
 fn main() {
 
@@ -40,12 +42,12 @@ fn f() -> bool {
     }
 
     while(true && false) {
-        for i in (0 .. 3){
+        for _ in (0 .. 3){
             println!("e~")
         }
     }
 
-    for i in (0 .. 3) {
+    for _ in (0 .. 3) {
         while (true && false) {
             println!("e~")
         }
diff --git a/src/test/ui/lint/used_parens_remove_json_suggestion.stderr b/src/test/ui/lint/unused_parens_remove_json_suggestion.stderr
index d8b23ae5443..b4eab200dd0 100644
--- a/src/test/ui/lint/used_parens_remove_json_suggestion.stderr
+++ b/src/test/ui/lint/unused_parens_remove_json_suggestion.stderr
@@ -7,11 +7,11 @@
   "level": "warning",
   "spans": [
     {
-      "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-      "byte_start": 478,
-      "byte_end": 482,
-      "line_start": 16,
-      "line_end": 16,
+      "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+      "byte_start": 521,
+      "byte_end": 525,
+      "line_start": 18,
+      "line_end": 18,
       "column_start": 8,
       "column_end": 12,
       "is_primary": true,
@@ -35,11 +35,11 @@
       "level": "note",
       "spans": [
         {
-          "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-          "byte_start": 420,
-          "byte_end": 433,
-          "line_start": 10,
-          "line_end": 10,
+          "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+          "byte_start": 435,
+          "byte_end": 448,
+          "line_start": 11,
+          "line_end": 11,
           "column_start": 9,
           "column_end": 22,
           "is_primary": true,
@@ -65,11 +65,11 @@
       "level": "help",
       "spans": [
         {
-          "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-          "byte_start": 478,
-          "byte_end": 482,
-          "line_start": 16,
-          "line_end": 16,
+          "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+          "byte_start": 521,
+          "byte_end": 525,
+          "line_start": 18,
+          "line_end": 18,
           "column_start": 8,
           "column_end": 12,
           "is_primary": true,
@@ -91,13 +91,13 @@
     }
   ],
   "rendered": "warning: unnecessary parentheses around `if` condition
-  --> $DIR/used_parens_remove_json_suggestion.rs:16:8
+  --> $DIR/unused_parens_remove_json_suggestion.rs:18:8
    |
 LL |     if (_b) {
    |        ^^^^ help: remove these parentheses
    |
 note: lint level defined here
-  --> $DIR/used_parens_remove_json_suggestion.rs:10:9
+  --> $DIR/unused_parens_remove_json_suggestion.rs:11:9
    |
 LL | #![warn(unused_parens)]
    |         ^^^^^^^^^^^^^
@@ -113,11 +113,11 @@ LL | #![warn(unused_parens)]
   "level": "warning",
   "spans": [
     {
-      "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-      "byte_start": 575,
-      "byte_end": 578,
-      "line_start": 27,
-      "line_end": 27,
+      "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+      "byte_start": 618,
+      "byte_end": 621,
+      "line_start": 29,
+      "line_end": 29,
       "column_start": 7,
       "column_end": 10,
       "is_primary": true,
@@ -141,11 +141,11 @@ LL | #![warn(unused_parens)]
       "level": "help",
       "spans": [
         {
-          "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-          "byte_start": 575,
-          "byte_end": 578,
-          "line_start": 27,
-          "line_end": 27,
+          "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+          "byte_start": 618,
+          "byte_end": 621,
+          "line_start": 29,
+          "line_end": 29,
           "column_start": 7,
           "column_end": 10,
           "is_primary": true,
@@ -167,7 +167,7 @@ LL | #![warn(unused_parens)]
     }
   ],
   "rendered": "warning: unnecessary parentheses around `if` condition
-  --> $DIR/used_parens_remove_json_suggestion.rs:27:7
+  --> $DIR/unused_parens_remove_json_suggestion.rs:29:7
    |
 LL |     if(c) {
    |       ^^^ help: remove these parentheses
@@ -183,11 +183,11 @@ LL |     if(c) {
   "level": "warning",
   "spans": [
     {
-      "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-      "byte_start": 621,
-      "byte_end": 624,
-      "line_start": 31,
-      "line_end": 31,
+      "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+      "byte_start": 664,
+      "byte_end": 667,
+      "line_start": 33,
+      "line_end": 33,
       "column_start": 8,
       "column_end": 11,
       "is_primary": true,
@@ -211,11 +211,11 @@ LL |     if(c) {
       "level": "help",
       "spans": [
         {
-          "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-          "byte_start": 621,
-          "byte_end": 624,
-          "line_start": 31,
-          "line_end": 31,
+          "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+          "byte_start": 664,
+          "byte_end": 667,
+          "line_start": 33,
+          "line_end": 33,
           "column_start": 8,
           "column_end": 11,
           "is_primary": true,
@@ -237,7 +237,7 @@ LL |     if(c) {
     }
   ],
   "rendered": "warning: unnecessary parentheses around `if` condition
-  --> $DIR/used_parens_remove_json_suggestion.rs:31:8
+  --> $DIR/unused_parens_remove_json_suggestion.rs:33:8
    |
 LL |     if (c){
    |        ^^^ help: remove these parentheses
@@ -253,11 +253,11 @@ LL |     if (c){
   "level": "warning",
   "spans": [
     {
-      "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-      "byte_start": 669,
-      "byte_end": 684,
-      "line_start": 35,
-      "line_end": 35,
+      "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+      "byte_start": 712,
+      "byte_end": 727,
+      "line_start": 37,
+      "line_end": 37,
       "column_start": 11,
       "column_end": 26,
       "is_primary": true,
@@ -281,11 +281,11 @@ LL |     if (c){
       "level": "help",
       "spans": [
         {
-          "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-          "byte_start": 669,
-          "byte_end": 684,
-          "line_start": 35,
-          "line_end": 35,
+          "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+          "byte_start": 712,
+          "byte_end": 727,
+          "line_start": 37,
+          "line_end": 37,
           "column_start": 11,
           "column_end": 26,
           "is_primary": true,
@@ -307,7 +307,7 @@ LL |     if (c){
     }
   ],
   "rendered": "warning: unnecessary parentheses around `while` condition
-  --> $DIR/used_parens_remove_json_suggestion.rs:35:11
+  --> $DIR/unused_parens_remove_json_suggestion.rs:37:11
    |
 LL |     while (false && true){
    |           ^^^^^^^^^^^^^^^ help: remove these parentheses
@@ -323,11 +323,11 @@ LL |     while (false && true){
   "level": "warning",
   "spans": [
     {
-      "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-      "byte_start": 697,
-      "byte_end": 700,
-      "line_start": 36,
-      "line_end": 36,
+      "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+      "byte_start": 740,
+      "byte_end": 743,
+      "line_start": 38,
+      "line_end": 38,
       "column_start": 12,
       "column_end": 15,
       "is_primary": true,
@@ -351,11 +351,11 @@ LL |     while (false && true){
       "level": "help",
       "spans": [
         {
-          "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-          "byte_start": 697,
-          "byte_end": 700,
-          "line_start": 36,
-          "line_end": 36,
+          "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+          "byte_start": 740,
+          "byte_end": 743,
+          "line_start": 38,
+          "line_end": 38,
           "column_start": 12,
           "column_end": 15,
           "is_primary": true,
@@ -377,7 +377,7 @@ LL |     while (false && true){
     }
   ],
   "rendered": "warning: unnecessary parentheses around `if` condition
-  --> $DIR/used_parens_remove_json_suggestion.rs:36:12
+  --> $DIR/unused_parens_remove_json_suggestion.rs:38:12
    |
 LL |         if (c) {
    |            ^^^ help: remove these parentheses
@@ -393,11 +393,11 @@ LL |         if (c) {
   "level": "warning",
   "spans": [
     {
-      "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-      "byte_start": 760,
-      "byte_end": 775,
-      "line_start": 42,
-      "line_end": 42,
+      "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+      "byte_start": 803,
+      "byte_end": 818,
+      "line_start": 44,
+      "line_end": 44,
       "column_start": 10,
       "column_end": 25,
       "is_primary": true,
@@ -421,11 +421,11 @@ LL |         if (c) {
       "level": "help",
       "spans": [
         {
-          "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-          "byte_start": 760,
-          "byte_end": 775,
-          "line_start": 42,
-          "line_end": 42,
+          "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+          "byte_start": 803,
+          "byte_end": 818,
+          "line_start": 44,
+          "line_end": 44,
           "column_start": 10,
           "column_end": 25,
           "is_primary": true,
@@ -447,7 +447,7 @@ LL |         if (c) {
     }
   ],
   "rendered": "warning: unnecessary parentheses around `while` condition
-  --> $DIR/used_parens_remove_json_suggestion.rs:42:10
+  --> $DIR/unused_parens_remove_json_suggestion.rs:44:10
    |
 LL |     while(true && false) {
    |          ^^^^^^^^^^^^^^^ help: remove these parentheses
@@ -463,17 +463,17 @@ LL |     while(true && false) {
   "level": "warning",
   "spans": [
     {
-      "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-      "byte_start": 795,
-      "byte_end": 803,
-      "line_start": 43,
-      "line_end": 43,
+      "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+      "byte_start": 838,
+      "byte_end": 846,
+      "line_start": 45,
+      "line_end": 45,
       "column_start": 18,
       "column_end": 26,
       "is_primary": true,
       "text": [
         {
-          "text": "        for i in (0 .. 3){",
+          "text": "        for _ in (0 .. 3){",
           "highlight_start": 18,
           "highlight_end": 26
         }
@@ -491,17 +491,17 @@ LL |     while(true && false) {
       "level": "help",
       "spans": [
         {
-          "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-          "byte_start": 795,
-          "byte_end": 803,
-          "line_start": 43,
-          "line_end": 43,
+          "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+          "byte_start": 838,
+          "byte_end": 846,
+          "line_start": 45,
+          "line_end": 45,
           "column_start": 18,
           "column_end": 26,
           "is_primary": true,
           "text": [
             {
-              "text": "        for i in (0 .. 3){",
+              "text": "        for _ in (0 .. 3){",
               "highlight_start": 18,
               "highlight_end": 26
             }
@@ -517,9 +517,9 @@ LL |     while(true && false) {
     }
   ],
   "rendered": "warning: unnecessary parentheses around `for` head expression
-  --> $DIR/used_parens_remove_json_suggestion.rs:43:18
+  --> $DIR/unused_parens_remove_json_suggestion.rs:45:18
    |
-LL |         for i in (0 .. 3){
+LL |         for _ in (0 .. 3){
    |                  ^^^^^^^^ help: remove these parentheses
 
 "
@@ -533,17 +533,17 @@ LL |         for i in (0 .. 3){
   "level": "warning",
   "spans": [
     {
-      "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-      "byte_start": 862,
-      "byte_end": 870,
-      "line_start": 48,
-      "line_end": 48,
+      "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+      "byte_start": 905,
+      "byte_end": 913,
+      "line_start": 50,
+      "line_end": 50,
       "column_start": 14,
       "column_end": 22,
       "is_primary": true,
       "text": [
         {
-          "text": "    for i in (0 .. 3) {",
+          "text": "    for _ in (0 .. 3) {",
           "highlight_start": 14,
           "highlight_end": 22
         }
@@ -561,17 +561,17 @@ LL |         for i in (0 .. 3){
       "level": "help",
       "spans": [
         {
-          "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-          "byte_start": 862,
-          "byte_end": 870,
-          "line_start": 48,
-          "line_end": 48,
+          "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+          "byte_start": 905,
+          "byte_end": 913,
+          "line_start": 50,
+          "line_end": 50,
           "column_start": 14,
           "column_end": 22,
           "is_primary": true,
           "text": [
             {
-              "text": "    for i in (0 .. 3) {",
+              "text": "    for _ in (0 .. 3) {",
               "highlight_start": 14,
               "highlight_end": 22
             }
@@ -587,9 +587,9 @@ LL |         for i in (0 .. 3){
     }
   ],
   "rendered": "warning: unnecessary parentheses around `for` head expression
-  --> $DIR/used_parens_remove_json_suggestion.rs:48:14
+  --> $DIR/unused_parens_remove_json_suggestion.rs:50:14
    |
-LL |     for i in (0 .. 3) {
+LL |     for _ in (0 .. 3) {
    |              ^^^^^^^^ help: remove these parentheses
 
 "
@@ -603,11 +603,11 @@ LL |     for i in (0 .. 3) {
   "level": "warning",
   "spans": [
     {
-      "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-      "byte_start": 887,
-      "byte_end": 902,
-      "line_start": 49,
-      "line_end": 49,
+      "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+      "byte_start": 930,
+      "byte_end": 945,
+      "line_start": 51,
+      "line_end": 51,
       "column_start": 15,
       "column_end": 30,
       "is_primary": true,
@@ -631,11 +631,11 @@ LL |     for i in (0 .. 3) {
       "level": "help",
       "spans": [
         {
-          "file_name": "$DIR/used_parens_remove_json_suggestion.rs",
-          "byte_start": 887,
-          "byte_end": 902,
-          "line_start": 49,
-          "line_end": 49,
+          "file_name": "$DIR/unused_parens_remove_json_suggestion.rs",
+          "byte_start": 930,
+          "byte_end": 945,
+          "line_start": 51,
+          "line_end": 51,
           "column_start": 15,
           "column_end": 30,
           "is_primary": true,
@@ -657,7 +657,7 @@ LL |     for i in (0 .. 3) {
     }
   ],
   "rendered": "warning: unnecessary parentheses around `while` condition
-  --> $DIR/used_parens_remove_json_suggestion.rs:49:15
+  --> $DIR/unused_parens_remove_json_suggestion.rs:51:15
    |
 LL |         while (true && false) {
    |               ^^^^^^^^^^^^^^^ help: remove these parentheses