Skip to content

quote: Explicitly borrow the ExtCtxt #17040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/librustc/front/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl<'a> fold::Folder for TestHarnessGenerator<'a> {

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

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

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

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

Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1951,15 +1951,15 @@ fn roundtrip(in_item: Option<Gc<ast::Item>>) {
#[test]
fn test_basic() {
let cx = mk_ctxt();
roundtrip(quote_item!(cx,
roundtrip(quote_item!(&cx,
fn foo() {}
));
}
/* NOTE: When there's a snapshot, update this (yay quasiquoter!)
#[test]
fn test_smalltalk() {
let cx = mk_ctxt();
roundtrip(quote_item!(cx,
roundtrip(quote_item!(&cx,
fn foo() -> int { 3 + 4 } // first smalltalk program ever executed.
));
}
Expand All @@ -1968,7 +1968,7 @@ fn test_smalltalk() {
#[test]
fn test_more() {
let cx = mk_ctxt();
roundtrip(quote_item!(cx,
roundtrip(quote_item!(&cx,
fn foo(x: uint, y: uint) -> uint {
let z = x + y;
return z;
Expand All @@ -1987,7 +1987,7 @@ fn test_simplification() {
).unwrap();
let item_in = e::IIItemRef(&*item);
let item_out = simplify_ast(item_in);
let item_exp = ast::IIItem(quote_item!(cx,
let item_exp = ast::IIItem(quote_item!(&cx,
fn new_int_alist<B>() -> alist<int, B> {
return alist {eq_fn: eq_int, data: Vec::new()};
}
Expand Down
4 changes: 3 additions & 1 deletion src/libsyntax/ext/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,9 @@ fn expand_wrapper(cx: &ExtCtxt,
cx.view_use_glob(sp, ast::Inherited, ids_ext(path))
}).collect();

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

cx.expr_block(cx.block_all(sp, uses, vec!(stmt_let_ext_cx), Some(expr)))
}
Expand Down
25 changes: 25 additions & 0 deletions src/test/run-pass-fulldeps/issue-16992.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// ignore-pretty

#![feature(quote)]

extern crate syntax;

use syntax::ext::base::ExtCtxt;

#[allow(dead_code)]
fn foobar(cx: &mut ExtCtxt) {
quote_expr!(cx, 1i);
quote_expr!(cx, 2i);
}

fn main() { }