From 15985277b98e53014b52c1e243eefcfb0335089f Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Tue, 6 Mar 2012 18:07:10 -0700 Subject: [PATCH] Fix Issue #1926 by sorting the gather list. --- src/rustc/syntax/ext/qquote.rs | 7 ++++++- src/test/run-pass/qquote.rs | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/rustc/syntax/ext/qquote.rs b/src/rustc/syntax/ext/qquote.rs index afcae2ff6908..f93a4019c31f 100644 --- a/src/rustc/syntax/ext/qquote.rs +++ b/src/rustc/syntax/ext/qquote.rs @@ -103,6 +103,9 @@ fn gather_anti_quotes(lo: uint, node: N) -> aq_ctxt with *default_visitor()}; let cx = @{lo:lo, mutable gather: []}; node.visit(cx, mk_vt(v)); + // FIXME: Maybe this is an overkill (merge_sort), it might be better + // to just keep the gather array in sorted order ... + cx.gather = std::sort::merge_sort({|a,b| a.lo < b.lo}, copy cx.gather); ret cx; } @@ -200,9 +203,11 @@ fn finish let qcx = gather_anti_quotes(sp.lo, node); let cx = qcx; - // assert that the vector is sorted by position: uint::range(1u, vec::len(cx.gather)) {|i| assert cx.gather[i-1u].lo < cx.gather[i].lo; + // ^^ check that the vector is sorted + assert cx.gather[i-1u].hi <= cx.gather[i].lo; + // ^^ check that the spans are non-overlapping } let str2 = ""; diff --git a/src/test/run-pass/qquote.rs b/src/test/run-pass/qquote.rs index 04aeba9093c8..8bb722706a14 100644 --- a/src/test/run-pass/qquote.rs +++ b/src/test/run-pass/qquote.rs @@ -91,6 +91,12 @@ fn main() { let crate = #ast(crate) { fn a() { } }; check_pp(crate, pprust::print_crate_, "fn a() { }\n"); + + // issue #1926 + let s = #ast(expr){__s}; + let e = #ast(expr){__e}; + let call = #ast(expr){$(s).foo {|__e| $(e)}}; + check_pp(call, pprust::print_expr, "__s.foo {|__e| __e }") } fn check_pp(expr: T, f: fn(pprust::ps, T), expect: str) {