forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#60188 - estebank:recover-block, r=varkor
Identify when a stmt could have been parsed as an expr There are some expressions that can be parsed as a statement without a trailing semicolon depending on the context, which can lead to confusing errors due to the same looking code being accepted in some places and not others. Identify these cases and suggest enclosing in parenthesis making the parse non-ambiguous without changing the accepted grammar. Fix rust-lang#54186, cc rust-lang#54482, fix rust-lang#59975, fix rust-lang#47287.
- Loading branch information
Showing
17 changed files
with
312 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// run-rustfix | ||
#![allow(unused_variables)] | ||
#![allow(dead_code)] | ||
#![allow(unused_must_use)] | ||
|
||
fn foo() -> i32 { | ||
({2}) + {2} //~ ERROR expected expression, found `+` | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn bar() -> i32 { | ||
({2}) + 2 //~ ERROR expected expression, found `+` | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn zul() -> u32 { | ||
let foo = 3; | ||
({ 42 }) + foo; //~ ERROR expected expression, found `+` | ||
//~^ ERROR mismatched types | ||
32 | ||
} | ||
|
||
fn baz() -> i32 { | ||
({ 3 }) * 3 //~ ERROR type `{integer}` cannot be dereferenced | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn qux(a: Option<u32>, b: Option<u32>) -> bool { | ||
(if let Some(x) = a { true } else { false }) | ||
&& //~ ERROR expected expression | ||
if let Some(y) = a { true } else { false } | ||
} | ||
|
||
fn moo(x: u32) -> bool { | ||
(match x { | ||
_ => 1, | ||
}) > 0 //~ ERROR expected expression | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// run-rustfix | ||
#![allow(unused_variables)] | ||
#![allow(dead_code)] | ||
#![allow(unused_must_use)] | ||
|
||
fn foo() -> i32 { | ||
{2} + {2} //~ ERROR expected expression, found `+` | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn bar() -> i32 { | ||
{2} + 2 //~ ERROR expected expression, found `+` | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn zul() -> u32 { | ||
let foo = 3; | ||
{ 42 } + foo; //~ ERROR expected expression, found `+` | ||
//~^ ERROR mismatched types | ||
32 | ||
} | ||
|
||
fn baz() -> i32 { | ||
{ 3 } * 3 //~ ERROR type `{integer}` cannot be dereferenced | ||
//~^ ERROR mismatched types | ||
} | ||
|
||
fn qux(a: Option<u32>, b: Option<u32>) -> bool { | ||
if let Some(x) = a { true } else { false } | ||
&& //~ ERROR expected expression | ||
if let Some(y) = a { true } else { false } | ||
} | ||
|
||
fn moo(x: u32) -> bool { | ||
match x { | ||
_ => 1, | ||
} > 0 //~ ERROR expected expression | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.