-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #125051 - dtolnay:printletelse, r=compiler-errors
Pretty-print let-else with added parenthesization when needed Rustc used to produce invalid syntax for the following code, which is problematic because it means we cannot apply rustfmt to the output of `-Zunpretty=expanded`. ```rust macro_rules! expr { ($e:expr) => { $e }; } fn main() { let _ = expr!(loop {}) else { return; }; } ``` ```console $ rustc repro.rs -Zunpretty=expanded | rustfmt error: `loop...else` loops are not supported --> <stdin>:9:29 | 9 | fn main() { let _ = loop {} else { return; }; } | ---- ^^^^^^^^^^^^^^^^ | | | `else` is attached to this loop | = note: consider moving this `else` clause to a separate `if` statement and use a `bool` variable to control if it should run ```
- Loading branch information
Showing
6 changed files
with
46 additions
and
1 deletion.
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
File renamed without changes.
File renamed without changes.
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,11 @@ | ||
//@ compile-flags: -Zunpretty=expanded | ||
//@ check-pass | ||
|
||
macro_rules! expr { | ||
($e:expr) => { $e }; | ||
} | ||
|
||
fn main() { | ||
let _ = expr!(1 + 1) else { return; }; | ||
let _ = expr!(loop {}) else { return; }; | ||
} |
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,15 @@ | ||
#![feature(prelude_import)] | ||
#![no_std] | ||
#[prelude_import] | ||
use ::std::prelude::rust_2015::*; | ||
#[macro_use] | ||
extern crate std; | ||
//@ compile-flags: -Zunpretty=expanded | ||
//@ check-pass | ||
|
||
macro_rules! expr { ($e:expr) => { $e }; } | ||
|
||
fn main() { | ||
let _ = 1 + 1 else { return; }; | ||
let _ = (loop {}) else { return; }; | ||
} |