about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorsjwang05 <63834813+sjwang05@users.noreply.github.com>2023-10-27 15:14:55 -0700
committersjwang05 <63834813+sjwang05@users.noreply.github.com>2023-12-26 20:59:14 -0800
commit97cf1c87bd98c13f4de91f7afbc971dba829ac92 (patch)
tree31444bc560707e904eb92f20262d97268664edc3 /tests
parented086d86b8b224f7df2da09cf48ac2a654bf841e (diff)
downloadrust-97cf1c87bd98c13f4de91f7afbc971dba829ac92.tar.gz
rust-97cf1c87bd98c13f4de91f7afbc971dba829ac92.zip
Suggest `=>` --> `>=` in conditions
Diffstat (limited to 'tests')
-rw-r--r--tests/ui/missing/missing-block-hint.stderr4
-rw-r--r--tests/ui/parser/eq-gt-to-gt-eq.fixed45
-rw-r--r--tests/ui/parser/eq-gt-to-gt-eq.rs45
-rw-r--r--tests/ui/parser/eq-gt-to-gt-eq.stderr106
4 files changed, 200 insertions, 0 deletions
diff --git a/tests/ui/missing/missing-block-hint.stderr b/tests/ui/missing/missing-block-hint.stderr
index 16954223a45..18719289abd 100644
--- a/tests/ui/missing/missing-block-hint.stderr
+++ b/tests/ui/missing/missing-block-hint.stderr
@@ -9,6 +9,10 @@ note: the `if` expression is missing a block after this condition
    |
 LL |         if (foo) => {}
    |            ^^^^^
+help: you might have meant to write a "greater than or equal to" comparison
+   |
+LL |         if (foo) >= {}
+   |                  ~~
 
 error: expected `{`, found `bar`
   --> $DIR/missing-block-hint.rs:7:13
diff --git a/tests/ui/parser/eq-gt-to-gt-eq.fixed b/tests/ui/parser/eq-gt-to-gt-eq.fixed
new file mode 100644
index 00000000000..44cb464fc0c
--- /dev/null
+++ b/tests/ui/parser/eq-gt-to-gt-eq.fixed
@@ -0,0 +1,45 @@
+// run-rustfix
+// Check that we try to correct `=>` to `>=` in conditions.
+#![allow(unused)]
+
+fn main() {
+    let a = 0;
+    let b = 1;
+    if a >= b {} //~ERROR
+}
+
+fn foo() {
+    let a = 0;
+    if a >= 1 {} //~ERROR
+}
+
+fn a() {
+    let a = 0;
+    if 1 >= a {} //~ERROR
+}
+
+fn bar() {
+    let a = 0;
+    let b = 1;
+    if a >= b && a != b {} //~ERROR
+}
+
+fn qux() {
+    let a = 0;
+    let b = 1;
+    if a != b && a >= b {} //~ERROR
+}
+
+fn baz() {
+    let a = 0;
+    let b = 1;
+    let _ = a >= b; //~ERROR
+}
+
+fn b() {
+    let a = 0;
+    let b = 1;
+    match a >= b { //~ERROR
+        _ => todo!(),
+    }
+}
diff --git a/tests/ui/parser/eq-gt-to-gt-eq.rs b/tests/ui/parser/eq-gt-to-gt-eq.rs
new file mode 100644
index 00000000000..dca67c89cc0
--- /dev/null
+++ b/tests/ui/parser/eq-gt-to-gt-eq.rs
@@ -0,0 +1,45 @@
+// run-rustfix
+// Check that we try to correct `=>` to `>=` in conditions.
+#![allow(unused)]
+
+fn main() {
+    let a = 0;
+    let b = 1;
+    if a => b {} //~ERROR
+}
+
+fn foo() {
+    let a = 0;
+    if a => 1 {} //~ERROR
+}
+
+fn a() {
+    let a = 0;
+    if 1 => a {} //~ERROR
+}
+
+fn bar() {
+    let a = 0;
+    let b = 1;
+    if a => b && a != b {} //~ERROR
+}
+
+fn qux() {
+    let a = 0;
+    let b = 1;
+    if a != b && a => b {} //~ERROR
+}
+
+fn baz() {
+    let a = 0;
+    let b = 1;
+    let _ = a => b; //~ERROR
+}
+
+fn b() {
+    let a = 0;
+    let b = 1;
+    match a => b { //~ERROR
+        _ => todo!(),
+    }
+}
diff --git a/tests/ui/parser/eq-gt-to-gt-eq.stderr b/tests/ui/parser/eq-gt-to-gt-eq.stderr
new file mode 100644
index 00000000000..73f465f7b9b
--- /dev/null
+++ b/tests/ui/parser/eq-gt-to-gt-eq.stderr
@@ -0,0 +1,106 @@
+error: expected `{`, found `=>`
+  --> $DIR/eq-gt-to-gt-eq.rs:8:10
+   |
+LL |     if a => b {}
+   |          ^^ expected `{`
+   |
+note: the `if` expression is missing a block after this condition
+  --> $DIR/eq-gt-to-gt-eq.rs:8:8
+   |
+LL |     if a => b {}
+   |        ^
+help: you might have meant to write a "greater than or equal to" comparison
+   |
+LL |     if a >= b {}
+   |          ~~
+
+error: expected `{`, found `=>`
+  --> $DIR/eq-gt-to-gt-eq.rs:13:10
+   |
+LL |     if a => 1 {}
+   |          ^^ expected `{`
+   |
+note: the `if` expression is missing a block after this condition
+  --> $DIR/eq-gt-to-gt-eq.rs:13:8
+   |
+LL |     if a => 1 {}
+   |        ^
+help: you might have meant to write a "greater than or equal to" comparison
+   |
+LL |     if a >= 1 {}
+   |          ~~
+
+error: expected `{`, found `=>`
+  --> $DIR/eq-gt-to-gt-eq.rs:18:10
+   |
+LL |     if 1 => a {}
+   |          ^^ expected `{`
+   |
+note: the `if` expression is missing a block after this condition
+  --> $DIR/eq-gt-to-gt-eq.rs:18:8
+   |
+LL |     if 1 => a {}
+   |        ^
+help: you might have meant to write a "greater than or equal to" comparison
+   |
+LL |     if 1 >= a {}
+   |          ~~
+
+error: expected `{`, found `=>`
+  --> $DIR/eq-gt-to-gt-eq.rs:24:10
+   |
+LL |     if a => b && a != b {}
+   |          ^^ expected `{`
+   |
+note: the `if` expression is missing a block after this condition
+  --> $DIR/eq-gt-to-gt-eq.rs:24:8
+   |
+LL |     if a => b && a != b {}
+   |        ^
+help: you might have meant to write a "greater than or equal to" comparison
+   |
+LL |     if a >= b && a != b {}
+   |          ~~
+
+error: expected `{`, found `=>`
+  --> $DIR/eq-gt-to-gt-eq.rs:30:20
+   |
+LL |     if a != b && a => b {}
+   |                    ^^ expected `{`
+   |
+note: the `if` expression is missing a block after this condition
+  --> $DIR/eq-gt-to-gt-eq.rs:30:8
+   |
+LL |     if a != b && a => b {}
+   |        ^^^^^^^^^^^
+help: you might have meant to write a "greater than or equal to" comparison
+   |
+LL |     if a != b && a >= b {}
+   |                    ~~
+
+error: expected one of `!`, `.`, `::`, `;`, `?`, `else`, `{`, or an operator, found `=>`
+  --> $DIR/eq-gt-to-gt-eq.rs:36:15
+   |
+LL |     let _ = a => b;
+   |               ^^ expected one of 8 possible tokens
+   |
+help: you might have meant to write a "greater than or equal to" comparison
+   |
+LL |     let _ = a >= b;
+   |               ~~
+
+error: expected one of `!`, `.`, `::`, `?`, `{`, or an operator, found `=>`
+  --> $DIR/eq-gt-to-gt-eq.rs:42:13
+   |
+LL |     match a => b {
+   |     -----   ^^ expected one of `!`, `.`, `::`, `?`, `{`, or an operator
+   |     |
+   |     while parsing this `match` expression
+   |
+help: you might have meant to write a "greater than or equal to" comparison
+   |
+LL |     match a >= b {
+   |             ~~
+
+error: aborting due to 7 previous errors
+