mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-04 04:39:16 +00:00
106 lines
2.7 KiB
Plaintext
106 lines
2.7 KiB
Plaintext
#![feature(prelude_import)]
|
|
#![no_std]
|
|
//@ compile-flags: -Zunpretty=expanded
|
|
//@ check-pass
|
|
|
|
// This test covers the AST pretty-printer's insertion of parentheses in some
|
|
// macro metavariable edge cases. Synthetic parentheses (i.e. not appearing in
|
|
// the syntax tree) need to be printed in order for the printed code to be valid
|
|
// Rust syntax. We also test negative cases: the pretty-printer should not be
|
|
// synthesizing parentheses indiscriminately; only where necessary.
|
|
|
|
#![feature(let_chains)]
|
|
#![feature(if_let_guard)]
|
|
#[prelude_import]
|
|
use ::std::prelude::rust_2015::*;
|
|
#[macro_use]
|
|
extern crate std;
|
|
|
|
macro_rules! expr { ($expr:expr) => { $expr }; }
|
|
|
|
macro_rules! stmt { ($stmt:stmt) => { $stmt }; }
|
|
|
|
fn break_labeled_loop() {
|
|
let no_paren =
|
|
'outer: loop { break 'outer 'inner: loop { break 'inner 1; } + 1; };
|
|
|
|
let paren_around_break_value =
|
|
'outer: loop { break ('inner: loop { break 'inner 1; } + 1); };
|
|
|
|
macro_rules! breaking { ($value:expr) => { break $value }; }
|
|
|
|
let paren_around_break_value =
|
|
loop { break ('inner: loop { break 'inner 1; } + 1); };
|
|
}
|
|
|
|
fn if_let() {
|
|
macro_rules! if_let {
|
|
($pat:pat, $expr:expr) => { if let $pat = $expr {} };
|
|
}
|
|
|
|
if let no_paren = true && false {}
|
|
if let paren_around_binary = (true && false) {};
|
|
if let no_paren = true {};
|
|
|
|
struct Struct {}
|
|
match () { _ if let no_paren = Struct {} => {} }
|
|
}
|
|
|
|
fn let_else() {
|
|
let no_paren = 1 + 1 else { return; };
|
|
let paren_around_loop = (loop {}) else { return; };
|
|
}
|
|
|
|
fn local() {
|
|
macro_rules! let_expr_minus_one {
|
|
($pat:pat, $expr:expr) => { let $pat = $expr - 1; };
|
|
}
|
|
|
|
let void;
|
|
let no_paren = match void {} - 1;
|
|
|
|
macro_rules! let_expr_else_return {
|
|
($pat:pat, $expr:expr) => { let $pat = $expr else { return; }; };
|
|
}
|
|
let
|
|
|
|
no_paren = void() else { return; };
|
|
}
|
|
|
|
fn match_arm() {
|
|
macro_rules! match_arm {
|
|
($pat:pat, $expr:expr) => { match () { $pat => $expr } };
|
|
}
|
|
match () {
|
|
|
|
|
|
no_paren => 1 - 1,
|
|
};
|
|
match () { paren_around_brace => ({ 1 }) - 1, };
|
|
}
|
|
|
|
/// https://github.com/rust-lang/rust/issues/98790
|
|
fn stmt_boundary() {
|
|
macro_rules! expr_as_stmt { ($expr:expr) => { stmt!($expr) }; }
|
|
|
|
let paren_around_match;
|
|
(match paren_around_match {}) | true;
|
|
|
|
macro_rules! minus_one { ($expr:expr) => { expr_as_stmt!($expr - 1) }; }
|
|
|
|
let (no_paren, paren_around_loop);
|
|
no_paren - 1;
|
|
(match paren_around_match {}) - 1;
|
|
(match paren_around_match {})() - 1;
|
|
(match paren_around_match {})[0] - 1;
|
|
(loop { break paren_around_loop; }) - 1;
|
|
}
|
|
|
|
fn vis_inherited() {
|
|
macro_rules! vis_inherited {
|
|
($vis:vis struct) => { $vis struct Struct; };
|
|
}
|
|
struct Struct;
|
|
|
|
}
|