Add AST pretty-printer tests for let-else

This commit is contained in:
David Tolnay 2024-05-12 13:24:36 -07:00
parent 852a78ea8d
commit 68854b798e
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82
5 changed files with 41 additions and 0 deletions

View File

@ -675,6 +675,11 @@ fn test_stmt() {
"let (a, b): (u32, u32) = (1, 2);", "let (a, b): (u32, u32) = (1, 2);",
"let (a, b): (u32, u32) = (1, 2)" "let (a, b): (u32, u32) = (1, 2)"
); );
c2!(stmt,
[ let _ = f() else { return; } ],
"let _ = f() else { return; };",
"let _ = f() else { return; }",
);
macro_rules! c2_let_expr_minus_one { macro_rules! c2_let_expr_minus_one {
([ $expr:expr ], $stmt_expected:expr, $tokens_expected:expr $(,)?) => { ([ $expr:expr ], $stmt_expected:expr, $tokens_expected:expr $(,)?) => {
c2!(stmt, [ let _ = $expr - 1 ], $stmt_expected, $tokens_expected); c2!(stmt, [ let _ = $expr - 1 ], $stmt_expected, $tokens_expected);
@ -685,6 +690,16 @@ fn test_stmt() {
"let _ = match void {} - 1;", "let _ = match void {} - 1;",
"let _ = match void {} - 1", "let _ = match void {} - 1",
); );
macro_rules! c2_let_expr_else_return {
([ $expr:expr ], $stmt_expected:expr, $tokens_expected:expr $(,)?) => {
c2!(stmt, [ let _ = $expr else { return; } ], $stmt_expected, $tokens_expected);
};
}
c2_let_expr_else_return!(
[ f() ],
"let _ = f() else { return; };",
"let _ = f() else { return; }",
);
// StmtKind::Item // StmtKind::Item
c1!(stmt, [ struct S; ], "struct S;"); c1!(stmt, [ struct S; ], "struct S;");

View File

@ -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; };
}

View File

@ -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; };
}