Revert "Add #call_box instruction"

This reverts commit 0311bab45b.
This commit is contained in:
Chris Wong 2015-09-26 13:56:52 +12:00
parent 7fde2aafb1
commit cf0cf095c2
3 changed files with 18 additions and 44 deletions
maud_macros

View file

@ -158,11 +158,6 @@ impl<'cx, 'i> Parser<'cx, 'i> {
let func = try!(self.splice(sp)); let func = try!(self.splice(sp));
self.render.emit_call(func); self.render.emit_call(func);
}, },
[pound!(), ident!(sp, name), ..] if name.name == "call_box" => {
self.shift(2);
let func = try!(self.splice(sp));
self.render.emit_call_box(func);
},
// Splice // Splice
[ref tt @ dollar!(), dollar!(), ..] => { [ref tt @ dollar!(), dollar!(), ..] => {
self.shift(2); self.shift(2);

View file

@ -198,16 +198,6 @@ impl<'cx> Renderer<'cx> {
let stmt = self.wrap_try(expr); let stmt = self.wrap_try(expr);
self.push(stmt); self.push(stmt);
} }
pub fn emit_call_box(&mut self, func: P<Expr>) {
let w = self.writer;
let expr = quote_expr!(self.cx,
::std::boxed::FnBox::call_box(
$func,
(&mut *$w as &mut ::std::fmt::Write,)));
let stmt = self.wrap_try(expr);
self.push(stmt);
}
} }
fn html_escape(s: &str) -> String { fn html_escape(s: &str) -> String {

View file

@ -1,8 +1,10 @@
#![feature(fnbox, plugin)] #![feature(plugin)]
#![plugin(maud_macros)] #![plugin(maud_macros)]
extern crate maud; extern crate maud;
use std::fmt;
#[test] #[test]
fn literals() { fn literals() {
let mut s = String::new(); let mut s = String::new();
@ -272,35 +274,22 @@ mod issue_10 {
} }
} }
mod subtemplates { #[test]
use std::fmt; fn call() {
fn ducks(w: &mut fmt::Write) -> fmt::Result { fn ducks(w: &mut fmt::Write) -> fmt::Result {
write!(w, "Ducks") write!(w, "Ducks")
} }
let mut s = String::new();
#[test] let swans = |yes|
fn call() { if yes {
let mut s = String::new(); |w: &mut fmt::Write| write!(w, "Swans")
let swans = |yes| } else {
if yes { panic!("oh noes")
|w: &mut fmt::Write| write!(w, "Swans") };
} else { html!(s, {
panic!("oh noes") #call ducks
}; #call (|w: &mut fmt::Write| write!(w, "Geese"))
html!(s, { #call swans(true)
#call ducks }).unwrap();
#call (|w: &mut fmt::Write| write!(w, "Geese")) assert_eq!(s, "DucksGeeseSwans");
#call swans(true)
}).unwrap();
assert_eq!(s, "DucksGeeseSwans");
}
#[test]
fn call_box() {
let mut s = String::new();
let ducks = Box::new(ducks);
html!(s, #call_box ducks).unwrap();
assert_eq!(s, "Ducks");
}
} }