Auto merge of #39087 - nrc:qquote-empty-delim, r=jseyfried
proc macros/qquote: Handle empty delimited tokens r? @jseyfried
This commit is contained in:
commit
32da85148a
4 changed files with 111 additions and 38 deletions
35
src/test/run-pass-fulldeps/auxiliary/hello_macro.rs
Normal file
35
src/test/run-pass-fulldeps/auxiliary/hello_macro.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2017 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.
|
||||
|
||||
#![feature(plugin)]
|
||||
#![feature(plugin_registrar)]
|
||||
#![feature(rustc_private)]
|
||||
#![plugin(proc_macro_plugin)]
|
||||
|
||||
extern crate rustc_plugin;
|
||||
extern crate proc_macro_tokens;
|
||||
extern crate syntax;
|
||||
|
||||
use syntax::ext::proc_macro_shim::prelude::*;
|
||||
use proc_macro_tokens::prelude::*;
|
||||
|
||||
use rustc_plugin::Registry;
|
||||
|
||||
#[plugin_registrar]
|
||||
pub fn plugin_registrar(reg: &mut Registry) {
|
||||
reg.register_macro("hello", hello);
|
||||
}
|
||||
|
||||
// This macro is not very interesting, but it does contain delimited tokens with
|
||||
// no content - `()` and `{}` - which has caused problems in the past.
|
||||
fn hello<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[TokenTree]) -> Box<MacResult + 'cx> {
|
||||
let output = qquote!({ fn hello() {} hello(); });
|
||||
build_block_emitter(cx, sp, output)
|
||||
}
|
||||
22
src/test/run-pass-fulldeps/macro-quote-empty-delims.rs
Normal file
22
src/test/run-pass-fulldeps/macro-quote-empty-delims.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Copyright 2012-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.
|
||||
|
||||
// Test that a macro can emit delimiters with nothing inside - `()`, `{}`
|
||||
|
||||
// aux-build:hello_macro.rs
|
||||
// ignore-stage1
|
||||
|
||||
#![feature(plugin)]
|
||||
#![feature(rustc_private)]
|
||||
#![plugin(hello_macro)]
|
||||
|
||||
fn main() {
|
||||
hello!();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue