Skip to content

Commit a7ab733

Browse files
committed
auto merge of #14432 : kballard/rust/nt_block, r=huonw
Fixes #13678.
2 parents 20a4151 + ff0f9b6 commit a7ab733

File tree

2 files changed

+32
-7
lines changed

2 files changed

+32
-7
lines changed

src/libsyntax/parse/parser.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,21 @@ at INTERPOLATED tokens */
135135
macro_rules! maybe_whole_expr (
136136
($p:expr) => (
137137
{
138-
let mut maybe_path = match ($p).token {
139-
INTERPOLATED(token::NtPath(ref pt)) => Some((**pt).clone()),
140-
_ => None,
141-
};
142-
let found = match ($p).token {
138+
let found = match $p.token {
143139
INTERPOLATED(token::NtExpr(e)) => {
144140
Some(e)
145141
}
146142
INTERPOLATED(token::NtPath(_)) => {
147-
let pt = maybe_path.take_unwrap();
148-
Some($p.mk_expr(($p).span.lo, ($p).span.hi, ExprPath(pt)))
143+
// FIXME: The following avoids an issue with lexical borrowck scopes,
144+
// but the clone is unfortunate.
145+
let pt = match $p.token {
146+
INTERPOLATED(token::NtPath(ref pt)) => (**pt).clone(),
147+
_ => unreachable!()
148+
};
149+
Some($p.mk_expr($p.span.lo, $p.span.hi, ExprPath(pt)))
150+
}
151+
INTERPOLATED(token::NtBlock(b)) => {
152+
Some($p.mk_expr($p.span.lo, $p.span.hi, ExprBlock(b)))
149153
}
150154
_ => None
151155
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
#![feature(macro_rules)]
12+
13+
macro_rules! do_block{
14+
($val:block) => {$val}
15+
}
16+
17+
fn main() {
18+
let s;
19+
do_block!({ s = "it works!"; });
20+
assert_eq!(s, "it works!");
21+
}

0 commit comments

Comments
 (0)