Skip to content

Commit 1598527

Browse files
kevinanikomatsakis
authored andcommitted
Fix Issue #1926 by sorting the gather list.
1 parent 6f5853f commit 1598527

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/rustc/syntax/ext/qquote.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
103103
with *default_visitor()};
104104
let cx = @{lo:lo, mutable gather: []};
105105
node.visit(cx, mk_vt(v));
106+
// FIXME: Maybe this is an overkill (merge_sort), it might be better
107+
// to just keep the gather array in sorted order ...
108+
cx.gather = std::sort::merge_sort({|a,b| a.lo < b.lo}, copy cx.gather);
106109
ret cx;
107110
}
108111

@@ -200,9 +203,11 @@ fn finish<T: qq_helper>
200203
let qcx = gather_anti_quotes(sp.lo, node);
201204
let cx = qcx;
202205

203-
// assert that the vector is sorted by position:
204206
uint::range(1u, vec::len(cx.gather)) {|i|
205207
assert cx.gather[i-1u].lo < cx.gather[i].lo;
208+
// ^^ check that the vector is sorted
209+
assert cx.gather[i-1u].hi <= cx.gather[i].lo;
210+
// ^^ check that the spans are non-overlapping
206211
}
207212

208213
let str2 = "";

src/test/run-pass/qquote.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ fn main() {
9191

9292
let crate = #ast(crate) { fn a() { } };
9393
check_pp(crate, pprust::print_crate_, "fn a() { }\n");
94+
95+
// issue #1926
96+
let s = #ast(expr){__s};
97+
let e = #ast(expr){__e};
98+
let call = #ast(expr){$(s).foo {|__e| $(e)}};
99+
check_pp(call, pprust::print_expr, "__s.foo {|__e| __e }")
94100
}
95101

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

0 commit comments

Comments
 (0)