File tree 3 files changed +67
-4
lines changed
compiler/rustc_parse/src/parser
3 files changed +67
-4
lines changed Original file line number Diff line number Diff line change @@ -2425,6 +2425,7 @@ impl<'a> Parser<'a> {
2425
2425
}
2426
2426
} else {
2427
2427
let attrs = self . parse_outer_attributes ( ) ?; // For recovery.
2428
+ let maybe_fatarrow = self . token . clone ( ) ;
2428
2429
let block = if self . check ( & token:: OpenDelim ( Delimiter :: Brace ) ) {
2429
2430
self . parse_block ( ) ?
2430
2431
} else {
@@ -2434,10 +2435,20 @@ impl<'a> Parser<'a> {
2434
2435
self . error_on_extra_if ( & cond) ?;
2435
2436
// Parse block, which will always fail, but we can add a nice note to the error
2436
2437
self . parse_block ( ) . map_err ( |mut err| {
2437
- err. span_note (
2438
- cond_span,
2439
- "the `if` expression is missing a block after this condition" ,
2440
- ) ;
2438
+ // Look for usages of '=>' where '>=' was probably intended.
2439
+ if maybe_fatarrow. kind == token:: FatArrow {
2440
+ err. span_suggestion (
2441
+ maybe_fatarrow. span ,
2442
+ "you probably meant to write a \" greater than or equal to\" comparison" ,
2443
+ ">=" ,
2444
+ Applicability :: MachineApplicable ,
2445
+ ) ;
2446
+ } else {
2447
+ err. span_note (
2448
+ cond_span,
2449
+ "the `if` expression is missing a block after this condition" ,
2450
+ ) ;
2451
+ }
2441
2452
err
2442
2453
} ) ?
2443
2454
}
Original file line number Diff line number Diff line change
1
+ // Check that we try to correct `=>` to `>=` in conditions.
2
+
3
+ fn foo ( ) {
4
+ let a = 0 ;
5
+ let b = 4 ;
6
+ if a => b { //~ERROR
7
+ println ! ( "yay!" ) ;
8
+ }
9
+ }
10
+
11
+ fn bar ( ) {
12
+ let a = 0 ;
13
+ let b = 4 ;
14
+ if a = >b { //~ERROR
15
+ println ! ( "yay!" ) ;
16
+ }
17
+ }
18
+
19
+ fn baz ( ) {
20
+ let a = 0 ;
21
+ let b = 4 ;
22
+ if a = > b { //~ERROR
23
+ println ! ( "yay!" ) ;
24
+ }
25
+ }
26
+
27
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: expected `{`, found `=>`
2
+ --> $DIR/eq-gt-to-gt-eq.rs:6:10
3
+ |
4
+ LL | if a => b {
5
+ | ^^ expected `{`
6
+ |
7
+ help: you probably meant to write a "greater than or equal to" comparison
8
+ |
9
+ LL | if a >= b {
10
+ | ~~
11
+
12
+ error: expected expression, found `>`
13
+ --> $DIR/eq-gt-to-gt-eq.rs:14:12
14
+ |
15
+ LL | if a = >b {
16
+ | ^ expected expression
17
+
18
+ error: expected expression, found `>`
19
+ --> $DIR/eq-gt-to-gt-eq.rs:22:12
20
+ |
21
+ LL | if a = > b {
22
+ | ^ expected expression
23
+
24
+ error: aborting due to 3 previous errors
25
+
You can’t perform that action at this time.
0 commit comments