Skip to content

Commit

Permalink
Allow $foo:block nonterminals in expression position
Browse files Browse the repository at this point in the history
Fixes #13678.
  • Loading branch information
lilyball committed May 26, 2014
1 parent 759517c commit ff0f9b6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/libsyntax/parse/parser.rs
Expand Up @@ -135,17 +135,21 @@ at INTERPOLATED tokens */
macro_rules! maybe_whole_expr (
($p:expr) => (
{
let mut maybe_path = match ($p).token {
INTERPOLATED(token::NtPath(ref pt)) => Some((**pt).clone()),
_ => None,
};
let found = match ($p).token {
let found = match $p.token {
INTERPOLATED(token::NtExpr(e)) => {
Some(e)
}
INTERPOLATED(token::NtPath(_)) => {
let pt = maybe_path.take_unwrap();
Some($p.mk_expr(($p).span.lo, ($p).span.hi, ExprPath(pt)))
// FIXME: The following avoids an issue with lexical borrowck scopes,
// but the clone is unfortunate.
let pt = match $p.token {
INTERPOLATED(token::NtPath(ref pt)) => (**pt).clone(),
_ => unreachable!()
};
Some($p.mk_expr($p.span.lo, $p.span.hi, ExprPath(pt)))
}
INTERPOLATED(token::NtBlock(b)) => {
Some($p.mk_expr($p.span.lo, $p.span.hi, ExprBlock(b)))
}
_ => None
};
Expand Down
21 changes: 21 additions & 0 deletions src/test/run-pass/macro-block-nonterminal.rs
@@ -0,0 +1,21 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

#![feature(macro_rules)]

macro_rules! do_block{
($val:block) => {$val}
}

fn main() {
let s;
do_block!({ s = "it works!"; });
assert_eq!(s, "it works!");
}

5 comments on commit ff0f9b6

@bors
Copy link
Contributor

@bors bors commented on ff0f9b6 May 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at lilyball@ff0f9b6

@bors
Copy link
Contributor

@bors bors commented on ff0f9b6 May 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging kballard/rust/nt_block = ff0f9b6 into auto

@bors
Copy link
Contributor

@bors bors commented on ff0f9b6 May 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kballard/rust/nt_block = ff0f9b6 merged ok, testing candidate = a7ab733

@bors
Copy link
Contributor

@bors bors commented on ff0f9b6 May 26, 2014

@bors
Copy link
Contributor

@bors bors commented on ff0f9b6 May 26, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = a7ab733

Please sign in to comment.