proc_macro: Turn quote
into a regular built-in macro
Previously in was implemented using a special hack in the metadata loader
This commit is contained in:
parent
9b91b9c10e
commit
32e5acb3eb
6 changed files with 19 additions and 17 deletions
|
@ -19,12 +19,15 @@
|
|||
|
||||
#![feature(nll)]
|
||||
#![feature(staged_api)]
|
||||
#![feature(allow_internal_unstable)]
|
||||
#![feature(const_fn)]
|
||||
#![feature(decl_macro)]
|
||||
#![feature(extern_types)]
|
||||
#![feature(in_band_lifetimes)]
|
||||
#![feature(optin_builtin_traits)]
|
||||
#![feature(mem_take)]
|
||||
#![feature(non_exhaustive)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(specialization)]
|
||||
|
||||
#![recursion_limit="256"]
|
||||
|
@ -222,11 +225,10 @@ pub mod token_stream {
|
|||
///
|
||||
/// Unquoting is done with `$`, and works by taking the single next ident as the unquoted term.
|
||||
/// To quote `$` itself, use `$$`.
|
||||
///
|
||||
/// This is a dummy macro, the actual implementation is in `quote::quote`.`
|
||||
#[unstable(feature = "proc_macro_quote", issue = "54722")]
|
||||
#[macro_export]
|
||||
macro_rules! quote { () => {} }
|
||||
#[allow_internal_unstable(proc_macro_def_site)]
|
||||
#[cfg_attr(not(bootstrap), rustc_builtin_macro)]
|
||||
pub macro quote ($($t:tt)*) { /* compiler built-in */ }
|
||||
|
||||
#[unstable(feature = "proc_macro_internals", issue = "27812")]
|
||||
#[doc(hidden)]
|
||||
|
|
|
@ -57,9 +57,9 @@ macro_rules! quote {
|
|||
}
|
||||
|
||||
/// Quote a `TokenStream` into a `TokenStream`.
|
||||
/// This is the actual `quote!()` proc macro.
|
||||
/// This is the actual implementation of the `quote!()` proc macro.
|
||||
///
|
||||
/// It is manually loaded in `CStore::load_macro_untracked`.
|
||||
/// It is loaded by the compiler in `register_builtin_macros`.
|
||||
#[unstable(feature = "proc_macro_quote", issue = "54722")]
|
||||
pub fn quote(stream: TokenStream) -> TokenStream {
|
||||
if stream.is_empty() {
|
||||
|
|
|
@ -30,11 +30,9 @@ use syntax::ast;
|
|||
use syntax::attr;
|
||||
use syntax::source_map;
|
||||
use syntax::edition::Edition;
|
||||
use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind};
|
||||
use syntax::ext::proc_macro::BangProcMacro;
|
||||
use syntax::parse::source_file_to_stream;
|
||||
use syntax::parse::parser::emit_unclosed_delims;
|
||||
use syntax::symbol::{Symbol, sym};
|
||||
use syntax::symbol::Symbol;
|
||||
use syntax_pos::{Span, FileName};
|
||||
use rustc_data_structures::bit_set::BitSet;
|
||||
|
||||
|
@ -437,14 +435,6 @@ impl cstore::CStore {
|
|||
let data = self.get_crate_data(id.krate);
|
||||
if data.is_proc_macro_crate() {
|
||||
return LoadedMacro::ProcMacro(data.get_proc_macro(id.index, sess).ext);
|
||||
} else if data.name == sym::proc_macro && data.item_name(id.index) == sym::quote {
|
||||
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
|
||||
let kind = SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client }));
|
||||
let ext = SyntaxExtension {
|
||||
allow_internal_unstable: Some([sym::proc_macro_def_site][..].into()),
|
||||
..SyntaxExtension::default(kind, data.root.edition)
|
||||
};
|
||||
return LoadedMacro::ProcMacro(Lrc::new(ext));
|
||||
}
|
||||
|
||||
let def = data.get_macro(id.index);
|
||||
|
|
|
@ -7,13 +7,18 @@
|
|||
#![feature(decl_macro)]
|
||||
#![feature(mem_take)]
|
||||
#![feature(nll)]
|
||||
#![feature(proc_macro_internals)]
|
||||
#![feature(proc_macro_quote)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
use crate::deriving::*;
|
||||
|
||||
use syntax::ast::Ident;
|
||||
use syntax::edition::Edition;
|
||||
use syntax::ext::base::{SyntaxExtension, SyntaxExtensionKind, MacroExpanderFn};
|
||||
use syntax::ext::proc_macro::BangProcMacro;
|
||||
use syntax::symbol::sym;
|
||||
|
||||
mod error_codes;
|
||||
|
@ -100,4 +105,7 @@ pub fn register_builtin_macros(resolver: &mut dyn syntax::ext::base::Resolver, e
|
|||
RustcDecodable: decodable::expand_deriving_rustc_decodable,
|
||||
RustcEncodable: encodable::expand_deriving_rustc_encodable,
|
||||
}
|
||||
|
||||
let client = proc_macro::bridge::client::Client::expand1(proc_macro::quote);
|
||||
register(sym::quote, SyntaxExtensionKind::Bang(Box::new(BangProcMacro { client })));
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#![crate_type = "proc-macro"]
|
||||
#![feature(proc_macro_hygiene)]
|
||||
#![feature(proc_macro_quote)]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#![crate_type = "proc-macro"]
|
||||
#![feature(proc_macro_hygiene)]
|
||||
#![feature(proc_macro_quote)]
|
||||
|
||||
extern crate proc_macro;
|
||||
|
||||
|
|
Loading…
Reference in a new issue