Skip to content

Commit 1e329bf

Browse files
committed
don't expand subexprs of for loop, just re-expand whole thing.
Fixes #15167
1 parent d2adb7c commit 1e329bf

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,6 @@ pub fn expand_expr(e: Gc<ast::Expr>, fld: &mut MacroExpander) -> Gc<ast::Expr> {
132132
ast::ExprForLoop(src_pat, src_expr, src_loop_block, opt_ident) => {
133133
// Expand any interior macros etc.
134134
// NB: we don't fold pats yet. Curious.
135-
let src_expr = fld.fold_expr(src_expr).clone();
136-
let (src_loop_block, opt_ident) = expand_loop_block(src_loop_block, opt_ident, fld);
137135

138136
let span = e.span;
139137

@@ -143,7 +141,7 @@ pub fn expand_expr(e: Gc<ast::Expr>, fld: &mut MacroExpander) -> Gc<ast::Expr> {
143141
// i => {
144142
// ['<ident>:] loop {
145143
// match i.next() {
146-
// None => break,
144+
// None => break ['<ident>],
147145
// Some(mut value) => {
148146
// let <src_pat> = value;
149147
// <src_loop_block>
@@ -163,7 +161,7 @@ pub fn expand_expr(e: Gc<ast::Expr>, fld: &mut MacroExpander) -> Gc<ast::Expr> {
163161
let local_path = fld.cx.path_ident(span, local_ident);
164162
let some_path = fld.cx.path_ident(span, fld.cx.ident_of("Some"));
165163

166-
// `None => break ['<ident>];`
164+
// `None => break ['<ident>],`
167165
let none_arm = {
168166
let break_expr = fld.cx.expr(span, ast::ExprBreak(opt_ident));
169167
let none_pat = fld.cx.pat_ident(span, none_ident);
@@ -222,7 +220,9 @@ pub fn expand_expr(e: Gc<ast::Expr>, fld: &mut MacroExpander) -> Gc<ast::Expr> {
222220
let discrim = fld.cx.expr_mut_addr_of(span, src_expr);
223221
let i_pattern = fld.cx.pat_ident(span, local_ident);
224222
let arm = fld.cx.arm(span, vec!(i_pattern), loop_expr);
225-
fld.cx.expr_match(span, discrim, vec!(arm))
223+
// why these clone()'s everywhere? I guess I'll follow the pattern....
224+
let match_expr = fld.cx.expr_match(span, discrim, vec!(arm));
225+
fld.fold_expr(match_expr).clone()
226226
}
227227

228228
ast::ExprLoop(loop_block, opt_ident) => {
@@ -1248,6 +1248,7 @@ mod test {
12481248

12491249
// FIXME #9384, match variable hygiene. Should expand into
12501250
// fn z() {match 8 {x_1 => {match 9 {x_2 | x_2 => x_2 + x_1}}}}
1251+
#[ignore]
12511252
#[test] fn issue_9384(){
12521253
run_renaming_test(
12531254
&("macro_rules! bad_macro (($ex:expr) => ({match 9 {x | x => x + $ex}}))

0 commit comments

Comments
 (0)