Store optional label in Expr::Block
diff --git a/src/expr.rs b/src/expr.rs
index 1f99ea2..60caae2 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -337,6 +337,7 @@
/// *This type is available if Syn is built with the `"full"` feature.*
pub Block(ExprBlock #full {
pub attrs: Vec<Attribute>,
+ pub label: Option<Label>,
pub block: Block,
}),
@@ -1627,8 +1628,6 @@
|
cond_reduce!(allow_block, syn!(ExprBlock)) => { Expr::Block }
|
- call!(unstable_labeled_block) => { Expr::Verbatim }
- |
// NOTE: This is the prefix-form of range
call!(expr_range, allow_struct)
|
@@ -1670,8 +1669,6 @@
syn!(ExprUnsafe) => { Expr::Unsafe }
|
syn!(ExprBlock) => { Expr::Block }
- |
- call!(unstable_labeled_block) => { Expr::Verbatim }
) >>
// If the next token is a `.` or a `?` it is special-cased to parse
// as an expression instead of a blockexpression.
@@ -1932,6 +1929,7 @@
else_block: braces!(Block::parse_within) >>
(Expr::Block(ExprBlock {
attrs: Vec::new(),
+ label: None,
block: Block {
brace_token: else_block.0,
stmts: else_block.1,
@@ -2125,6 +2123,7 @@
ReturnType::Type(arrow, Box::new(ty)),
Expr::Block(ExprBlock {
attrs: Vec::new(),
+ label: None,
block: body,
},
))
@@ -2435,6 +2434,7 @@
impl Synom for ExprBlock {
named!(parse -> Self, do_parse!(
outer_attrs: many0!(Attribute::parse_outer) >>
+ label: option!(syn!(Label)) >>
block: braces!(tuple!(
many0!(Attribute::parse_inner),
call!(Block::parse_within),
@@ -2445,6 +2445,7 @@
attrs.extend((block.1).0);
attrs
},
+ label: label,
block: Block {
brace_token: block.0,
stmts: (block.1).1,
@@ -2458,21 +2459,6 @@
}
#[cfg(feature = "full")]
- named!(unstable_labeled_block -> ExprVerbatim, do_parse!(
- begin: call!(verbatim::grab_cursor) >>
- many0!(Attribute::parse_outer) >>
- syn!(Label) >>
- braces!(tuple!(
- many0!(Attribute::parse_inner),
- call!(Block::parse_within),
- )) >>
- end: call!(verbatim::grab_cursor) >>
- (ExprVerbatim {
- tts: verbatim::token_range(begin..end),
- })
- ));
-
- #[cfg(feature = "full")]
named!(expr_range(allow_struct: bool) -> Expr, do_parse!(
limits: syn!(RangeLimits) >>
hi: opt_ambiguous_expr!(allow_struct) >>
@@ -3477,6 +3463,7 @@
impl ToTokens for ExprBlock {
fn to_tokens(&self, tokens: &mut TokenStream) {
outer_attrs_to_tokens(&self.attrs, tokens);
+ self.label.to_tokens(tokens);
self.block.brace_token.surround(tokens, |tokens| {
inner_attrs_to_tokens(&self.attrs, tokens);
tokens.append_all(&self.block.stmts);
diff --git a/src/gen/fold.rs b/src/gen/fold.rs
index b792053..8bfa9fe 100644
--- a/src/gen/fold.rs
+++ b/src/gen/fold.rs
@@ -1272,6 +1272,7 @@
pub fn fold_expr_block<V: Fold + ?Sized>(_visitor: &mut V, _i: ExprBlock) -> ExprBlock {
ExprBlock {
attrs: FoldHelper::lift(_i.attrs, |it| _visitor.fold_attribute(it)),
+ label: (_i.label).map(|it| _visitor.fold_label(it)),
block: _visitor.fold_block(_i.block),
}
}
diff --git a/src/gen/visit.rs b/src/gen/visit.rs
index 9145591..a21e108 100644
--- a/src/gen/visit.rs
+++ b/src/gen/visit.rs
@@ -1337,6 +1337,9 @@
for it in &_i.attrs {
_visitor.visit_attribute(it)
}
+ if let Some(ref it) = _i.label {
+ _visitor.visit_label(it)
+ };
_visitor.visit_block(&_i.block);
}
#[cfg(feature = "full")]
diff --git a/src/gen/visit_mut.rs b/src/gen/visit_mut.rs
index 428fd76..f1b3b1a 100644
--- a/src/gen/visit_mut.rs
+++ b/src/gen/visit_mut.rs
@@ -1332,6 +1332,9 @@
for it in &mut _i.attrs {
_visitor.visit_attribute_mut(it)
}
+ if let Some(ref mut it) = _i.label {
+ _visitor.visit_label_mut(it)
+ };
_visitor.visit_block_mut(&mut _i.block);
}
#[cfg(feature = "full")]
diff --git a/tests/test_asyncness.rs b/tests/test_asyncness.rs
index 9cb7300..b73537b 100644
--- a/tests/test_asyncness.rs
+++ b/tests/test_asyncness.rs
@@ -59,6 +59,7 @@
output: ReturnType::Default,
body: Box::new(Expr::Block(ExprBlock {
attrs: vec![],
+ label: None,
block: Block {
brace_token: Default::default(),
stmts: vec![],
diff --git a/tests/test_precedence.rs b/tests/test_precedence.rs
index dd8edea..a85bf27 100644
--- a/tests/test_precedence.rs
+++ b/tests/test_precedence.rs
@@ -228,12 +228,6 @@
impl Folder for BracketsFolder {
fn fold_expr(&mut self, e: P<Expr>) -> P<Expr> {
e.map(|e| match e.node {
- ExprKind::Block(_, label) if label.is_some() => Expr {
- id: ast::DUMMY_NODE_ID,
- node: ExprKind::Paren(P(e)),
- span: DUMMY_SP,
- attrs: ThinVec::new(),
- },
ExprKind::If(..) | ExprKind::Block(..) | ExprKind::IfLet(..) => {
fold::noop_fold_expr(e, self)
}