Skip to content

Commit 5d38dc6

Browse files
committed
Don't recursively expand undefined macros
This led to infinite recursion when compiling a macro which inside used an undefined macro. Instead some dummy expression is returned for the result of expansion (rather than the macro itself). Closes rust-lang#11692
1 parent 4c967e7 commit 5d38dc6

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/libsyntax/ext/expand.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,11 @@ pub fn expand_expr(e: @ast::Expr, fld: &mut MacroExpander) -> @ast::Expr {
6464
extnamestr.get()));
6565

6666
// let compilation continue
67-
return e;
67+
return @ast::Expr {
68+
id: ast::DUMMY_NODE_ID,
69+
node: ast::ExprLogLevel,
70+
span: e.span,
71+
}
6872
}
6973
Some(&NormalTT(ref expandfun, exp_span)) => {
7074
fld.cx.bt_push(ExpnInfo {

src/test/compile-fail/issue-11692.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
fn main() {
12+
print!(test!());
13+
//~^ ERROR: macro undefined: 'test'
14+
//~^^ ERROR: macro undefined: 'test'
15+
//~^^^ ERROR: format argument must be a string literal
16+
17+
concat!(test!());
18+
//~^ ERROR: macro undefined: 'test'
19+
//~^^ ERROR: expected a literal
20+
}

0 commit comments

Comments
 (0)