Skip to content

Commit fb3c67a

Browse files
committed
rollup merge of #17040 : kmcallister/borrow-extctxt
2 parents d1d9d19 + 2b36194 commit fb3c67a

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

src/librustc/front/test.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {
9696

9797
// Add a special __test module to the crate that will contain code
9898
// generated for the test harness
99-
let (mod_, reexport) = mk_test_module(&self.cx, &self.cx.reexport_test_harness_main);
99+
let (mod_, reexport) = mk_test_module(&mut self.cx);
100100
folded.module.items.push(mod_);
101101
match reexport {
102102
Some(re) => folded.module.view_items.push(re),
@@ -378,8 +378,7 @@ fn mk_std(cx: &TestCtxt) -> ast::ViewItem {
378378
}
379379
}
380380

381-
fn mk_test_module(cx: &TestCtxt, reexport_test_harness_main: &Option<InternedString>)
382-
-> (Gc<ast::Item>, Option<ast::ViewItem>) {
381+
fn mk_test_module(cx: &mut TestCtxt) -> (Gc<ast::Item>, Option<ast::ViewItem>) {
383382
// Link to test crate
384383
let view_items = vec!(mk_std(cx));
385384

@@ -388,7 +387,7 @@ fn mk_test_module(cx: &TestCtxt, reexport_test_harness_main: &Option<InternedStr
388387

389388
// The synthesized main function which will call the console test runner
390389
// with our list of tests
391-
let mainfn = (quote_item!(&cx.ext_cx,
390+
let mainfn = (quote_item!(&mut cx.ext_cx,
392391
pub fn main() {
393392
#![main]
394393
use std::slice::Slice;
@@ -412,7 +411,7 @@ fn mk_test_module(cx: &TestCtxt, reexport_test_harness_main: &Option<InternedStr
412411
vis: ast::Public,
413412
span: DUMMY_SP,
414413
};
415-
let reexport = reexport_test_harness_main.as_ref().map(|s| {
414+
let reexport = cx.reexport_test_harness_main.as_ref().map(|s| {
416415
// building `use <ident> = __test::main`
417416
let reexport_ident = token::str_to_ident(s.get());
418417

src/librustc/middle/astencode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,15 +1951,15 @@ fn roundtrip(in_item: Option<Gc<ast::Item>>) {
19511951
#[test]
19521952
fn test_basic() {
19531953
let cx = mk_ctxt();
1954-
roundtrip(quote_item!(cx,
1954+
roundtrip(quote_item!(&cx,
19551955
fn foo() {}
19561956
));
19571957
}
19581958
/* NOTE: When there's a snapshot, update this (yay quasiquoter!)
19591959
#[test]
19601960
fn test_smalltalk() {
19611961
let cx = mk_ctxt();
1962-
roundtrip(quote_item!(cx,
1962+
roundtrip(quote_item!(&cx,
19631963
fn foo() -> int { 3 + 4 } // first smalltalk program ever executed.
19641964
));
19651965
}
@@ -1968,7 +1968,7 @@ fn test_smalltalk() {
19681968
#[test]
19691969
fn test_more() {
19701970
let cx = mk_ctxt();
1971-
roundtrip(quote_item!(cx,
1971+
roundtrip(quote_item!(&cx,
19721972
fn foo(x: uint, y: uint) -> uint {
19731973
let z = x + y;
19741974
return z;
@@ -1987,7 +1987,7 @@ fn test_simplification() {
19871987
).unwrap();
19881988
let item_in = e::IIItemRef(&*item);
19891989
let item_out = simplify_ast(item_in);
1990-
let item_exp = ast::IIItem(quote_item!(cx,
1990+
let item_exp = ast::IIItem(quote_item!(&cx,
19911991
fn new_int_alist<B>() -> alist<int, B> {
19921992
return alist {eq_fn: eq_int, data: Vec::new()};
19931993
}

src/libsyntax/ext/quote.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,9 @@ fn expand_wrapper(cx: &ExtCtxt,
766766
cx.view_use_glob(sp, ast::Inherited, ids_ext(path))
767767
}).collect();
768768

769-
let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr);
769+
// Explicitly borrow to avoid moving from the invoker (#16992)
770+
let cx_expr_borrow = cx.expr_addr_of(sp, cx.expr_deref(sp, cx_expr));
771+
let stmt_let_ext_cx = cx.stmt_let(sp, false, id_ext("ext_cx"), cx_expr_borrow);
770772

771773
cx.expr_block(cx.block_all(sp, uses, vec!(stmt_let_ext_cx), Some(expr)))
772774
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
// ignore-pretty
12+
13+
#![feature(quote)]
14+
15+
extern crate syntax;
16+
17+
use syntax::ext::base::ExtCtxt;
18+
19+
#[allow(dead_code)]
20+
fn foobar(cx: &mut ExtCtxt) {
21+
quote_expr!(cx, 1i);
22+
quote_expr!(cx, 2i);
23+
}
24+
25+
fn main() { }

0 commit comments

Comments
 (0)