Skip to content

Commit a803a14

Browse files
kevinanikomatsakis
authored andcommitted
Bug fix to accept $ in 0th pos, (ie #ast{$(x) + ...}).
Note: part from Niko Matsakis commit: rewrite assert to accept a $ in 0th pos.
1 parent 3eef8d1 commit a803a14

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

src/comp/syntax/ext/qquote.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,12 @@ fn finish<T: qq_helper>
184184
let sp = node.span();
185185
let qcx = gather_anti_quotes(sp.lo, node);
186186
let cx = qcx;
187-
let prev = 0u;
188-
for {lo: lo, _} in cx.gather {
189-
assert lo > prev;
190-
prev = lo;
187+
188+
// assert that the vector is sorted by position:
189+
uint::range(1u, vec::len(cx.gather)) {|i|
190+
assert cx.gather[i-1u].lo < cx.gather[i].lo;
191191
}
192+
192193
let str2 = "";
193194
enum state {active, skip(uint), blank};
194195
let state = active;

src/test/run-pass/qquote.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ fn main() {
8181
let x = #ast{1};
8282
let test1 = #ast{1+$(x)};
8383
check_pp(test1, pprust::print_expr, "1 + 1");
84+
85+
let test2 = #ast{$(x)+1};
86+
check_pp(test2, pprust::print_expr, "1 + 1");
87+
88+
let y = #ast{2};
89+
let test3 = #ast{$(x) + $(y)};
90+
check_pp(test3, pprust::print_expr, "1 + 2");
8491
}
8592

8693
fn check_pp<T>(expr: T, f: fn(pprust::ps, T), expect: str) {

0 commit comments

Comments
 (0)