Skip to content

quote_expr silently discards trailing expressions #16935

Closed
@huonw

Description

@huonw
// synext.rs                                                  

#![feature(plugin_registrar, quote, rustc_private)]           
#![crate_type = "dylib"]                                      

extern crate syntax;                                          
extern crate rustc;                                           

use syntax::ext::base::{MacResult, MacEager};                 
use syntax::ast;                                              
use syntax::codemap::Span;                                    
use syntax::ext::base::ExtCtxt;                               

#[plugin_registrar]                                           
pub fn registrar(reg: &mut rustc::plugin::Registry) {         
  reg.register_macro("test", expand);                         
}                                                             

fn expand(cx: &mut ExtCtxt, _sp: Span,                        
          _tts: &[ast::TokenTree]) -> Box<MacResult+'static> {
    MacEager::expr(quote_expr!(cx,                            
        std::io::println("one");                              
        std::io::println("two");                              
    ))                                                        
}                                                             
// test-synext.rs
#![feature(phase)]

#[phase(plugin)] extern crate synext;

fn main() {
    test!()
}

Compiling those with rustc synext.rs && rustc -L . test-synext.rs --pretty expanded with

#![feature(phase)]
#![feature(phase)]
#![no_std]
#![feature(globs)]
#[phase(plugin, link)]
extern crate "std" as std;
extern crate "native" as rt;

#[phase(plugin)]
extern crate synext;
#[prelude_import]
use std::prelude::*;

fn main() { std::io::println("one") }

i.e. the std::io::println("two") is gone. Wrapping the two expressions into a { ... } works.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-syntaxextArea: Syntax extensions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions