From 5e5924b79915326d81db2aebfe73d2a20b8506f1 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Mon, 15 Sep 2014 16:09:09 -0700 Subject: Replace LetSyntaxTT with MacroRulesTT The implementation of LetSyntaxTT was specialized to macro_rules! in various ways. This gets rid of the false generality and simplifies the code. --- src/libsyntax/ext/base.rs | 12 +++------ src/libsyntax/ext/expand.rs | 54 +++++++++++++++---------------------- src/libsyntax/ext/tt/macro_rules.rs | 21 ++++----------- 3 files changed, 30 insertions(+), 57 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 91cc8a24622..4b38e6c0cb2 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -328,13 +328,8 @@ pub enum SyntaxExtension { /// IdentTT(Box, Option), - /// An ident macro that has two properties: - /// - it adds a macro definition to the environment, and - /// - the definition it adds doesn't introduce any new - /// identifiers. - /// - /// `macro_rules!` is a LetSyntaxTT - LetSyntaxTT(Box, Option), + /// Represents `macro_rules!` itself. + MacroRulesTT, } pub type NamedSyntaxExtension = (Name, SyntaxExtension); @@ -364,8 +359,7 @@ fn initial_syntax_expander_table(ecfg: &expand::ExpansionConfig) -> SyntaxEnv { } let mut syntax_expanders = SyntaxEnv::new(); - syntax_expanders.insert(intern("macro_rules"), - LetSyntaxTT(box ext::tt::macro_rules::add_new_extension, None)); + syntax_expanders.insert(intern("macro_rules"), MacroRulesTT); syntax_expanders.insert(intern("fmt"), builtin_normal_expander( ext::fmt::expand_syntax_ext)); diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index b3f30dd4581..a1a13f23064 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -7,7 +7,6 @@ // , at your // option. This file may not be copied, modified, or distributed // except according to those terms. -use self::Either::*; use ast::{Block, Crate, DeclLocal, ExprMac, PatMac}; use ast::{Local, Ident, MacInvocTT}; @@ -18,6 +17,7 @@ use ast; use ast_util::path_to_ident; use ext::mtwt; use ext::build::AstBuilder; +use ext::tt::macro_rules; use attr; use attr::AttrMetaMethods; use codemap; @@ -33,11 +33,6 @@ use util::small_vector::SmallVector; use visit; use visit::Visitor; -enum Either { - Left(L), - Right(R) -} - pub fn expand_type(t: P, fld: &mut MacroExpander, impl_ty: Option>) @@ -548,8 +543,8 @@ pub fn expand_item_mac(it: P, fld: &mut MacroExpander) let extnamestr = token::get_ident(extname); let fm = fresh_mark(); - let def_or_items = { - let mut expanded = match fld.cx.syntax_env.find(&extname.name) { + let items = { + let expanded = match fld.cx.syntax_env.find(&extname.name) { None => { fld.cx.span_err(path_span, format!("macro undefined: '{}!'", @@ -600,11 +595,10 @@ pub fn expand_item_mac(it: P, fld: &mut MacroExpander) let marked_tts = mark_tts(tts[], fm); expander.expand(fld.cx, it.span, it.ident, marked_tts) } - LetSyntaxTT(ref expander, span) => { + MacroRulesTT => { if it.ident.name == parse::token::special_idents::invalid.name { fld.cx.span_err(path_span, - format!("macro {}! expects an ident argument", - extnamestr.get())[]); + format!("macro_rules! expects an ident argument")[]); return SmallVector::zero(); } fld.cx.bt_push(ExpnInfo { @@ -612,11 +606,21 @@ pub fn expand_item_mac(it: P, fld: &mut MacroExpander) callee: NameAndSpan { name: extnamestr.get().to_string(), format: MacroBang, - span: span + span: None, } }); - // DON'T mark before expansion: - expander.expand(fld.cx, it.span, it.ident, tts) + // DON'T mark before expansion. + let MacroDef { name, ext } + = macro_rules::add_new_extension(fld.cx, it.span, it.ident, tts); + + fld.cx.syntax_env.insert(intern(name.as_slice()), ext); + if attr::contains_name(it.attrs.as_slice(), "macro_export") { + fld.cx.exported_macros.push(it); + } + + // macro_rules! has a side effect but expands to nothing. + fld.cx.bt_pop(); + return SmallVector::zero(); } _ => { fld.cx.span_err(it.span, @@ -627,31 +631,17 @@ pub fn expand_item_mac(it: P, fld: &mut MacroExpander) } }; - match expanded.make_def() { - Some(def) => Left(def), - None => Right(expanded.make_items()) - } + expanded.make_items() }; - let items = match def_or_items { - Left(MacroDef { name, ext }) => { - // hidden invariant: this should only be possible as the - // result of expanding a LetSyntaxTT, and thus doesn't - // need to be marked. Not that it could be marked anyway. - // create issue to recommend refactoring here? - fld.cx.syntax_env.insert(intern(name[]), ext); - if attr::contains_name(it.attrs[], "macro_export") { - fld.cx.exported_macros.push(it); - } - SmallVector::zero() - } - Right(Some(items)) => { + let items = match items { + Some(items) => { items.into_iter() .map(|i| mark_item(i, fm)) .flat_map(|i| fld.fold_item(i).into_iter()) .collect() } - Right(None) => { + None => { fld.cx.span_err(path_span, format!("non-item macro in item position: {}", extnamestr.get())[]); diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 08014dc1338..15b75442ca2 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -129,15 +129,6 @@ impl TTMacroExpander for MacroRulesMacroExpander { } } -struct MacroRulesDefiner { - def: Option -} -impl MacResult for MacroRulesDefiner { - fn make_def(&mut self) -> Option { - Some(self.def.take().expect("empty MacroRulesDefiner")) - } -} - /// Given `lhses` and `rhses`, this is the new macro we create fn generic_extension<'cx>(cx: &'cx ExtCtxt, sp: Span, @@ -219,7 +210,7 @@ pub fn add_new_extension<'cx>(cx: &'cx mut ExtCtxt, sp: Span, name: Ident, arg: Vec ) - -> Box { + -> MacroDef { let lhs_nm = gensym_ident("lhs"); let rhs_nm = gensym_ident("rhs"); @@ -279,10 +270,8 @@ pub fn add_new_extension<'cx>(cx: &'cx mut ExtCtxt, rhses: rhses, }; - box MacroRulesDefiner { - def: Some(MacroDef { - name: token::get_ident(name).to_string(), - ext: NormalTT(exp, Some(sp)) - }) - } as Box + MacroDef { + name: token::get_ident(name).to_string(), + ext: NormalTT(exp, Some(sp)) + } } -- cgit 1.4.1-3-g733a5 From ad7c64777380a780b42028855ad0d09932a11623 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Mon, 15 Sep 2014 18:27:28 -0700 Subject: Add a special macro nonterminal $crate --- src/librustdoc/html/highlight.rs | 3 +++ src/libsyntax/ast.rs | 7 ++++++ src/libsyntax/ext/expand.rs | 12 +++++---- src/libsyntax/ext/tt/macro_rules.rs | 8 ++++++ src/libsyntax/ext/tt/transcribe.rs | 29 +++++++++++++++++++++- src/libsyntax/parse/mod.rs | 2 +- src/libsyntax/parse/parser.rs | 7 ++++-- src/libsyntax/parse/token.rs | 24 ++++++++++++++++++ src/libsyntax/print/pprust.rs | 2 ++ src/test/auxiliary/macro_crate_nonterminal.rs | 24 ++++++++++++++++++ .../run-pass/macro-crate-nonterminal-renamed.rs | 22 ++++++++++++++++ src/test/run-pass/macro-crate-nonterminal.rs | 22 ++++++++++++++++ 12 files changed, 153 insertions(+), 9 deletions(-) create mode 100644 src/test/auxiliary/macro_crate_nonterminal.rs create mode 100644 src/test/run-pass/macro-crate-nonterminal-renamed.rs create mode 100644 src/test/run-pass/macro-crate-nonterminal.rs (limited to 'src/libsyntax/ext') diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs index cfaae1a9f80..30b9d6c63c5 100644 --- a/src/librustdoc/html/highlight.rs +++ b/src/librustdoc/html/highlight.rs @@ -166,6 +166,9 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader, } } + // Special macro vars are like keywords + token::SpecialVarNt(_) => "kw-2", + token::Lifetime(..) => "lifetime", token::DocComment(..) => "doccomment", token::Underscore | token::Eof | token::Interpolated(..) | diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index c9d27e304ff..55aa73b4faa 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -884,6 +884,7 @@ impl TokenTree { match *self { TtToken(_, token::DocComment(_)) => 2, TtToken(_, token::SubstNt(..)) => 2, + TtToken(_, token::SpecialVarNt(..)) => 2, TtToken(_, token::MatchNt(..)) => 3, TtDelimited(_, ref delimed) => { delimed.tts.len() + 2 @@ -925,6 +926,12 @@ impl TokenTree { TtToken(sp, token::Ident(name, name_st))]; v[index] } + (&TtToken(sp, token::SpecialVarNt(var)), _) => { + let v = [TtToken(sp, token::Dollar), + TtToken(sp, token::Ident(token::str_to_ident(var.as_str()), + token::Plain))]; + v[index] + } (&TtToken(sp, token::MatchNt(name, kind, name_st, kind_st)), _) => { let v = [TtToken(sp, token::SubstNt(name, name_st)), TtToken(sp, token::Colon), diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index a1a13f23064..325d8aa594a 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -432,7 +432,7 @@ pub fn expand_item(it: P, fld: &mut MacroExpander) } let mut new_items = match it.node { - ast::ItemMac(..) => expand_item_mac(it, fld), + ast::ItemMac(..) => expand_item_mac(it, None, fld), ast::ItemMod(_) | ast::ItemForeignMod(_) => { let valid_ident = it.ident.name != parse::token::special_idents::invalid.name; @@ -529,8 +529,9 @@ fn contains_macro_escape(attrs: &[ast::Attribute]) -> bool { // Support for item-position macro invocations, exactly the same // logic as for expression-position macro invocations. -pub fn expand_item_mac(it: P, fld: &mut MacroExpander) - -> SmallVector> { +pub fn expand_item_mac(it: P, + imported_from: Option, + fld: &mut MacroExpander) -> SmallVector> { let (extname, path_span, tts) = match it.node { ItemMac(codemap::Spanned { node: MacInvocTT(ref pth, ref tts, _), @@ -611,7 +612,8 @@ pub fn expand_item_mac(it: P, fld: &mut MacroExpander) }); // DON'T mark before expansion. let MacroDef { name, ext } - = macro_rules::add_new_extension(fld.cx, it.span, it.ident, tts); + = macro_rules::add_new_extension(fld.cx, it.span, it.ident, + imported_from, tts); fld.cx.syntax_env.insert(intern(name.as_slice()), ext); if attr::contains_name(it.attrs.as_slice(), "macro_export") { @@ -1190,7 +1192,7 @@ pub fn expand_crate(parse_sess: &parse::ParseSess, expander.cx.cfg(), expander.cx.parse_sess()) .expect("expected a serialized item"); - expand_item_mac(item, &mut expander); + expand_item_mac(item, Some(crate_name), &mut expander); } } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 15b75442ca2..a278604b167 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -110,6 +110,7 @@ impl<'a> MacResult for ParserAnyMacro<'a> { struct MacroRulesMacroExpander { name: Ident, + imported_from: Option, lhses: Vec>, rhses: Vec>, } @@ -123,6 +124,7 @@ impl TTMacroExpander for MacroRulesMacroExpander { generic_extension(cx, sp, self.name, + self.imported_from, arg, self.lhses[], self.rhses[]) @@ -133,6 +135,7 @@ impl TTMacroExpander for MacroRulesMacroExpander { fn generic_extension<'cx>(cx: &'cx ExtCtxt, sp: Span, name: Ident, + imported_from: Option, arg: &[ast::TokenTree], lhses: &[Rc], rhses: &[Rc]) @@ -156,6 +159,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt, }; // `None` is because we're not interpolating let mut arg_rdr = new_tt_reader(&cx.parse_sess().span_diagnostic, + None, None, arg.iter() .map(|x| (*x).clone()) @@ -177,6 +181,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt, // rhs has holes ( `$id` and `$(...)` that need filled) let trncbr = new_tt_reader(&cx.parse_sess().span_diagnostic, Some(named_matches), + imported_from, rhs); let p = Parser::new(cx.parse_sess(), cx.cfg(), box trncbr); // Let the context choose how to interpret the result. @@ -209,6 +214,7 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt, pub fn add_new_extension<'cx>(cx: &'cx mut ExtCtxt, sp: Span, name: Ident, + imported_from: Option, arg: Vec ) -> MacroDef { @@ -246,6 +252,7 @@ pub fn add_new_extension<'cx>(cx: &'cx mut ExtCtxt, // Parse the macro_rules! invocation (`none` is for no interpolations): let arg_reader = new_tt_reader(&cx.parse_sess().span_diagnostic, + None, None, arg.clone()); let argument_map = parse_or_else(cx.parse_sess(), @@ -266,6 +273,7 @@ pub fn add_new_extension<'cx>(cx: &'cx mut ExtCtxt, let exp = box MacroRulesMacroExpander { name: name, + imported_from: imported_from, lhses: lhses, rhses: rhses, }; diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs index 86e81ede8b0..e4e6f5ac6b0 100644 --- a/src/libsyntax/ext/tt/transcribe.rs +++ b/src/libsyntax/ext/tt/transcribe.rs @@ -15,7 +15,7 @@ use codemap::{Span, DUMMY_SP}; use diagnostic::SpanHandler; use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal}; use parse::token::{Eof, DocComment, Interpolated, MatchNt, SubstNt}; -use parse::token::{Token, NtIdent}; +use parse::token::{Token, NtIdent, SpecialMacroVar}; use parse::token; use parse::lexer::TokenAndSpan; @@ -39,6 +39,10 @@ pub struct TtReader<'a> { stack: Vec, /* for MBE-style macro transcription */ interpolations: HashMap>, + imported_from: Option, + + // Some => return imported_from as the next token + crate_name_next: Option, repeat_idx: Vec, repeat_len: Vec, /* cached: */ @@ -53,6 +57,7 @@ pub struct TtReader<'a> { /// should) be none. pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler, interp: Option>>, + imported_from: Option, src: Vec ) -> TtReader<'a> { let mut r = TtReader { @@ -71,6 +76,8 @@ pub fn new_tt_reader<'a>(sp_diag: &'a SpanHandler, None => HashMap::new(), Some(x) => x, }, + imported_from: imported_from, + crate_name_next: None, repeat_idx: Vec::new(), repeat_len: Vec::new(), desugar_doc_comments: false, @@ -162,6 +169,14 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { sp: r.cur_span.clone(), }; loop { + match r.crate_name_next.take() { + None => (), + Some(sp) => { + r.cur_span = sp; + r.cur_tok = token::Ident(r.imported_from.unwrap(), token::Plain); + return ret_val; + }, + } let should_pop = match r.stack.last() { None => { assert_eq!(ret_val.tok, token::Eof); @@ -307,6 +322,18 @@ pub fn tt_next_token(r: &mut TtReader) -> TokenAndSpan { sep: None }); } + TtToken(sp, token::SpecialVarNt(SpecialMacroVar::CrateMacroVar)) => { + r.stack.last_mut().unwrap().idx += 1; + + if r.imported_from.is_some() { + r.cur_span = sp; + r.cur_tok = token::ModSep; + r.crate_name_next = Some(sp); + return ret_val; + } + + // otherwise emit nothing and proceed to the next token + } TtToken(sp, tok) => { r.cur_span = sp; r.cur_tok = tok; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 8598571e5c3..3e4f2c8d4e2 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -291,7 +291,7 @@ pub fn filemap_to_tts(sess: &ParseSess, filemap: Rc) pub fn tts_to_parser<'a>(sess: &'a ParseSess, tts: Vec, cfg: ast::CrateConfig) -> Parser<'a> { - let trdr = lexer::new_tt_reader(&sess.span_diagnostic, None, tts); + let trdr = lexer::new_tt_reader(&sess.span_diagnostic, None, None, tts); Parser::new(sess, cfg, box trdr) } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index cc67079e538..f513692c31d 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -75,8 +75,8 @@ use parse::classify; use parse::common::{SeqSep, seq_sep_none, seq_sep_trailing_allowed}; use parse::lexer::{Reader, TokenAndSpan}; use parse::obsolete::*; -use parse::token::{self, MatchNt, SubstNt, InternedString}; -use parse::token::{keywords, special_idents}; +use parse::token::{self, MatchNt, SubstNt, SpecialVarNt, InternedString}; +use parse::token::{keywords, special_idents, SpecialMacroVar}; use parse::{new_sub_parser_from_file, ParseSess}; use print::pprust; use ptr::P; @@ -2747,6 +2747,9 @@ impl<'a> Parser<'a> { op: repeat, num_captures: name_num })) + } else if p.token.is_keyword_allow_following_colon(keywords::Crate) { + p.bump(); + TtToken(sp, SpecialVarNt(SpecialMacroVar::CrateMacroVar)) } else { // A nonterminal that matches or not let namep = match p.token { token::Ident(_, p) => p, _ => token::Plain }; diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index b7e89b32b70..a653190cffd 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -61,6 +61,21 @@ pub enum IdentStyle { Plain, } +#[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Show, Copy)] +pub enum SpecialMacroVar { + /// `$crate` will be filled in with the name of the crate a macro was + /// imported from, if any. + CrateMacroVar, +} + +impl SpecialMacroVar { + pub fn as_str(self) -> &'static str { + match self { + SpecialMacroVar::CrateMacroVar => "crate", + } + } +} + #[derive(Clone, RustcEncodable, RustcDecodable, PartialEq, Eq, Hash, Show, Copy)] pub enum Lit { Byte(ast::Name), @@ -143,6 +158,8 @@ pub enum Token { // In right-hand-sides of MBE macros: /// A syntactic variable that will be filled in by macro expansion. SubstNt(ast::Ident, IdentStyle), + /// A macro variable with special meaning. + SpecialVarNt(SpecialMacroVar), // Junk. These carry no data because we don't really care about the data // they *would* carry, and don't really want to allocate a new ident for @@ -265,6 +282,13 @@ impl Token { } } + pub fn is_keyword_allow_following_colon(&self, kw: keywords::Keyword) -> bool { + match *self { + Ident(sid, _) => { kw.to_name() == sid.name } + _ => { false } + } + } + /// Returns `true` if the token is either a special identifier, or a strict /// or reserved keyword. #[allow(non_upper_case_globals)] diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index 61b7aa408a8..27db49b65ce 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -272,6 +272,8 @@ pub fn token_to_string(tok: &Token) -> String { token::Comment => "/* */".to_string(), token::Shebang(s) => format!("/* shebang: {}*/", s.as_str()), + token::SpecialVarNt(var) => format!("${}", var.as_str()), + token::Interpolated(ref nt) => match *nt { token::NtExpr(ref e) => expr_to_string(&**e), token::NtMeta(ref e) => meta_item_to_string(&**e), diff --git a/src/test/auxiliary/macro_crate_nonterminal.rs b/src/test/auxiliary/macro_crate_nonterminal.rs new file mode 100644 index 00000000000..20df664c3c6 --- /dev/null +++ b/src/test/auxiliary/macro_crate_nonterminal.rs @@ -0,0 +1,24 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(macro_rules)] + +pub fn increment(x: uint) -> uint { + x + 1 +} + +#[macro_export] +macro_rules! increment { + ($x:expr) => ($crate::increment($x)) +} + +pub fn check_local() { + assert_eq!(increment!(3), 4); +} diff --git a/src/test/run-pass/macro-crate-nonterminal-renamed.rs b/src/test/run-pass/macro-crate-nonterminal-renamed.rs new file mode 100644 index 00000000000..cf9a53f27be --- /dev/null +++ b/src/test/run-pass/macro-crate-nonterminal-renamed.rs @@ -0,0 +1,22 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:macro_crate_nonterminal.rs +// ignore-stage1 + +#![feature(phase)] + +#[phase(plugin, link)] +extern crate "macro_crate_nonterminal" as new_name; + +pub fn main() { + new_name::check_local(); + assert_eq!(increment!(5), 6); +} diff --git a/src/test/run-pass/macro-crate-nonterminal.rs b/src/test/run-pass/macro-crate-nonterminal.rs new file mode 100644 index 00000000000..8abf534ab12 --- /dev/null +++ b/src/test/run-pass/macro-crate-nonterminal.rs @@ -0,0 +1,22 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:macro_crate_nonterminal.rs +// ignore-stage1 + +#![feature(phase)] + +#[phase(plugin, link)] +extern crate macro_crate_nonterminal; + +pub fn main() { + macro_crate_nonterminal::check_local(); + assert_eq!(increment!(5), 6); +} -- cgit 1.4.1-3-g733a5 From 538288176a22b4d3755df085783f84d476386019 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Mon, 15 Sep 2014 19:02:14 -0700 Subject: Implement macro re-export Fixes #17103. --- src/librustc_driver/driver.rs | 2 ++ src/libsyntax/ext/expand.rs | 9 ++++- src/libsyntax/ext/tt/reexport.rs | 41 ++++++++++++++++++++++ src/libsyntax/lib.rs | 1 + src/test/auxiliary/macro_reexport_1.rs | 17 +++++++++ src/test/auxiliary/macro_reexport_2.rs | 17 +++++++++ .../compile-fail/macro-reexport-malformed-1.rs | 13 +++++++ .../compile-fail/macro-reexport-malformed-2.rs | 13 +++++++ .../compile-fail/macro-reexport-malformed-3.rs | 13 +++++++ src/test/run-pass/macro-reexport.rs | 22 ++++++++++++ 10 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 src/libsyntax/ext/tt/reexport.rs create mode 100644 src/test/auxiliary/macro_reexport_1.rs create mode 100644 src/test/auxiliary/macro_reexport_2.rs create mode 100644 src/test/compile-fail/macro-reexport-malformed-1.rs create mode 100644 src/test/compile-fail/macro-reexport-malformed-2.rs create mode 100644 src/test/compile-fail/macro-reexport-malformed-3.rs create mode 100644 src/test/run-pass/macro-reexport.rs (limited to 'src/libsyntax/ext') diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 0d9736a8273..5056ada6a8c 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -275,6 +275,8 @@ pub fn phase_2_configure_and_expand(sess: &Session, deriving_hash_type_parameter: sess.features.borrow().default_type_params, enable_quotes: sess.features.borrow().quote, recursion_limit: sess.recursion_limit.get(), + reexported_macros: syntax::ext::tt::reexport::gather(sess.diagnostic(), + &krate), }; let ret = syntax::ext::expand::expand_crate(&sess.parse_sess, cfg, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 325d8aa594a..d4be46d025e 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -616,7 +616,12 @@ pub fn expand_item_mac(it: P, imported_from, tts); fld.cx.syntax_env.insert(intern(name.as_slice()), ext); - if attr::contains_name(it.attrs.as_slice(), "macro_export") { + + if match imported_from { + None => attr::contains_name(it.attrs.as_slice(), "macro_export"), + Some(_) => fld.cx.ecfg.reexported_macros.iter() + .any(|e| e.as_slice() == name.as_slice()), + } { fld.cx.exported_macros.push(it); } @@ -1156,6 +1161,7 @@ pub struct ExpansionConfig { pub deriving_hash_type_parameter: bool, pub enable_quotes: bool, pub recursion_limit: uint, + pub reexported_macros: Vec, } impl ExpansionConfig { @@ -1165,6 +1171,7 @@ impl ExpansionConfig { deriving_hash_type_parameter: false, enable_quotes: false, recursion_limit: 64, + reexported_macros: vec![], } } } diff --git a/src/libsyntax/ext/tt/reexport.rs b/src/libsyntax/ext/tt/reexport.rs new file mode 100644 index 00000000000..104f3787253 --- /dev/null +++ b/src/libsyntax/ext/tt/reexport.rs @@ -0,0 +1,41 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Defines the crate attribute syntax for macro re-export. + +use ast; +use attr::AttrMetaMethods; +use diagnostic::SpanHandler; + +/// Return a vector of the names of all macros re-exported from the crate. +pub fn gather(diag: &SpanHandler, krate: &ast::Crate) -> Vec { + let usage = "malformed macro_reexport attribute, expected \ + #![macro_reexport(ident, ident, ...)]"; + + let mut reexported: Vec = vec!(); + for attr in krate.attrs.iter() { + if !attr.check_name("macro_reexport") { + continue; + } + + match attr.meta_item_list() { + None => diag.span_err(attr.span, usage), + Some(list) => for mi in list.iter() { + match mi.node { + ast::MetaWord(ref word) + => reexported.push(word.to_string()), + _ => diag.span_err(mi.span, usage), + } + } + } + } + + reexported +} diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 18cdb3fc647..0503d88cca2 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -104,5 +104,6 @@ pub mod ext { pub mod transcribe; pub mod macro_parser; pub mod macro_rules; + pub mod reexport; } } diff --git a/src/test/auxiliary/macro_reexport_1.rs b/src/test/auxiliary/macro_reexport_1.rs new file mode 100644 index 00000000000..bd00b33f280 --- /dev/null +++ b/src/test/auxiliary/macro_reexport_1.rs @@ -0,0 +1,17 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "dylib"] +#![feature(macro_rules)] + +#[macro_export] +macro_rules! reexported { + () => ( 3u ) +} diff --git a/src/test/auxiliary/macro_reexport_2.rs b/src/test/auxiliary/macro_reexport_2.rs new file mode 100644 index 00000000000..3b68d47c558 --- /dev/null +++ b/src/test/auxiliary/macro_reexport_2.rs @@ -0,0 +1,17 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "dylib"] +#![feature(phase)] + +#![macro_reexport(reexported)] + +#[phase(plugin)] +extern crate macro_reexport_1; diff --git a/src/test/compile-fail/macro-reexport-malformed-1.rs b/src/test/compile-fail/macro-reexport-malformed-1.rs new file mode 100644 index 00000000000..ea3074db124 --- /dev/null +++ b/src/test/compile-fail/macro-reexport-malformed-1.rs @@ -0,0 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![macro_reexport] //~ ERROR malformed macro_reexport attribute + +fn main() { } diff --git a/src/test/compile-fail/macro-reexport-malformed-2.rs b/src/test/compile-fail/macro-reexport-malformed-2.rs new file mode 100644 index 00000000000..3daa089d2c6 --- /dev/null +++ b/src/test/compile-fail/macro-reexport-malformed-2.rs @@ -0,0 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![macro_reexport="foo"] //~ ERROR malformed macro_reexport attribute + +fn main() { } diff --git a/src/test/compile-fail/macro-reexport-malformed-3.rs b/src/test/compile-fail/macro-reexport-malformed-3.rs new file mode 100644 index 00000000000..b3c0bf95ce9 --- /dev/null +++ b/src/test/compile-fail/macro-reexport-malformed-3.rs @@ -0,0 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![macro_reexport(foo="bar")] //~ ERROR malformed macro_reexport attribute + +fn main() { } diff --git a/src/test/run-pass/macro-reexport.rs b/src/test/run-pass/macro-reexport.rs new file mode 100644 index 00000000000..bc3632e76ba --- /dev/null +++ b/src/test/run-pass/macro-reexport.rs @@ -0,0 +1,22 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:macro_reexport_1.rs +// aux-build:macro_reexport_2.rs +// ignore-stage1 + +#![feature(phase)] + +#[phase(plugin)] +extern crate macro_reexport_2; + +fn main() { + assert_eq!(reexported!(), 3u); +} -- cgit 1.4.1-3-g733a5 From 5bf385be6a5ce267ac7cd9d1725178488e33131c Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Thu, 18 Dec 2014 20:48:26 -0800 Subject: Rename macro_escape to macro_use In the future we want to support #[macro_use(foo, bar)] mod macros; but it's not an essential part of macro reform. Reserve the syntax for now. --- src/libcollections/lib.rs | 3 +- src/libcore/lib.rs | 12 ++++-- src/libcoretest/num/mod.rs | 6 ++- src/liblog/lib.rs | 3 +- src/librustc_driver/driver.rs | 2 +- src/librustc_trans/trans/mod.rs | 3 +- src/librustdoc/lib.rs | 3 +- src/libstd/io/mod.rs | 3 +- src/libstd/lib.rs | 21 ++++++---- src/libstd/rt/mod.rs | 2 + src/libstd/thread_local/mod.rs | 3 +- src/libsyntax/ext/expand.rs | 45 +++++++++++++--------- src/libsyntax/parse/mod.rs | 3 +- .../compile-fail/module-macro_use-arguments.rs | 16 ++++++++ src/test/run-pass/cfg-macros-foo.rs | 4 +- src/test/run-pass/cfg-macros-notfoo.rs | 4 +- src/test/run-pass/deprecated-macro_escape-inner.rs | 19 +++++++++ src/test/run-pass/deprecated-macro_escape.rs | 18 +++++++++ 18 files changed, 127 insertions(+), 43 deletions(-) create mode 100644 src/test/compile-fail/module-macro_use-arguments.rs create mode 100644 src/test/run-pass/deprecated-macro_escape-inner.rs create mode 100644 src/test/run-pass/deprecated-macro_escape.rs (limited to 'src/libsyntax/ext') diff --git a/src/libcollections/lib.rs b/src/libcollections/lib.rs index 9214ec7e65b..142ac6f34e0 100644 --- a/src/libcollections/lib.rs +++ b/src/libcollections/lib.rs @@ -54,7 +54,8 @@ pub use vec_map::VecMap; // Needed for the vec! macro pub use alloc::boxed; -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] mod macros; pub mod binary_heap; diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index 588421dfa10..aff0065c527 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -62,19 +62,23 @@ #![feature(default_type_params, unboxed_closures, associated_types)] #![deny(missing_docs)] -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] mod macros; #[path = "num/float_macros.rs"] -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] mod float_macros; #[path = "num/int_macros.rs"] -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] mod int_macros; #[path = "num/uint_macros.rs"] -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] mod uint_macros; #[path = "num/int.rs"] pub mod int; diff --git a/src/libcoretest/num/mod.rs b/src/libcoretest/num/mod.rs index 01868675c76..f86c85f8216 100644 --- a/src/libcoretest/num/mod.rs +++ b/src/libcoretest/num/mod.rs @@ -14,7 +14,8 @@ use core::num::{NumCast, cast}; use core::ops::{Add, Sub, Mul, Div, Rem}; use core::kinds::Copy; -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] mod int_macros; mod i8; @@ -23,7 +24,8 @@ mod i32; mod i64; mod int; -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] mod uint_macros; mod u8; diff --git a/src/liblog/lib.rs b/src/liblog/lib.rs index 61523c6fd0f..c210873563c 100644 --- a/src/liblog/lib.rs +++ b/src/liblog/lib.rs @@ -183,7 +183,8 @@ use regex::Regex; use directive::LOG_LEVEL_NAMES; -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] pub mod macros; mod directive; diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index 5056ada6a8c..027af6619ab 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -182,7 +182,7 @@ pub fn phase_2_configure_and_expand(sess: &Session, // strip before expansion to allow macros to depend on // configuration variables e.g/ in // - // #[macro_escape] #[cfg(foo)] + // #[macro_use] #[cfg(foo)] // mod bar { macro_rules! baz!(() => {{}}) } // // baz! should not use this definition unless foo is enabled. diff --git a/src/librustc_trans/trans/mod.rs b/src/librustc_trans/trans/mod.rs index 9b7f282f8bb..fa9cd5a698b 100644 --- a/src/librustc_trans/trans/mod.rs +++ b/src/librustc_trans/trans/mod.rs @@ -16,7 +16,8 @@ pub use self::base::trans_crate; pub use self::context::CrateContext; pub use self::common::gensym_name; -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] mod macros; mod doc; diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index a454760c8b5..319eee87317 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -49,7 +49,8 @@ use rustc::session::search_paths::SearchPaths; // reexported from `clean` so it can be easily updated with the mod itself pub use clean::SCHEMA_VERSION; -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] pub mod externalfiles; pub mod clean; diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index bf373a145e4..e9386c30a6d 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -285,7 +285,8 @@ pub mod stdio; pub mod timer; pub mod util; -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] pub mod test; /// The default buffer size for various I/O operations diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 5ffd3ebc7ad..abe968849c2 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -173,14 +173,17 @@ pub use unicode::char; /* Exported macros */ #[cfg(stage0)] -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] pub mod macros_stage0; #[cfg(not(stage0))] -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] pub mod macros; -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] pub mod bitflags; mod rtdeps; @@ -193,15 +196,18 @@ pub mod prelude; /* Primitive types */ #[path = "num/float_macros.rs"] -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] mod float_macros; #[path = "num/int_macros.rs"] -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] mod int_macros; #[path = "num/uint_macros.rs"] -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] mod uint_macros; #[path = "num/int.rs"] pub mod int; @@ -229,7 +235,8 @@ pub mod num; /* Runtime and platform support */ -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] pub mod thread_local; pub mod c_str; diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 2b0639c5705..e556888a470 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -39,6 +39,8 @@ pub use alloc::heap; pub mod backtrace; // Internals +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] mod macros; // These should be refactored/moved/made private over time diff --git a/src/libstd/thread_local/mod.rs b/src/libstd/thread_local/mod.rs index 1ed01c034b5..e0cbaa8ca50 100644 --- a/src/libstd/thread_local/mod.rs +++ b/src/libstd/thread_local/mod.rs @@ -40,7 +40,8 @@ use prelude::v1::*; use cell::UnsafeCell; -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] pub mod scoped; // Sure wish we had macro hygiene, no? diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d4be46d025e..13cbc83f730 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -440,9 +440,9 @@ pub fn expand_item(it: P, fld: &mut MacroExpander) if valid_ident { fld.cx.mod_push(it.ident); } - let macro_escape = contains_macro_escape(new_attrs[]); + let macro_use = contains_macro_use(fld, new_attrs[]); let result = with_exts_frame!(fld.cx.syntax_env, - macro_escape, + macro_use, noop_fold_item(it, fld)); if valid_ident { fld.cx.mod_pop(); @@ -522,9 +522,28 @@ fn expand_item_underscore(item: ast::Item_, fld: &mut MacroExpander) -> ast::Ite } } -// does this attribute list contain "macro_escape" ? -fn contains_macro_escape(attrs: &[ast::Attribute]) -> bool { - attr::contains_name(attrs, "macro_escape") +// does this attribute list contain "macro_use" ? +fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool { + for attr in attrs.iter() { + let mut is_use = attr.check_name("macro_use"); + if attr.check_name("macro_escape") { + fld.cx.span_warn(attr.span, "macro_escape is a deprecated synonym for macro_use"); + is_use = true; + if let ast::AttrInner = attr.node.style { + fld.cx.span_help(attr.span, "consider an outer attribute, \ + #[macro_use] mod ..."); + } + }; + + if is_use { + match attr.node.value.node { + ast::MetaWord(..) => (), + _ => fld.cx.span_err(attr.span, "arguments to macro_use are not allowed here"), + } + return true; + } + } + false } // Support for item-position macro invocations, exactly the same @@ -1299,7 +1318,7 @@ impl<'a, 'v> Visitor<'v> for MacroExterminator<'a> { #[cfg(test)] mod test { - use super::{pattern_bindings, expand_crate, contains_macro_escape}; + use super::{pattern_bindings, expand_crate, contains_macro_use}; use super::{PatIdentFinder, IdentRenamer, PatIdentRenamer, ExpansionConfig}; use ast; use ast::{Attribute_, AttrOuter, MetaWord, Name}; @@ -1396,9 +1415,9 @@ mod test { expand_crate(&sess,test_ecfg(),vec!(),vec!(),crate_ast); } - // macro_escape modules should allow macros to escape + // macro_use modules should allow macros to escape #[test] fn macros_can_escape_flattened_mods_test () { - let src = "#[macro_escape] mod foo {macro_rules! z (() => (3+4));}\ + let src = "#[macro_use] mod foo {macro_rules! z (() => (3+4));}\ fn inty() -> int { z!() }".to_string(); let sess = parse::new_parse_sess(); let crate_ast = parse::parse_crate_from_source_str( @@ -1408,16 +1427,6 @@ mod test { expand_crate(&sess, test_ecfg(), vec!(), vec!(), crate_ast); } - #[test] fn test_contains_flatten (){ - let attr1 = make_dummy_attr ("foo"); - let attr2 = make_dummy_attr ("bar"); - let escape_attr = make_dummy_attr ("macro_escape"); - let attrs1 = vec!(attr1.clone(), escape_attr, attr2.clone()); - assert_eq!(contains_macro_escape(attrs1[]),true); - let attrs2 = vec!(attr1,attr2); - assert_eq!(contains_macro_escape(attrs2[]),false); - } - // make a MetaWord outer attribute with the given name fn make_dummy_attr(s: &str) -> ast::Attribute { Spanned { diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 05ed535ee36..ee7edceaf69 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -24,7 +24,8 @@ use std::num::Int; use std::str; use std::iter; -#[macro_escape] +#[cfg_attr(stage0, macro_escape)] +#[cfg_attr(not(stage0), macro_use)] pub mod parser; pub mod lexer; diff --git a/src/test/compile-fail/module-macro_use-arguments.rs b/src/test/compile-fail/module-macro_use-arguments.rs new file mode 100644 index 00000000000..6d3038b4820 --- /dev/null +++ b/src/test/compile-fail/module-macro_use-arguments.rs @@ -0,0 +1,16 @@ +// Copyright 2013-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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[macro_use(foo, bar)] //~ ERROR arguments to macro_use are not allowed here +mod foo { +} + +fn main() { +} diff --git a/src/test/run-pass/cfg-macros-foo.rs b/src/test/run-pass/cfg-macros-foo.rs index ec9ef381501..548057e9e60 100644 --- a/src/test/run-pass/cfg-macros-foo.rs +++ b/src/test/run-pass/cfg-macros-foo.rs @@ -16,7 +16,7 @@ #![feature(macro_rules)] #[cfg(foo)] -#[macro_escape] +#[macro_use] mod foo { macro_rules! bar { () => { true } @@ -24,7 +24,7 @@ mod foo { } #[cfg(not(foo))] -#[macro_escape] +#[macro_use] mod foo { macro_rules! bar { () => { false } diff --git a/src/test/run-pass/cfg-macros-notfoo.rs b/src/test/run-pass/cfg-macros-notfoo.rs index fb44176ec22..bf4f7e6bc40 100644 --- a/src/test/run-pass/cfg-macros-notfoo.rs +++ b/src/test/run-pass/cfg-macros-notfoo.rs @@ -16,7 +16,7 @@ #![feature(macro_rules)] #[cfg(foo)] -#[macro_escape] +#[macro_use] mod foo { macro_rules! bar { () => { true } @@ -24,7 +24,7 @@ mod foo { } #[cfg(not(foo))] -#[macro_escape] +#[macro_use] mod foo { macro_rules! bar { () => { false } diff --git a/src/test/run-pass/deprecated-macro_escape-inner.rs b/src/test/run-pass/deprecated-macro_escape-inner.rs new file mode 100644 index 00000000000..7960a91bdc4 --- /dev/null +++ b/src/test/run-pass/deprecated-macro_escape-inner.rs @@ -0,0 +1,19 @@ +// Copyright 2013-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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-pretty + +mod foo { + #![macro_escape] //~ WARNING macro_escape is a deprecated synonym for macro_use + //~^ HELP consider an outer attribute +} + +fn main() { +} diff --git a/src/test/run-pass/deprecated-macro_escape.rs b/src/test/run-pass/deprecated-macro_escape.rs new file mode 100644 index 00000000000..b03905e1a0d --- /dev/null +++ b/src/test/run-pass/deprecated-macro_escape.rs @@ -0,0 +1,18 @@ +// Copyright 2013-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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-pretty + +#[macro_escape] //~ WARNING macro_escape is a deprecated synonym for macro_use +mod foo { +} + +fn main() { +} -- cgit 1.4.1-3-g733a5 From 677b7cad3d0ca1347f65ae9b409078343a5f302e Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Tue, 30 Dec 2014 19:10:46 -0800 Subject: Reformat metadata for exported macros Instead of copy-pasting the whole macro_rules! item from the original .rs file, we serialize a separate name, attributes list, and body, the latter as pretty-printed TTs. The compilation of macro_rules! macros is decoupled somewhat from the expansion of macros in item position. This filters out comments, and facilitates selective imports. --- src/librustc/metadata/common.rs | 8 ++++-- src/librustc/metadata/creader.rs | 40 ++++++++++++++++++++++++--- src/librustc/metadata/decoder.rs | 15 +++++----- src/librustc/metadata/encoder.rs | 35 +++++++++++------------ src/librustc/plugin/load.rs | 33 +++++++++------------- src/librustdoc/visit_ast.rs | 14 +++++----- src/libsyntax/ast.rs | 15 +++++++++- src/libsyntax/ext/base.rs | 22 +-------------- src/libsyntax/ext/expand.rs | 55 ++++++++++++++++--------------------- src/libsyntax/ext/tt/macro_rules.rs | 29 +++++++------------ src/libsyntax/fold.rs | 6 +++- src/libsyntax/parse/mod.rs | 4 +++ 12 files changed, 143 insertions(+), 133 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/librustc/metadata/common.rs b/src/librustc/metadata/common.rs index ca7c65c8e2b..de9a09ffe44 100644 --- a/src/librustc/metadata/common.rs +++ b/src/librustc/metadata/common.rs @@ -206,8 +206,8 @@ pub const tag_native_libraries_name: uint = 0x89; pub const tag_native_libraries_kind: uint = 0x8a; pub const tag_plugin_registrar_fn: uint = 0x8b; -pub const tag_exported_macros: uint = 0x8c; -pub const tag_macro_def: uint = 0x8d; + +// GAP 0x8c, 0x8d pub const tag_method_argument_names: uint = 0x8e; pub const tag_method_argument_name: uint = 0x8f; @@ -261,3 +261,7 @@ pub const tag_associated_type_names: uint = 0xb2; pub const tag_associated_type_name: uint = 0xb3; pub const tag_polarity: uint = 0xb4; + +pub const tag_macro_defs: uint = 0xb5; +pub const tag_macro_def: uint = 0xb6; +pub const tag_macro_def_body: uint = 0xb7; diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 2e6dbf077ee..3bf0e41ae9c 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -29,8 +29,9 @@ use syntax::ast; use syntax::abi; use syntax::attr; use syntax::attr::AttrMetaMethods; -use syntax::codemap::{Span}; +use syntax::codemap::{Span, mk_sp}; use syntax::diagnostic::SpanHandler; +use syntax::parse; use syntax::parse::token::InternedString; use syntax::parse::token; use syntax::visit; @@ -491,7 +492,36 @@ impl<'a> CrateReader<'a> { } None => { load_ctxt.report_load_errs(); unreachable!() }, }; - let macros = decoder::get_exported_macros(library.metadata.as_slice()); + + // Read exported macros + let imported_from = Some(token::intern(info.ident[]).ident()); + let source_name = format!("<{} macros>", info.ident[]); + let mut macros = vec![]; + decoder::each_exported_macro(library.metadata.as_slice(), &*self.sess.cstore.intr, + |name, attrs, body| { + // NB: Don't use parse::parse_tts_from_source_str because it parses with + // quote_depth > 0. + let mut p = parse::new_parser_from_source_str(&self.sess.parse_sess, + self.sess.opts.cfg.clone(), + source_name.clone(), + body); + let lo = p.span.lo; + let body = p.parse_all_token_trees(); + let span = mk_sp(lo, p.last_span.hi); + p.abort_if_errors(); + macros.push(ast::MacroDef { + ident: name.ident(), + attrs: attrs, + id: ast::DUMMY_NODE_ID, + span: span, + imported_from: imported_from, + body: body, + }); + true + } + ); + + // Look for a plugin registrar let registrar = decoder::get_plugin_registrar_fn(library.metadata.as_slice()).map(|id| { decoder::get_symbol(library.metadata.as_slice(), id) }); @@ -504,9 +534,11 @@ impl<'a> CrateReader<'a> { // empty dylib. } let pc = PluginMetadata { - lib: library.dylib.clone(), macros: macros, - registrar_symbol: registrar, + registrar: match (library.dylib.as_ref(), registrar) { + (Some(dylib), Some(reg)) => Some((dylib.clone(), reg)), + _ => None, + }, }; if should_link && self.existing_match(info.name[], None).is_none() { // register crate now to avoid double-reading metadata diff --git a/src/librustc/metadata/decoder.rs b/src/librustc/metadata/decoder.rs index 97f5228f033..0e1fbcfcb89 100644 --- a/src/librustc/metadata/decoder.rs +++ b/src/librustc/metadata/decoder.rs @@ -1353,15 +1353,16 @@ pub fn get_plugin_registrar_fn(data: &[u8]) -> Option { .map(|doc| FromPrimitive::from_u32(reader::doc_as_u32(doc)).unwrap()) } -pub fn get_exported_macros(data: &[u8]) -> Vec { - let macros = reader::get_doc(rbml::Doc::new(data), - tag_exported_macros); - let mut result = Vec::new(); +pub fn each_exported_macro(data: &[u8], intr: &IdentInterner, mut f: F) where + F: FnMut(ast::Name, Vec, String) -> bool, +{ + let macros = reader::get_doc(rbml::Doc::new(data), tag_macro_defs); reader::tagged_docs(macros, tag_macro_def, |macro_doc| { - result.push(macro_doc.as_str().to_string()); - true + let name = item_name(intr, macro_doc); + let attrs = get_attributes(macro_doc); + let body = reader::get_doc(macro_doc, tag_macro_def_body); + f(name, attrs, body.as_str().to_string()) }); - result } pub fn get_dylib_dependency_formats(cdata: Cmd) diff --git a/src/librustc/metadata/encoder.rs b/src/librustc/metadata/encoder.rs index 59679f0bc7c..37f06926317 100644 --- a/src/librustc/metadata/encoder.rs +++ b/src/librustc/metadata/encoder.rs @@ -42,6 +42,7 @@ use syntax::attr::AttrMetaMethods; use syntax::diagnostic::SpanHandler; use syntax::parse::token::special_idents; use syntax::parse::token; +use syntax::print::pprust; use syntax::ptr::P; use syntax::visit::Visitor; use syntax::visit; @@ -1818,25 +1819,21 @@ fn encode_plugin_registrar_fn(ecx: &EncodeContext, rbml_w: &mut Encoder) { } } -/// Given a span, write the text of that span into the output stream -/// as an exported macro -fn encode_macro_def(ecx: &EncodeContext, - rbml_w: &mut Encoder, - span: &syntax::codemap::Span) { - let def = ecx.tcx.sess.codemap().span_to_snippet(*span) - .expect("Unable to find source for macro"); - rbml_w.start_tag(tag_macro_def); - rbml_w.wr_str(def[]); - rbml_w.end_tag(); -} - /// Serialize the text of the exported macros -fn encode_macro_defs(ecx: &EncodeContext, - krate: &ast::Crate, - rbml_w: &mut Encoder) { - rbml_w.start_tag(tag_exported_macros); - for item in krate.exported_macros.iter() { - encode_macro_def(ecx, rbml_w, &item.span); +fn encode_macro_defs(rbml_w: &mut Encoder, + krate: &ast::Crate) { + rbml_w.start_tag(tag_macro_defs); + for def in krate.exported_macros.iter() { + rbml_w.start_tag(tag_macro_def); + + encode_name(rbml_w, def.ident.name); + encode_attributes(rbml_w, def.attrs[]); + + rbml_w.start_tag(tag_macro_def_body); + rbml_w.wr_str(pprust::tts_to_string(def.body[])[]); + rbml_w.end_tag(); + + rbml_w.end_tag(); } rbml_w.end_tag(); } @@ -2154,7 +2151,7 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter, // Encode macro definitions i = rbml_w.writer.tell().unwrap(); - encode_macro_defs(&ecx, krate, &mut rbml_w); + encode_macro_defs(&mut rbml_w, krate); stats.macro_defs_bytes = rbml_w.writer.tell().unwrap() - i; // Encode the types of all unboxed closures in this crate. diff --git a/src/librustc/plugin/load.rs b/src/librustc/plugin/load.rs index 19d7c24c953..9aa7d8fe990 100644 --- a/src/librustc/plugin/load.rs +++ b/src/librustc/plugin/load.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! Used by `rustc` when loading a plugin. +//! Used by `rustc` when loading a plugin, or a crate with exported macros. use session::Session; use metadata::creader::CrateReader; @@ -21,17 +21,14 @@ use syntax::ast; use syntax::attr; use syntax::visit; use syntax::visit::Visitor; -use syntax::ext::expand::ExportedMacros; use syntax::attr::AttrMetaMethods; -/// Plugin-related crate metadata. +/// Metadata for a single plugin crate. pub struct PluginMetadata { - /// Source code of macros exported by the crate. - pub macros: Vec, - /// Path to the shared library file. - pub lib: Option, - /// Symbol name of the plugin registrar function. - pub registrar_symbol: Option, + /// Macros exported by the crate. + pub macros: Vec, + /// Path to the shared library file, and registrar function symbol. + pub registrar: Option<(Path, String)>, } /// Pointer to a registrar function. @@ -40,8 +37,8 @@ pub type PluginRegistrarFun = /// Information about loaded plugins. pub struct Plugins { - /// Source code of exported macros. - pub macros: Vec, + /// Imported macros. + pub macros: Vec, /// Registrars, as function pointers. pub registrars: Vec, } @@ -90,7 +87,7 @@ pub fn load_plugins(sess: &Session, krate: &ast::Crate, impl<'a, 'v> Visitor<'v> for PluginLoader<'a> { fn visit_view_item(&mut self, vi: &ast::ViewItem) { match vi.node { - ast::ViewItemExternCrate(name, _, _) => { + ast::ViewItemExternCrate(_, _, _) => { let mut plugin_phase = false; for attr in vi.attrs.iter().filter(|a| a.check_name("phase")) { @@ -107,17 +104,13 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> { if !plugin_phase { return; } - let PluginMetadata { macros, lib, registrar_symbol } = + let PluginMetadata { macros, registrar } = self.reader.read_plugin_metadata(vi); - self.plugins.macros.push(ExportedMacros { - crate_name: name, - macros: macros, - }); + self.plugins.macros.extend(macros.into_iter()); - match (lib, registrar_symbol) { - (Some(lib), Some(symbol)) - => self.dylink_registrar(vi, lib, symbol), + match registrar { + Some((lib, symbol)) => self.dylink_registrar(vi, lib, symbol), _ => (), } } diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index c98ec97ab87..ad67672ea6e 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -73,7 +73,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { None); // attach the crate's exported macros to the top-level module: self.module.macros = krate.exported_macros.iter() - .map(|it| self.visit_macro(&**it)).collect(); + .map(|def| self.visit_macro(def)).collect(); self.module.is_crate = true; } @@ -363,13 +363,13 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { } // convert each exported_macro into a doc item - fn visit_macro(&self, item: &ast::Item) -> Macro { + fn visit_macro(&self, def: &ast::MacroDef) -> Macro { Macro { - id: item.id, - attrs: item.attrs.clone(), - name: item.ident, - whence: item.span, - stab: self.stability(item.id), + id: def.id, + attrs: def.attrs.clone(), + name: def.ident, + whence: def.span, + stab: self.stability(def.id), } } } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 55aa73b4faa..36fc8a691dc 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -476,7 +476,7 @@ pub struct Crate { pub attrs: Vec, pub config: CrateConfig, pub span: Span, - pub exported_macros: Vec> + pub exported_macros: Vec, } pub type MetaItem = Spanned; @@ -1698,6 +1698,19 @@ pub enum InlinedItem { IIForeign(P), } +/// A macro definition, in this crate or imported from another. +/// +/// Not parsed directly, but created on macro import or `macro_rules!` expansion. +#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Show)] +pub struct MacroDef { + pub ident: Ident, + pub attrs: Vec, + pub id: NodeId, + pub span: Span, + pub imported_from: Option, + pub body: Vec, +} + #[cfg(test)] mod test { use serialize::json; diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 4b38e6c0cb2..9a06745967f 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -28,19 +28,6 @@ use fold::Folder; use std::collections::HashMap; use std::rc::Rc; -// new-style macro! tt code: -// -// MacResult, NormalTT, IdentTT -// -// also note that ast::Mac used to have a bunch of extraneous cases and -// is now probably a redundant AST node, can be merged with -// ast::MacInvocTT. - -pub struct MacroDef { - pub name: String, - pub ext: SyntaxExtension -} - pub trait ItemDecorator { fn expand(&self, ecx: &mut ExtCtxt, @@ -140,13 +127,6 @@ impl IdentMacroExpander for F /// methods are spliced into the AST at the callsite of the macro (or /// just into the compiler's internal macro table, for `make_def`). pub trait MacResult { - /// Attempt to define a new macro. - // this should go away; the idea that a macro might expand into - // either a macro definition or an expression, depending on what - // the context wants, is kind of silly. - fn make_def(&mut self) -> Option { - None - } /// Create an expression. fn make_expr(self: Box) -> Option> { None @@ -469,7 +449,7 @@ pub struct ExtCtxt<'a> { pub mod_path: Vec , pub trace_mac: bool, - pub exported_macros: Vec>, + pub exported_macros: Vec, pub syntax_env: SyntaxEnv, pub recursion_count: uint, diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 13cbc83f730..d56df2d7fb4 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -432,7 +432,7 @@ pub fn expand_item(it: P, fld: &mut MacroExpander) } let mut new_items = match it.node { - ast::ItemMac(..) => expand_item_mac(it, None, fld), + ast::ItemMac(..) => expand_item_mac(it, fld), ast::ItemMod(_) | ast::ItemForeignMod(_) => { let valid_ident = it.ident.name != parse::token::special_idents::invalid.name; @@ -549,7 +549,6 @@ fn contains_macro_use(fld: &mut MacroExpander, attrs: &[ast::Attribute]) -> bool // Support for item-position macro invocations, exactly the same // logic as for expression-position macro invocations. pub fn expand_item_mac(it: P, - imported_from: Option, fld: &mut MacroExpander) -> SmallVector> { let (extname, path_span, tts) = match it.node { ItemMac(codemap::Spanned { @@ -630,18 +629,20 @@ pub fn expand_item_mac(it: P, } }); // DON'T mark before expansion. - let MacroDef { name, ext } - = macro_rules::add_new_extension(fld.cx, it.span, it.ident, - imported_from, tts); - - fld.cx.syntax_env.insert(intern(name.as_slice()), ext); - - if match imported_from { - None => attr::contains_name(it.attrs.as_slice(), "macro_export"), - Some(_) => fld.cx.ecfg.reexported_macros.iter() - .any(|e| e.as_slice() == name.as_slice()), - } { - fld.cx.exported_macros.push(it); + + let def = ast::MacroDef { + ident: it.ident, + attrs: it.attrs.clone(), + id: ast::DUMMY_NODE_ID, + span: it.span, + imported_from: None, + body: tts, + }; + let ext = macro_rules::compile(fld.cx, &def); + fld.cx.syntax_env.insert(def.ident.name, ext); + + if attr::contains_name(def.attrs.as_slice(), "macro_export") { + fld.cx.exported_macros.push(def); } // macro_rules! has a side effect but expands to nothing. @@ -680,9 +681,6 @@ pub fn expand_item_mac(it: P, } /// Expand a stmt -// -// I don't understand why this returns a vector... it looks like we're -// half done adding machinery to allow macros to expand into multiple statements. fn expand_stmt(s: Stmt, fld: &mut MacroExpander) -> SmallVector> { let (mac, style) = match s.node { StmtMac(mac, style) => (mac, style), @@ -1195,30 +1193,23 @@ impl ExpansionConfig { } } -pub struct ExportedMacros { - pub crate_name: Ident, - pub macros: Vec, -} - pub fn expand_crate(parse_sess: &parse::ParseSess, cfg: ExpansionConfig, // these are the macros being imported to this crate: - imported_macros: Vec, + imported_macros: Vec, user_exts: Vec, c: Crate) -> Crate { let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg); let mut expander = MacroExpander::new(&mut cx); - for ExportedMacros { crate_name, macros } in imported_macros.into_iter() { - let name = format!("<{} macros>", token::get_ident(crate_name)); + for def in imported_macros.iter() { + let ext = macro_rules::compile(expander.cx, def); + expander.cx.syntax_env.insert(def.ident.name, ext); + + if expander.cx.ecfg.reexported_macros.iter() + .any(|e| e[] == token::get_ident(def.ident).get()) { - for source in macros.into_iter() { - let item = parse::parse_item_from_source_str(name.clone(), - source, - expander.cx.cfg(), - expander.cx.parse_sess()) - .expect("expected a serialized item"); - expand_item_mac(item, Some(crate_name), &mut expander); + expander.cx.exported_macros.push(def.clone()); } } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index a278604b167..cf0d2c6474b 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -11,7 +11,7 @@ use ast::{Ident, TtDelimited, TtSequence, TtToken}; use ast; use codemap::{Span, DUMMY_SP}; -use ext::base::{ExtCtxt, MacResult, MacroDef}; +use ext::base::{ExtCtxt, MacResult, SyntaxExtension}; use ext::base::{NormalTT, TTMacroExpander}; use ext::tt::macro_parser::{Success, Error, Failure}; use ext::tt::macro_parser::{NamedMatch, MatchedSeq, MatchedNonterminal}; @@ -208,15 +208,9 @@ fn generic_extension<'cx>(cx: &'cx ExtCtxt, // // Holy self-referential! -/// This procedure performs the expansion of the -/// macro_rules! macro. It parses the RHS and adds -/// an extension to the current context. -pub fn add_new_extension<'cx>(cx: &'cx mut ExtCtxt, - sp: Span, - name: Ident, - imported_from: Option, - arg: Vec ) - -> MacroDef { +/// Converts a `macro_rules!` invocation into a syntax extension. +pub fn compile<'cx>(cx: &'cx mut ExtCtxt, + def: &ast::MacroDef) -> SyntaxExtension { let lhs_nm = gensym_ident("lhs"); let rhs_nm = gensym_ident("rhs"); @@ -254,7 +248,7 @@ pub fn add_new_extension<'cx>(cx: &'cx mut ExtCtxt, let arg_reader = new_tt_reader(&cx.parse_sess().span_diagnostic, None, None, - arg.clone()); + def.body.clone()); let argument_map = parse_or_else(cx.parse_sess(), cx.cfg(), arg_reader, @@ -263,23 +257,20 @@ pub fn add_new_extension<'cx>(cx: &'cx mut ExtCtxt, // Extract the arguments: let lhses = match *argument_map[lhs_nm] { MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(), - _ => cx.span_bug(sp, "wrong-structured lhs") + _ => cx.span_bug(def.span, "wrong-structured lhs") }; let rhses = match *argument_map[rhs_nm] { MatchedSeq(ref s, _) => /* FIXME (#2543) */ (*s).clone(), - _ => cx.span_bug(sp, "wrong-structured rhs") + _ => cx.span_bug(def.span, "wrong-structured rhs") }; let exp = box MacroRulesMacroExpander { - name: name, - imported_from: imported_from, + name: def.ident, + imported_from: def.imported_from, lhses: lhses, rhses: rhses, }; - MacroDef { - name: token::get_ident(name).to_string(), - ext: NormalTT(exp, Some(sp)) - } + NormalTT(exp, Some(def.span)) } diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 35b2e5dbc53..6b5d333ef8f 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -1115,7 +1115,7 @@ pub fn noop_fold_mod(Mod {inner, view_items, items}: Mod, folder: &mu } } -pub fn noop_fold_crate(Crate {module, attrs, config, exported_macros, span}: Crate, +pub fn noop_fold_crate(Crate {module, attrs, config, mut exported_macros, span}: Crate, folder: &mut T) -> Crate { let config = folder.fold_meta_items(config); @@ -1146,6 +1146,10 @@ pub fn noop_fold_crate(Crate {module, attrs, config, exported_macros, }, Vec::new(), span) }; + for def in exported_macros.iter_mut() { + def.id = folder.new_id(def.id); + } + Crate { module: module, attrs: attrs, diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index ee7edceaf69..b0969a573e6 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -169,6 +169,8 @@ pub fn parse_stmt_from_source_str(name: String, // Note: keep in sync with `with_hygiene::parse_tts_from_source_str` // until #16472 is resolved. +// +// Warning: This parses with quote_depth > 0, which is not the default. pub fn parse_tts_from_source_str(name: String, source: String, cfg: ast::CrateConfig, @@ -310,6 +312,8 @@ pub mod with_hygiene { // Note: keep this in sync with `super::parse_tts_from_source_str` until // #16472 is resolved. + // + // Warning: This parses with quote_depth > 0, which is not the default. pub fn parse_tts_from_source_str(name: String, source: String, cfg: ast::CrateConfig, -- cgit 1.4.1-3-g733a5 From 0816255c80ee3f2a8870ee5e4379e3739d8ed72e Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Thu, 1 Jan 2015 16:37:47 -0800 Subject: Move #[macro_reexport] to extern crate --- src/librustc/metadata/creader.rs | 1 + src/librustc/plugin/load.rs | 28 ++++++++++++++- src/librustc_driver/driver.rs | 2 -- src/libstd/lib.rs | 6 ++-- src/libsyntax/ast.rs | 1 + src/libsyntax/ext/base.rs | 10 ++++++ src/libsyntax/ext/expand.rs | 22 +++--------- src/libsyntax/ext/tt/reexport.rs | 41 ---------------------- src/libsyntax/lib.rs | 1 - src/test/auxiliary/macro_reexport_2.rs | 3 +- .../compile-fail/macro-reexport-malformed-1.rs | 3 +- .../compile-fail/macro-reexport-malformed-2.rs | 3 +- .../compile-fail/macro-reexport-malformed-3.rs | 3 +- 13 files changed, 53 insertions(+), 71 deletions(-) delete mode 100644 src/libsyntax/ext/tt/reexport.rs (limited to 'src/libsyntax/ext') diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index c7a8457c6d2..d83bd8b9223 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -552,6 +552,7 @@ impl<'a> PluginMetadata<'a> { id: ast::DUMMY_NODE_ID, span: span, imported_from: imported_from, + export: false, // overridden in plugin/load.rs body: body, }); true diff --git a/src/librustc/plugin/load.rs b/src/librustc/plugin/load.rs index d17ef199aa1..93c97f6caa6 100644 --- a/src/librustc/plugin/load.rs +++ b/src/librustc/plugin/load.rs @@ -17,8 +17,10 @@ use plugin::registry::Registry; use std::mem; use std::os; use std::dynamic_lib::DynamicLibrary; +use std::collections::HashSet; use syntax::ast; use syntax::attr; +use syntax::parse::token; use syntax::visit; use syntax::visit::Visitor; use syntax::attr::AttrMetaMethods; @@ -87,6 +89,7 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> { // Parse the attributes relating to macro / plugin loading. let mut load_macros = false; let mut load_registrar = false; + let mut reexport = HashSet::new(); for attr in vi.attrs.iter() { let mut used = true; match attr.name().get() { @@ -96,6 +99,23 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> { } "plugin" => load_registrar = true, "macro_use" => load_macros = true, + "macro_reexport" => { + let names = match attr.meta_item_list() { + Some(names) => names, + None => { + self.sess.span_err(attr.span, "bad macro reexport"); + continue; + } + }; + + for name in names.iter() { + if let ast::MetaWord(ref name) = name.node { + reexport.insert(name.clone()); + } else { + self.sess.span_err(name.span, "bad macro reexport"); + } + } + } _ => used = false, } if used { @@ -116,7 +136,13 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> { } } - self.plugins.macros.extend(macros.into_iter()); + for mut def in macros.into_iter() { + if reexport.contains(&token::get_ident(def.ident)) { + def.export = true; + } + self.plugins.macros.push(def); + } + if let Some((lib, symbol)) = registrar { self.dylink_registrar(vi, lib, symbol); } diff --git a/src/librustc_driver/driver.rs b/src/librustc_driver/driver.rs index f23cddf833c..261d73b5bf0 100644 --- a/src/librustc_driver/driver.rs +++ b/src/librustc_driver/driver.rs @@ -275,8 +275,6 @@ pub fn phase_2_configure_and_expand(sess: &Session, deriving_hash_type_parameter: sess.features.borrow().default_type_params, enable_quotes: sess.features.borrow().quote, recursion_limit: sess.recursion_limit.get(), - reexported_macros: syntax::ext::tt::reexport::gather(sess.diagnostic(), - &krate), }; let ret = syntax::ext::expand::expand_crate(&sess.parse_sess, cfg, diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 3eda6d3374e..65c36d813f4 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -117,9 +117,6 @@ #![reexport_test_harness_main = "test_main"] -#![macro_reexport(assert, assert_eq, debug_assert, debug_assert_eq, - unreachable, unimplemented, write, writeln, vec)] - #[cfg(all(test, stage0))] #[phase(plugin, link)] extern crate log; @@ -134,6 +131,8 @@ extern crate core; #[cfg(not(stage0))] #[macro_use] +#[macro_reexport(assert, assert_eq, debug_assert, debug_assert_eq, + unreachable, unimplemented, write, writeln)] extern crate core; #[cfg(stage0)] @@ -142,6 +141,7 @@ extern crate "collections" as core_collections; #[cfg(not(stage0))] #[macro_use] +#[macro_reexport(vec)] extern crate "collections" as core_collections; extern crate "rand" as core_rand; diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 36fc8a691dc..e34060a73c1 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1708,6 +1708,7 @@ pub struct MacroDef { pub id: NodeId, pub span: Span, pub imported_from: Option, + pub export: bool, pub body: Vec, } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 9a06745967f..815159e94c8 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -16,6 +16,7 @@ use codemap; use codemap::{CodeMap, Span, ExpnId, ExpnInfo, NO_EXPANSION}; use ext; use ext::expand; +use ext::tt::macro_rules; use parse; use parse::parser; use parse::token; @@ -568,6 +569,15 @@ impl<'a> ExtCtxt<'a> { } } } + + pub fn insert_macro(&mut self, def: ast::MacroDef) { + if def.export { + self.exported_macros.push(def.clone()); + } + let ext = macro_rules::compile(self, &def); + self.syntax_env.insert(def.ident.name, ext); + } + /// Emit `msg` attached to `sp`, and stop compilation immediately. /// /// `span_err` should be strongly preferred where-ever possible: diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d56df2d7fb4..6c2b0610fa0 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -17,7 +17,6 @@ use ast; use ast_util::path_to_ident; use ext::mtwt; use ext::build::AstBuilder; -use ext::tt::macro_rules; use attr; use attr::AttrMetaMethods; use codemap; @@ -636,14 +635,10 @@ pub fn expand_item_mac(it: P, id: ast::DUMMY_NODE_ID, span: it.span, imported_from: None, + export: attr::contains_name(it.attrs.as_slice(), "macro_export"), body: tts, }; - let ext = macro_rules::compile(fld.cx, &def); - fld.cx.syntax_env.insert(def.ident.name, ext); - - if attr::contains_name(def.attrs.as_slice(), "macro_export") { - fld.cx.exported_macros.push(def); - } + fld.cx.insert_macro(def); // macro_rules! has a side effect but expands to nothing. fld.cx.bt_pop(); @@ -1178,7 +1173,6 @@ pub struct ExpansionConfig { pub deriving_hash_type_parameter: bool, pub enable_quotes: bool, pub recursion_limit: uint, - pub reexported_macros: Vec, } impl ExpansionConfig { @@ -1188,7 +1182,6 @@ impl ExpansionConfig { deriving_hash_type_parameter: false, enable_quotes: false, recursion_limit: 64, - reexported_macros: vec![], } } } @@ -1202,15 +1195,8 @@ pub fn expand_crate(parse_sess: &parse::ParseSess, let mut cx = ExtCtxt::new(parse_sess, c.config.clone(), cfg); let mut expander = MacroExpander::new(&mut cx); - for def in imported_macros.iter() { - let ext = macro_rules::compile(expander.cx, def); - expander.cx.syntax_env.insert(def.ident.name, ext); - - if expander.cx.ecfg.reexported_macros.iter() - .any(|e| e[] == token::get_ident(def.ident).get()) { - - expander.cx.exported_macros.push(def.clone()); - } + for def in imported_macros.into_iter() { + expander.cx.insert_macro(def); } for (name, extension) in user_exts.into_iter() { diff --git a/src/libsyntax/ext/tt/reexport.rs b/src/libsyntax/ext/tt/reexport.rs deleted file mode 100644 index 104f3787253..00000000000 --- a/src/libsyntax/ext/tt/reexport.rs +++ /dev/null @@ -1,41 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Defines the crate attribute syntax for macro re-export. - -use ast; -use attr::AttrMetaMethods; -use diagnostic::SpanHandler; - -/// Return a vector of the names of all macros re-exported from the crate. -pub fn gather(diag: &SpanHandler, krate: &ast::Crate) -> Vec { - let usage = "malformed macro_reexport attribute, expected \ - #![macro_reexport(ident, ident, ...)]"; - - let mut reexported: Vec = vec!(); - for attr in krate.attrs.iter() { - if !attr.check_name("macro_reexport") { - continue; - } - - match attr.meta_item_list() { - None => diag.span_err(attr.span, usage), - Some(list) => for mi in list.iter() { - match mi.node { - ast::MetaWord(ref word) - => reexported.push(word.to_string()), - _ => diag.span_err(mi.span, usage), - } - } - } - } - - reexported -} diff --git a/src/libsyntax/lib.rs b/src/libsyntax/lib.rs index 774a9f61cf9..b7bfd346d50 100644 --- a/src/libsyntax/lib.rs +++ b/src/libsyntax/lib.rs @@ -111,6 +111,5 @@ pub mod ext { pub mod transcribe; pub mod macro_parser; pub mod macro_rules; - pub mod reexport; } } diff --git a/src/test/auxiliary/macro_reexport_2.rs b/src/test/auxiliary/macro_reexport_2.rs index f54e5e5c4e1..15d9f9cc914 100644 --- a/src/test/auxiliary/macro_reexport_2.rs +++ b/src/test/auxiliary/macro_reexport_2.rs @@ -10,7 +10,6 @@ #![crate_type = "dylib"] -#![macro_reexport(reexported)] - +#[macro_reexport(reexported)] #[macro_use] #[no_link] extern crate macro_reexport_1; diff --git a/src/test/compile-fail/macro-reexport-malformed-1.rs b/src/test/compile-fail/macro-reexport-malformed-1.rs index ea3074db124..b9f754b2778 100644 --- a/src/test/compile-fail/macro-reexport-malformed-1.rs +++ b/src/test/compile-fail/macro-reexport-malformed-1.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![macro_reexport] //~ ERROR malformed macro_reexport attribute +#[macro_reexport] //~ ERROR bad macro reexport +extern crate std; fn main() { } diff --git a/src/test/compile-fail/macro-reexport-malformed-2.rs b/src/test/compile-fail/macro-reexport-malformed-2.rs index 3daa089d2c6..9ced5be8479 100644 --- a/src/test/compile-fail/macro-reexport-malformed-2.rs +++ b/src/test/compile-fail/macro-reexport-malformed-2.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![macro_reexport="foo"] //~ ERROR malformed macro_reexport attribute +#[macro_reexport="foo"] //~ ERROR bad macro reexport +extern crate std; fn main() { } diff --git a/src/test/compile-fail/macro-reexport-malformed-3.rs b/src/test/compile-fail/macro-reexport-malformed-3.rs index b3c0bf95ce9..c8bd0a0509c 100644 --- a/src/test/compile-fail/macro-reexport-malformed-3.rs +++ b/src/test/compile-fail/macro-reexport-malformed-3.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![macro_reexport(foo="bar")] //~ ERROR malformed macro_reexport attribute +#[macro_reexport(foo="bar")] //~ ERROR bad macro reexport +extern crate std; fn main() { } -- cgit 1.4.1-3-g733a5 From aa69cbde8279cd90457454c3b3f40a36e8a79dff Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Fri, 2 Jan 2015 12:50:45 -0800 Subject: Allow selective macro import --- src/librustc/metadata/creader.rs | 5 +++- src/librustc/plugin/load.rs | 33 ++++++++++++++++++---- src/libsyntax/ast.rs | 1 + src/libsyntax/ext/base.rs | 6 ++-- src/libsyntax/ext/expand.rs | 1 + src/test/auxiliary/macro_reexport_2_no_use.rs | 15 ++++++++++ src/test/auxiliary/two_macros.rs | 19 +++++++++++++ src/test/compile-fail/empty-macro-use.rs | 19 +++++++++++++ .../macro-reexport-not-locally-visible.rs | 20 +++++++++++++ src/test/compile-fail/macro-use-bad-args-1.rs | 15 ++++++++++ src/test/compile-fail/macro-use-bad-args-2.rs | 15 ++++++++++ src/test/compile-fail/macro-use-wrong-name.rs | 19 +++++++++++++ src/test/compile-fail/missing-macro-use.rs | 18 ++++++++++++ .../run-pass/macro-reexport-no-intermediate-use.rs | 20 +++++++++++++ src/test/run-pass/macro-use-all-and-none.rs | 21 ++++++++++++++ src/test/run-pass/macro-use-all.rs | 20 +++++++++++++ src/test/run-pass/macro-use-both.rs | 20 +++++++++++++ src/test/run-pass/macro-use-one.rs | 19 +++++++++++++ src/test/run-pass/two-macro-use.rs | 21 ++++++++++++++ 19 files changed, 299 insertions(+), 8 deletions(-) create mode 100644 src/test/auxiliary/macro_reexport_2_no_use.rs create mode 100644 src/test/auxiliary/two_macros.rs create mode 100644 src/test/compile-fail/empty-macro-use.rs create mode 100644 src/test/compile-fail/macro-reexport-not-locally-visible.rs create mode 100644 src/test/compile-fail/macro-use-bad-args-1.rs create mode 100644 src/test/compile-fail/macro-use-bad-args-2.rs create mode 100644 src/test/compile-fail/macro-use-wrong-name.rs create mode 100644 src/test/compile-fail/missing-macro-use.rs create mode 100644 src/test/run-pass/macro-reexport-no-intermediate-use.rs create mode 100644 src/test/run-pass/macro-use-all-and-none.rs create mode 100644 src/test/run-pass/macro-use-all.rs create mode 100644 src/test/run-pass/macro-use-both.rs create mode 100644 src/test/run-pass/macro-use-one.rs create mode 100644 src/test/run-pass/two-macro-use.rs (limited to 'src/libsyntax/ext') diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index d83bd8b9223..171bfd74a81 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -552,7 +552,10 @@ impl<'a> PluginMetadata<'a> { id: ast::DUMMY_NODE_ID, span: span, imported_from: imported_from, - export: false, // overridden in plugin/load.rs + // overridden in plugin/load.rs + export: false, + use_locally: false, + body: body, }); true diff --git a/src/librustc/plugin/load.rs b/src/librustc/plugin/load.rs index 93c97f6caa6..3a9083828fc 100644 --- a/src/librustc/plugin/load.rs +++ b/src/librustc/plugin/load.rs @@ -87,8 +87,8 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> { } // Parse the attributes relating to macro / plugin loading. - let mut load_macros = false; let mut load_registrar = false; + let mut macro_selection = Some(HashSet::new()); // None => load all let mut reexport = HashSet::new(); for attr in vi.attrs.iter() { let mut used = true; @@ -98,7 +98,22 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> { #[macro_use], #[plugin], and/or #[no_link]"); } "plugin" => load_registrar = true, - "macro_use" => load_macros = true, + "macro_use" => { + let names = attr.meta_item_list(); + if names.is_none() { + // no names => load all + macro_selection = None; + } + if let (Some(sel), Some(names)) = (macro_selection.as_mut(), names) { + for name in names.iter() { + if let ast::MetaWord(ref name) = name.node { + sel.insert(name.clone()); + } else { + self.sess.span_err(name.span, "bad macro import"); + } + } + } + } "macro_reexport" => { let names = match attr.meta_item_list() { Some(names) => names, @@ -126,6 +141,11 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> { let mut macros = vec![]; let mut registrar = None; + let load_macros = match macro_selection.as_ref() { + Some(sel) => sel.len() != 0 || reexport.len() != 0, + None => true, + }; + if load_macros || load_registrar { let pmd = self.reader.read_plugin_metadata(vi); if load_macros { @@ -137,9 +157,12 @@ impl<'a, 'v> Visitor<'v> for PluginLoader<'a> { } for mut def in macros.into_iter() { - if reexport.contains(&token::get_ident(def.ident)) { - def.export = true; - } + let name = token::get_ident(def.ident); + def.use_locally = match macro_selection.as_ref() { + None => true, + Some(sel) => sel.contains(&name), + }; + def.export = reexport.contains(&name); self.plugins.macros.push(def); } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index e34060a73c1..0f90e31c17e 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1709,6 +1709,7 @@ pub struct MacroDef { pub span: Span, pub imported_from: Option, pub export: bool, + pub use_locally: bool, pub body: Vec, } diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs index 815159e94c8..91ae7396ea4 100644 --- a/src/libsyntax/ext/base.rs +++ b/src/libsyntax/ext/base.rs @@ -574,8 +574,10 @@ impl<'a> ExtCtxt<'a> { if def.export { self.exported_macros.push(def.clone()); } - let ext = macro_rules::compile(self, &def); - self.syntax_env.insert(def.ident.name, ext); + if def.use_locally { + let ext = macro_rules::compile(self, &def); + self.syntax_env.insert(def.ident.name, ext); + } } /// Emit `msg` attached to `sp`, and stop compilation immediately. diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index 6c2b0610fa0..d3f2e0ea095 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -636,6 +636,7 @@ pub fn expand_item_mac(it: P, span: it.span, imported_from: None, export: attr::contains_name(it.attrs.as_slice(), "macro_export"), + use_locally: true, body: tts, }; fld.cx.insert_macro(def); diff --git a/src/test/auxiliary/macro_reexport_2_no_use.rs b/src/test/auxiliary/macro_reexport_2_no_use.rs new file mode 100644 index 00000000000..63142b0a699 --- /dev/null +++ b/src/test/auxiliary/macro_reexport_2_no_use.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![crate_type = "dylib"] + +#[macro_reexport(reexported)] +#[no_link] +extern crate macro_reexport_1; diff --git a/src/test/auxiliary/two_macros.rs b/src/test/auxiliary/two_macros.rs new file mode 100644 index 00000000000..39393b77f25 --- /dev/null +++ b/src/test/auxiliary/two_macros.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// force-host + +#![feature(macro_rules)] + +#[macro_export] +macro_rules! macro_one { () => ("one") } + +#[macro_export] +macro_rules! macro_two { () => ("two") } diff --git a/src/test/compile-fail/empty-macro-use.rs b/src/test/compile-fail/empty-macro-use.rs new file mode 100644 index 00000000000..fbf6287db94 --- /dev/null +++ b/src/test/compile-fail/empty-macro-use.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:two_macros.rs +// ignore-stage1 + +#[macro_use()] +extern crate two_macros; + +pub fn main() { + macro_two!(); //~ ERROR macro undefined +} diff --git a/src/test/compile-fail/macro-reexport-not-locally-visible.rs b/src/test/compile-fail/macro-reexport-not-locally-visible.rs new file mode 100644 index 00000000000..c8e59f98d3c --- /dev/null +++ b/src/test/compile-fail/macro-reexport-not-locally-visible.rs @@ -0,0 +1,20 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:macro_reexport_1.rs +// ignore-stage1 + +#[macro_reexport(reexported)] +#[no_link] +extern crate macro_reexport_1; + +fn main() { + assert_eq!(reexported!(), 3u); //~ ERROR macro undefined +} diff --git a/src/test/compile-fail/macro-use-bad-args-1.rs b/src/test/compile-fail/macro-use-bad-args-1.rs new file mode 100644 index 00000000000..a73c4adb71f --- /dev/null +++ b/src/test/compile-fail/macro-use-bad-args-1.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[macro_use(foo(bar))] //~ ERROR bad macro import +extern crate std; + +fn main() { +} diff --git a/src/test/compile-fail/macro-use-bad-args-2.rs b/src/test/compile-fail/macro-use-bad-args-2.rs new file mode 100644 index 00000000000..31efe857605 --- /dev/null +++ b/src/test/compile-fail/macro-use-bad-args-2.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#[macro_use(foo="bar")] //~ ERROR bad macro import +extern crate std; + +fn main() { +} diff --git a/src/test/compile-fail/macro-use-wrong-name.rs b/src/test/compile-fail/macro-use-wrong-name.rs new file mode 100644 index 00000000000..4e0486f0db7 --- /dev/null +++ b/src/test/compile-fail/macro-use-wrong-name.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:two_macros.rs +// ignore-stage1 + +#[macro_use(macro_one)] +extern crate two_macros; + +pub fn main() { + macro_two!(); //~ ERROR macro undefined +} diff --git a/src/test/compile-fail/missing-macro-use.rs b/src/test/compile-fail/missing-macro-use.rs new file mode 100644 index 00000000000..0153d71fb26 --- /dev/null +++ b/src/test/compile-fail/missing-macro-use.rs @@ -0,0 +1,18 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:two_macros.rs +// ignore-stage1 + +extern crate two_macros; + +pub fn main() { + macro_two!(); //~ ERROR macro undefined +} diff --git a/src/test/run-pass/macro-reexport-no-intermediate-use.rs b/src/test/run-pass/macro-reexport-no-intermediate-use.rs new file mode 100644 index 00000000000..77ef9421273 --- /dev/null +++ b/src/test/run-pass/macro-reexport-no-intermediate-use.rs @@ -0,0 +1,20 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:macro_reexport_1.rs +// aux-build:macro_reexport_2_no_use.rs +// ignore-stage1 + +#[macro_use] #[no_link] +extern crate macro_reexport_2_no_use; + +fn main() { + assert_eq!(reexported!(), 3u); +} diff --git a/src/test/run-pass/macro-use-all-and-none.rs b/src/test/run-pass/macro-use-all-and-none.rs new file mode 100644 index 00000000000..b46910290a8 --- /dev/null +++ b/src/test/run-pass/macro-use-all-and-none.rs @@ -0,0 +1,21 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:two_macros.rs +// ignore-stage1 + +#[macro_use] +#[macro_use()] +extern crate two_macros; + +pub fn main() { + macro_one!(); + macro_two!(); +} diff --git a/src/test/run-pass/macro-use-all.rs b/src/test/run-pass/macro-use-all.rs new file mode 100644 index 00000000000..cf72d2c6230 --- /dev/null +++ b/src/test/run-pass/macro-use-all.rs @@ -0,0 +1,20 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:two_macros.rs +// ignore-stage1 + +#[macro_use] +extern crate two_macros; + +pub fn main() { + macro_one!(); + macro_two!(); +} diff --git a/src/test/run-pass/macro-use-both.rs b/src/test/run-pass/macro-use-both.rs new file mode 100644 index 00000000000..4b0814bef04 --- /dev/null +++ b/src/test/run-pass/macro-use-both.rs @@ -0,0 +1,20 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:two_macros.rs +// ignore-stage1 + +#[macro_use(macro_one, macro_two)] +extern crate two_macros; + +pub fn main() { + macro_one!(); + macro_two!(); +} diff --git a/src/test/run-pass/macro-use-one.rs b/src/test/run-pass/macro-use-one.rs new file mode 100644 index 00000000000..7911fec94da --- /dev/null +++ b/src/test/run-pass/macro-use-one.rs @@ -0,0 +1,19 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:two_macros.rs +// ignore-stage1 + +#[macro_use(macro_two)] +extern crate two_macros; + +pub fn main() { + macro_two!(); +} diff --git a/src/test/run-pass/two-macro-use.rs b/src/test/run-pass/two-macro-use.rs new file mode 100644 index 00000000000..51c0b75e8fb --- /dev/null +++ b/src/test/run-pass/two-macro-use.rs @@ -0,0 +1,21 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// aux-build:two_macros.rs +// ignore-stage1 + +#[macro_use(macro_one)] +#[macro_use(macro_two)] +extern crate two_macros; + +pub fn main() { + macro_one!(); + macro_two!(); +} -- cgit 1.4.1-3-g733a5 From c9f0ff3813a662197e262e64edb8302d2b4a3e75 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Fri, 2 Jan 2015 13:39:05 -0800 Subject: Reserve the keyword 'macro' --- src/doc/reference.md | 12 ++++++------ src/etc/vim/syntax/rust.vim | 2 +- src/librustc_back/svh.rs | 14 +++++++------- src/librustc_driver/pretty.rs | 4 ++-- src/libsyntax/ext/expand.rs | 12 ++++++------ src/libsyntax/feature_gate.rs | 4 ++-- src/libsyntax/fold.rs | 8 ++++---- src/libsyntax/parse/parser.rs | 6 +++--- src/libsyntax/parse/token.rs | 1 + src/libsyntax/show_span.rs | 4 ++-- src/libsyntax/visit.rs | 12 ++++++------ src/test/compile-fail/macro-keyword.rs | 15 +++++++++++++++ 12 files changed, 55 insertions(+), 39 deletions(-) create mode 100644 src/test/compile-fail/macro-keyword.rs (limited to 'src/libsyntax/ext') diff --git a/src/doc/reference.md b/src/doc/reference.md index d7930285260..e2134cdebef 100644 --- a/src/doc/reference.md +++ b/src/doc/reference.md @@ -193,12 +193,12 @@ grammar as double-quoted strings. Other tokens have exact rules given. | break | const | continue | crate | do | | else | enum | extern | false | final | | fn | for | if | impl | in | -| let | loop | match | mod | move | -| mut | offsetof | override | priv | pub | -| pure | ref | return | sizeof | static | -| self | struct | super | true | trait | -| type | typeof | unsafe | unsized | use | -| virtual | where | while | yield | +| let | loop | macro | match | mod | +| move | mut | offsetof | override | priv | +| pub | pure | ref | return | sizeof | +| static | self | struct | super | true | +| trait | type | typeof | unsafe | unsized | +| use | virtual | where | while | yield | Each of these keywords has special meaning in its grammar, and all of them are diff --git a/src/etc/vim/syntax/rust.vim b/src/etc/vim/syntax/rust.vim index 5588152a244..270459e8880 100644 --- a/src/etc/vim/syntax/rust.vim +++ b/src/etc/vim/syntax/rust.vim @@ -56,7 +56,7 @@ syn match rustMacroRepeatCount ".\?[*+]" contained syn match rustMacroVariable "$\w\+" " Reserved (but not yet used) keywords {{{2 -syn keyword rustReservedKeyword alignof be do offsetof priv pure sizeof typeof unsized yield abstract final override +syn keyword rustReservedKeyword alignof be do offsetof priv pure sizeof typeof unsized yield abstract final override macro " Built-in types {{{2 syn keyword rustType int uint float char bool u8 u16 u32 u64 f32 diff --git a/src/librustc_back/svh.rs b/src/librustc_back/svh.rs index 2ae88aa4476..86bd74d3f85 100644 --- a/src/librustc_back/svh.rs +++ b/src/librustc_back/svh.rs @@ -327,11 +327,11 @@ mod svh_visitor { impl<'a, 'v> Visitor<'v> for StrictVersionHashVisitor<'a> { - fn visit_mac(&mut self, macro: &Mac) { + fn visit_mac(&mut self, mac: &Mac) { // macro invocations, namely macro_rules definitions, // *can* appear as items, even in the expanded crate AST. - if macro_name(macro).get() == "macro_rules" { + if macro_name(mac).get() == "macro_rules" { // Pretty-printing definition to a string strips out // surface artifacts (currently), such as the span // information, yielding a content-based hash. @@ -341,7 +341,7 @@ mod svh_visitor { // trees might be faster. Implementing this is far // easier in short term. let macro_defn_as_string = pprust::to_string(|pp_state| { - pp_state.print_mac(macro, token::Paren) + pp_state.print_mac(mac, token::Paren) }); macro_defn_as_string.hash(self.st); } else { @@ -349,14 +349,14 @@ mod svh_visitor { // invocation at this stage except `macro_rules!`. panic!("reached macro somehow: {}", pprust::to_string(|pp_state| { - pp_state.print_mac(macro, token::Paren) + pp_state.print_mac(mac, token::Paren) })); } - visit::walk_mac(self, macro); + visit::walk_mac(self, mac); - fn macro_name(macro: &Mac) -> token::InternedString { - match ¯o.node { + fn macro_name(mac: &Mac) -> token::InternedString { + match &mac.node { &MacInvocTT(ref path, ref _tts, ref _stx_ctxt) => { let s = path.segments[]; assert_eq!(s.len(), 1); diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index d972229e7c7..61fd7d16ab7 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -484,8 +484,8 @@ impl fold::Folder for ReplaceBodyWithLoop { // in general the pretty printer processes unexpanded code, so // we override the default `fold_mac` method which panics. - fn fold_mac(&mut self, _macro: ast::Mac) -> ast::Mac { - fold::noop_fold_mac(_macro, self) + fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { + fold::noop_fold_mac(mac, self) } } diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d3f2e0ea095..8decedf289a 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -986,8 +986,8 @@ impl<'a> Folder for IdentRenamer<'a> { ctxt: mtwt::apply_renames(self.renames, id.ctxt), } } - fn fold_mac(&mut self, macro: ast::Mac) -> ast::Mac { - fold::noop_fold_mac(macro, self) + fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { + fold::noop_fold_mac(mac, self) } } @@ -1023,8 +1023,8 @@ impl<'a> Folder for PatIdentRenamer<'a> { _ => unreachable!() }) } - fn fold_mac(&mut self, macro: ast::Mac) -> ast::Mac { - fold::noop_fold_mac(macro, self) + fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { + fold::noop_fold_mac(mac, self) } } @@ -1286,8 +1286,8 @@ struct MacroExterminator<'a>{ } impl<'a, 'v> Visitor<'v> for MacroExterminator<'a> { - fn visit_mac(&mut self, macro: &ast::Mac) { - self.sess.span_diagnostic.span_bug(macro.span, + fn visit_mac(&mut self, mac: &ast::Mac) { + self.sess.span_diagnostic.span_bug(mac.span, "macro exterminator: expected AST \ with no macro invocations"); } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index e41fef4e778..28265b8e7c2 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -165,8 +165,8 @@ struct MacroVisitor<'a> { } impl<'a, 'v> Visitor<'v> for MacroVisitor<'a> { - fn visit_mac(&mut self, macro: &ast::Mac) { - let ast::MacInvocTT(ref path, _, _) = macro.node; + fn visit_mac(&mut self, mac: &ast::Mac) { + let ast::MacInvocTT(ref path, _, _) = mac.node; let id = path.segments.last().unwrap().identifier; if id == token::str_to_ident("macro_rules") { diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs index 6b5d333ef8f..aa4b04b2879 100644 --- a/src/libsyntax/fold.rs +++ b/src/libsyntax/fold.rs @@ -194,13 +194,13 @@ pub trait Folder : Sized { noop_fold_local(l, self) } - fn fold_mac(&mut self, _macro: Mac) -> Mac { + fn fold_mac(&mut self, _mac: Mac) -> Mac { panic!("fold_mac disabled by default"); // NB: see note about macros above. // if you really want a folder that // works on macros, use this // definition in your trait impl: - // fold::noop_fold_mac(_macro, self) + // fold::noop_fold_mac(_mac, self) } fn fold_explicit_self(&mut self, es: ExplicitSelf) -> ExplicitSelf { @@ -1487,8 +1487,8 @@ mod test { fn fold_ident(&mut self, _: ast::Ident) -> ast::Ident { token::str_to_ident("zz") } - fn fold_mac(&mut self, macro: ast::Mac) -> ast::Mac { - fold::noop_fold_mac(macro, self) + fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac { + fold::noop_fold_mac(mac, self) } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 5539abb16b4..24011df7acb 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -3881,13 +3881,13 @@ impl<'a> Parser<'a> { &mut stmts, &mut expr); } - StmtMac(macro, MacStmtWithoutBraces) => { + StmtMac(mac, MacStmtWithoutBraces) => { // statement macro without braces; might be an // expr depending on whether a semicolon follows match self.token { token::Semi => { stmts.push(P(Spanned { - node: StmtMac(macro, + node: StmtMac(mac, MacStmtWithSemicolon), span: span, })); @@ -3896,7 +3896,7 @@ impl<'a> Parser<'a> { _ => { let e = self.mk_mac_expr(span.lo, span.hi, - macro.and_then(|m| m.node)); + mac.and_then(|m| m.node)); let e = self.parse_dot_or_call_expr_with(e); self.handle_expression_like_statement( diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index a653190cffd..094aacf3207 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -574,6 +574,7 @@ declare_special_idents_and_keywords! { (56, Abstract, "abstract"); (57, Final, "final"); (58, Override, "override"); + (59, Macro, "macro"); } } diff --git a/src/libsyntax/show_span.rs b/src/libsyntax/show_span.rs index 354ba854b10..e7c9101ebc6 100644 --- a/src/libsyntax/show_span.rs +++ b/src/libsyntax/show_span.rs @@ -28,8 +28,8 @@ impl<'a, 'v> Visitor<'v> for ShowSpanVisitor<'a> { visit::walk_expr(self, e); } - fn visit_mac(&mut self, macro: &ast::Mac) { - visit::walk_mac(self, macro); + fn visit_mac(&mut self, mac: &ast::Mac) { + visit::walk_mac(self, mac); } } diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index 054a288a69e..888c0251d76 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -115,13 +115,13 @@ pub trait Visitor<'v> : Sized { fn visit_explicit_self(&mut self, es: &'v ExplicitSelf) { walk_explicit_self(self, es) } - fn visit_mac(&mut self, _macro: &'v Mac) { + fn visit_mac(&mut self, _mac: &'v Mac) { panic!("visit_mac disabled by default"); // NB: see note about macros above. // if you really want a visitor that // works on macros, use this // definition in your trait impl: - // visit::walk_mac(self, _macro) + // visit::walk_mac(self, _mac) } fn visit_path(&mut self, path: &'v Path, _id: ast::NodeId) { walk_path(self, path) @@ -334,7 +334,7 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) { visitor.visit_trait_item(method) } } - ItemMac(ref macro) => visitor.visit_mac(macro), + ItemMac(ref mac) => visitor.visit_mac(mac), } for attr in item.attrs.iter() { visitor.visit_attribute(attr); @@ -546,7 +546,7 @@ pub fn walk_pat<'v, V: Visitor<'v>>(visitor: &mut V, pattern: &'v Pat) { visitor.visit_pat(&**postpattern) } } - PatMac(ref macro) => visitor.visit_mac(macro), + PatMac(ref mac) => visitor.visit_mac(mac), } } @@ -746,7 +746,7 @@ pub fn walk_stmt<'v, V: Visitor<'v>>(visitor: &mut V, statement: &'v Stmt) { StmtExpr(ref expression, _) | StmtSemi(ref expression, _) => { visitor.visit_expr(&**expression) } - StmtMac(ref macro, _) => visitor.visit_mac(&**macro), + StmtMac(ref mac, _) => visitor.visit_mac(&**mac), } } @@ -893,7 +893,7 @@ pub fn walk_expr<'v, V: Visitor<'v>>(visitor: &mut V, expression: &'v Expr) { ExprRet(ref optional_expression) => { walk_expr_opt(visitor, optional_expression) } - ExprMac(ref macro) => visitor.visit_mac(macro), + ExprMac(ref mac) => visitor.visit_mac(mac), ExprParen(ref subexpression) => { visitor.visit_expr(&**subexpression) } diff --git a/src/test/compile-fail/macro-keyword.rs b/src/test/compile-fail/macro-keyword.rs new file mode 100644 index 00000000000..9d4ec9c176c --- /dev/null +++ b/src/test/compile-fail/macro-keyword.rs @@ -0,0 +1,15 @@ +// Copyright 2015 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +fn macro() { //~ ERROR `macro` is a reserved keyword +} + +pub fn main() { +} -- cgit 1.4.1-3-g733a5 From 416137eb3186c05b7a601e94cde354e9b3ec0a78 Mon Sep 17 00:00:00 2001 From: Keegan McAllister Date: Fri, 2 Jan 2015 14:44:21 -0800 Subject: Modernize macro_rules! invocations macro_rules! is like an item that defines a macro. Other items don't have a trailing semicolon, or use a paren-delimited body. If there's an argument for matching the invocation syntax, e.g. parentheses for an expr macro, then I think that applies more strongly to the *inner* delimiters on the LHS, wrapping the individual argument patterns. --- src/grammar/verify.rs | 4 +- src/libcollections/slice.rs | 8 +- src/libcollections/str.rs | 8 +- src/libcollections/string.rs | 4 +- src/libcore/result.rs | 4 +- src/libcore/str/mod.rs | 9 +- src/libcoretest/num/int_macros.rs | 4 +- src/libcoretest/num/uint_macros.rs | 5 +- src/librand/distributions/mod.rs | 4 +- src/librand/distributions/range.rs | 8 +- src/librand/isaac.rs | 141 +++++++++++---------- src/librustc/lint/context.rs | 36 +++--- src/librustc/middle/const_eval.rs | 4 +- src/librustc/middle/ty.rs | 4 +- src/librustc_back/sha2.rs | 8 +- src/librustc_back/target/mod.rs | 8 +- src/librustc_trans/trans/context.rs | 12 +- src/libstd/path/posix.rs | 68 +++++----- src/libstd/path/windows.rs | 76 +++++------ src/libsyntax/ext/deriving/cmp/eq.rs | 4 +- src/libsyntax/ext/deriving/cmp/ord.rs | 4 +- src/libsyntax/ext/deriving/mod.rs | 8 +- src/libsyntax/ext/tt/macro_rules.rs | 4 +- src/libterm/terminfo/parser/compiled.rs | 4 +- src/test/auxiliary/lint_stability.rs | 12 +- src/test/auxiliary/macro_crate_def_only.rs | 4 +- src/test/auxiliary/macro_crate_test.rs | 4 +- src/test/auxiliary/macro_export_inner_module.rs | 4 +- src/test/bench/core-std.rs | 5 +- src/test/compile-fail/gated-macro-rules.rs | 2 +- src/test/compile-fail/infinite-macro-expansion.rs | 8 +- src/test/compile-fail/issue-15167.rs | 2 +- src/test/compile-fail/issue-6596.rs | 4 +- .../compile-fail/liveness-return-last-stmt-semi.rs | 2 +- src/test/compile-fail/macro-inner-attributes.rs | 4 +- src/test/compile-fail/macro-match-nonterminal.rs | 2 +- src/test/compile-fail/macro-outer-attributes.rs | 4 +- src/test/compile-fail/macros-no-semicolon-items.rs | 1 - src/test/compile-fail/method-macro-backtrace.rs | 6 +- src/test/compile-fail/pattern-macro-hygiene.rs | 2 +- .../borrowck-macro-interaction-issue-6304.rs | 4 +- src/test/run-pass/cleanup-rvalue-scopes.rs | 8 +- src/test/run-pass/const-binops.rs | 4 +- src/test/run-pass/core-run-destroy.rs | 4 +- src/test/run-pass/deriving-in-macro.rs | 4 +- src/test/run-pass/exponential-notation.rs | 4 +- src/test/run-pass/html-literals.rs | 8 +- src/test/run-pass/ifmt.rs | 4 +- src/test/run-pass/intrinsics-math.rs | 4 +- src/test/run-pass/issue-15189.rs | 4 +- src/test/run-pass/issue-15221.rs | 10 +- src/test/run-pass/issue-5060.rs | 4 +- src/test/run-pass/issue-7911.rs | 4 +- src/test/run-pass/issue-8709.rs | 8 +- src/test/run-pass/issue-8851.rs | 4 +- src/test/run-pass/issue-9110.rs | 4 +- src/test/run-pass/issue-9129.rs | 4 +- src/test/run-pass/issue-9737.rs | 4 +- src/test/run-pass/lambda-var-hygiene.rs | 4 +- src/test/run-pass/let-var-hygiene.rs | 5 +- src/test/run-pass/macro-2.rs | 4 +- src/test/run-pass/macro-interpolation.rs | 4 +- ...ro-invocation-in-count-expr-fixed-array-type.rs | 4 +- src/test/run-pass/macro-multiple-items.rs | 4 +- src/test/run-pass/macro-nt-list.rs | 8 +- src/test/run-pass/macro-of-higher-order.rs | 6 +- src/test/run-pass/macro-pat.rs | 20 +-- src/test/run-pass/macro-stmt.rs | 12 +- src/test/run-pass/macro-with-attrs1.rs | 4 +- src/test/run-pass/macro-with-attrs2.rs | 4 +- .../run-pass/macro-with-braces-in-expr-position.rs | 2 +- src/test/run-pass/match-in-macro.rs | 4 +- src/test/run-pass/match-var-hygiene.rs | 4 +- src/test/run-pass/non-built-in-quote.rs | 2 +- src/test/run-pass/syntax-extension-source-utils.rs | 2 +- .../typeck-macro-interaction-issue-8852.rs | 4 +- 76 files changed, 361 insertions(+), 331 deletions(-) (limited to 'src/libsyntax/ext') diff --git a/src/grammar/verify.rs b/src/grammar/verify.rs index ad271d23090..2e8bce3f506 100644 --- a/src/grammar/verify.rs +++ b/src/grammar/verify.rs @@ -268,7 +268,7 @@ fn main() { assert!(rustc_tok.sp == antlr_tok.sp, "{} and {} have different spans", rustc_tok, antlr_tok); - macro_rules! matches ( + macro_rules! matches { ( $($x:pat),+ ) => ( match rustc_tok.tok { $($x => match antlr_tok.tok { @@ -284,7 +284,7 @@ fn main() { ref c => assert!(c == &antlr_tok.tok, "{} is not {}", rustc_tok, antlr_tok) } ) - ); + } matches!( token::Literal(token::Byte(..), _), diff --git a/src/libcollections/slice.rs b/src/libcollections/slice.rs index 3602bfc10c3..6a9abfbd22e 100644 --- a/src/libcollections/slice.rs +++ b/src/libcollections/slice.rs @@ -2460,13 +2460,13 @@ mod tests { #[test] fn test_show() { - macro_rules! test_show_vec( + macro_rules! test_show_vec { ($x:expr, $x_str:expr) => ({ let (x, x_str) = ($x, $x_str); assert_eq!(format!("{}", x), x_str); assert_eq!(format!("{}", x.as_slice()), x_str); }) - ); + } let empty: Vec = vec![]; test_show_vec!(empty, "[]"); test_show_vec!(vec![1i], "[1]"); @@ -2486,12 +2486,12 @@ mod tests { #[test] fn test_vec_default() { - macro_rules! t ( + macro_rules! t { ($ty:ty) => {{ let v: $ty = Default::default(); assert!(v.is_empty()); }} - ); + } t!(&[int]); t!(Vec); diff --git a/src/libcollections/str.rs b/src/libcollections/str.rs index ecf17820d2d..69403ccd88b 100644 --- a/src/libcollections/str.rs +++ b/src/libcollections/str.rs @@ -1838,7 +1838,9 @@ mod tests { #[test] fn test_is_utf16() { use unicode::str::is_utf16; - macro_rules! pos ( ($($e:expr),*) => { { $(assert!(is_utf16($e));)* } }); + macro_rules! pos { + ($($e:expr),*) => { { $(assert!(is_utf16($e));)* } } + } // non-surrogates pos!(&[0x0000], @@ -1858,7 +1860,9 @@ mod tests { &[0x0067, 0xd8ff, 0xddb7, 0x000f, 0xd900, 0xdc80]); // negative tests - macro_rules! neg ( ($($e:expr),*) => { { $(assert!(!is_utf16($e));)* } }); + macro_rules! neg { + ($($e:expr),*) => { { $(assert!(!is_utf16($e));)* } } + } neg!( // surrogate + regular unit diff --git a/src/libcollections/string.rs b/src/libcollections/string.rs index e7451331908..8fe636f8cd3 100644 --- a/src/libcollections/string.rs +++ b/src/libcollections/string.rs @@ -182,7 +182,7 @@ impl String { let byte = unsafe_get(v, i); i += 1; - macro_rules! error(() => ({ + macro_rules! error { () => ({ unsafe { if subseqidx != i_ { res.as_mut_vec().push_all(v[subseqidx..i_]); @@ -190,7 +190,7 @@ impl String { subseqidx = i; res.as_mut_vec().push_all(REPLACEMENT); } - })); + })} if byte < 128u8 { // subseqidx handles this diff --git a/src/libcore/result.rs b/src/libcore/result.rs index 7135faaa765..3ed0116c289 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -220,9 +220,9 @@ //! //! ``` //! # #![feature(macro_rules)] -//! macro_rules! try( +//! macro_rules! try { //! ($e:expr) => (match $e { Ok(e) => e, Err(e) => return Err(e) }) -//! ); +//! } //! # fn main() { } //! ``` //! diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index d069744f8da..02887024d00 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -948,17 +948,18 @@ fn run_utf8_validation_iterator(iter: &mut slice::Iter) let old = *iter; // restore the iterator we had at the start of this codepoint. - macro_rules! err (() => { { + macro_rules! err { () => {{ *iter = old; return Err(Utf8Error::InvalidByte(whole.len() - iter.as_slice().len())) - } }); - macro_rules! next ( () => { + }}} + + macro_rules! next { () => { match iter.next() { Some(a) => *a, // we needed data, but there was none: error! None => return Err(Utf8Error::TooShort), } - }); + }} let first = match iter.next() { Some(&b) => b, diff --git a/src/libcoretest/num/int_macros.rs b/src/libcoretest/num/int_macros.rs index 965ffde7097..b98432e26b2 100644 --- a/src/libcoretest/num/int_macros.rs +++ b/src/libcoretest/num/int_macros.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -macro_rules! int_module (($T:ty, $T_i:ident) => ( +macro_rules! int_module { ($T:ty, $T_i:ident) => ( #[cfg(test)] mod tests { use core::$T_i::*; @@ -203,4 +203,4 @@ mod tests { } } -)); +)} diff --git a/src/libcoretest/num/uint_macros.rs b/src/libcoretest/num/uint_macros.rs index eff238c816e..04d8fb15cf5 100644 --- a/src/libcoretest/num/uint_macros.rs +++ b/src/libcoretest/num/uint_macros.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -macro_rules! uint_module (($T:ty, $T_i:ident) => ( +macro_rules! uint_module { ($T:ty, $T_i:ident) => ( #[cfg(test)] mod tests { use core::$T_i::*; @@ -123,4 +123,5 @@ mod tests { assert!(5u.checked_div(0) == None); } } -)); + +)} diff --git a/src/librand/distributions/mod.rs b/src/librand/distributions/mod.rs index e684fcf40f7..2fdba8a6c4f 100644 --- a/src/librand/distributions/mod.rs +++ b/src/librand/distributions/mod.rs @@ -297,7 +297,7 @@ mod tests { // it doesn't do weird things to the RNG (so 0 maps to 0, 1 to // 1, internally; modulo a modulo operation). - macro_rules! t ( + macro_rules! t { ($items:expr, $expected:expr) => {{ let mut items = $items; let wc = WeightedChoice::new(items.as_mut_slice()); @@ -309,7 +309,7 @@ mod tests { assert_eq!(wc.ind_sample(&mut rng), val) } }} - ); + } t!(vec!(Weighted { weight: 1, item: 10i}), [10]); diff --git a/src/librand/distributions/range.rs b/src/librand/distributions/range.rs index 558fa201256..1038009522d 100644 --- a/src/librand/distributions/range.rs +++ b/src/librand/distributions/range.rs @@ -182,7 +182,7 @@ mod tests { #[test] fn test_integers() { let mut rng = ::test::rng(); - macro_rules! t ( + macro_rules! t { ($($ty:ty),*) => {{ $( let v: &[($ty, $ty)] = &[(0, 10), @@ -199,7 +199,7 @@ mod tests { } )* }} - ); + } t!(i8, i16, i32, i64, int, u8, u16, u32, u64, uint) } @@ -207,7 +207,7 @@ mod tests { #[test] fn test_floats() { let mut rng = ::test::rng(); - macro_rules! t ( + macro_rules! t { ($($ty:ty),*) => {{ $( let v: &[($ty, $ty)] = &[(0.0, 100.0), @@ -225,7 +225,7 @@ mod tests { } )* }} - ); + } t!(f32, f64) } diff --git a/src/librand/isaac.rs b/src/librand/isaac.rs index 53ae242c5e2..698730302b9 100644 --- a/src/librand/isaac.rs +++ b/src/librand/isaac.rs @@ -69,7 +69,7 @@ impl IsaacRng { let mut g = a; let mut h = a; - macro_rules! mix( + macro_rules! mix { () => {{ a^=b<<11; d+=a; b+=c; b^=c>>2; e+=b; c+=d; @@ -80,14 +80,14 @@ impl IsaacRng { g^=h<<8; b+=g; h+=a; h^=a>>9; c+=h; a+=b; }} - ); + } for _ in range(0u, 4) { mix!(); } if use_rsl { - macro_rules! memloop ( + macro_rules! memloop { ($arr:expr) => {{ for i in range_step(0, RAND_SIZE as uint, 8) { a+=$arr[i ]; b+=$arr[i+1]; @@ -101,7 +101,7 @@ impl IsaacRng { self.mem[i+6]=g; self.mem[i+7]=h; } }} - ); + } memloop!(self.rsl); memloop!(self.mem); @@ -129,41 +129,42 @@ impl IsaacRng { static MIDPOINT: uint = (RAND_SIZE / 2) as uint; - macro_rules! ind (($x:expr) => { - self.mem[(($x >> 2) as uint & ((RAND_SIZE - 1) as uint))] - }); + macro_rules! ind { + ($x:expr) => ( self.mem[(($x >> 2) as uint & ((RAND_SIZE - 1) as uint))] ) + } let r = [(0, MIDPOINT), (MIDPOINT, 0)]; for &(mr_offset, m2_offset) in r.iter() { - macro_rules! rngstepp( + macro_rules! rngstepp { ($j:expr, $shift:expr) => {{ - let base = $j; - let mix = a << $shift as uint; + let base = $j; + let mix = a << $shift as uint; - let x = self.mem[base + mr_offset]; - a = (a ^ mix) + self.mem[base + m2_offset]; - let y = ind!(x) + a + b; - self.mem[base + mr_offset] = y; + let x = self.mem[base + mr_offset]; + a = (a ^ mix) + self.mem[base + m2_offset]; + let y = ind!(x) + a + b; + self.mem[base + mr_offset] = y; - b = ind!(y >> RAND_SIZE_LEN as uint) + x; - self.rsl[base + mr_offset] = b; - }} - ); - macro_rules! rngstepn( + b = ind!(y >> RAND_SIZE_LEN as uint) + x; + self.rsl[base + mr_offset] = b; + }} + } + + macro_rules! rngstepn { ($j:expr, $shift:expr) => {{ - let base = $j; - let mix = a >> $shift as uint; + let base = $j; + let mix = a >> $shift as uint; - let x = self.mem[base + mr_offset]; - a = (a ^ mix) + self.mem[base + m2_offset]; - let y = ind!(x) + a + b; - self.mem[base + mr_offset] = y; + let x = self.mem[base + mr_offset]; + a = (a ^ mix) + self.mem[base + m2_offset]; + let y = ind!(x) + a + b; + self.mem[base + mr_offset] = y; - b = ind!(y >> RAND_SIZE_LEN as uint) + x; - self.rsl[base + mr_offset] = b; - }} - ); + b = ind!(y >> RAND_SIZE_LEN as uint) + x; + self.rsl[base + mr_offset] = b; + }} + } for i in range_step(0u, MIDPOINT, 4) { rngstepp!(i + 0, 13); @@ -294,15 +295,15 @@ impl Isaac64Rng { /// of `rsl` as a seed, otherwise construct one algorithmically (not /// randomly). fn init(&mut self, use_rsl: bool) { - macro_rules! init ( + macro_rules! init { ($var:ident) => ( let mut $var = 0x9e3779b97f4a7c13; ) - ); + } init!(a); init!(b); init!(c); init!(d); init!(e); init!(f); init!(g); init!(h); - macro_rules! mix( + macro_rules! mix { () => {{ a-=e; f^=h>>9; h+=a; b-=f; g^=a<<9; a+=b; @@ -313,14 +314,14 @@ impl Isaac64Rng { g-=c; d^=f>>17; f+=g; h-=d; e^=g<<14; g+=h; }} - ); + } for _ in range(0u, 4) { mix!(); } if use_rsl { - macro_rules! memloop ( + macro_rules! memloop { ($arr:expr) => {{ for i in range(0, RAND_SIZE_64 / 8).map(|i| i * 8) { a+=$arr[i ]; b+=$arr[i+1]; @@ -334,7 +335,7 @@ impl Isaac64Rng { self.mem[i+6]=g; self.mem[i+7]=h; } }} - ); + } memloop!(self.rsl); memloop!(self.mem); @@ -359,49 +360,51 @@ impl Isaac64Rng { let mut b = self.b + self.c; const MIDPOINT: uint = RAND_SIZE_64 / 2; const MP_VEC: [(uint, uint); 2] = [(0,MIDPOINT), (MIDPOINT, 0)]; - macro_rules! ind ( + macro_rules! ind { ($x:expr) => { *self.mem.get_unchecked(($x as uint >> 3) & (RAND_SIZE_64 - 1)) } - ); + } for &(mr_offset, m2_offset) in MP_VEC.iter() { for base in range(0, MIDPOINT / 4).map(|i| i * 4) { - macro_rules! rngstepp( + macro_rules! rngstepp { ($j:expr, $shift:expr) => {{ - let base = base + $j; - let mix = a ^ (a << $shift as uint); - let mix = if $j == 0 {!mix} else {mix}; - - unsafe { - let x = *self.mem.get_unchecked(base + mr_offset); - a = mix + *self.mem.get_unchecked(base + m2_offset); - let y = ind!(x) + a + b; - *self.mem.get_unchecked_mut(base + mr_offset) = y; - - b = ind!(y >> RAND_SIZE_64_LEN) + x; - *self.rsl.get_unchecked_mut(base + mr_offset) = b; - } - }} - ); - macro_rules! rngstepn( + let base = base + $j; + let mix = a ^ (a << $shift as uint); + let mix = if $j == 0 {!mix} else {mix}; + + unsafe { + let x = *self.mem.get_unchecked(base + mr_offset); + a = mix + *self.mem.get_unchecked(base + m2_offset); + let y = ind!(x) + a + b; + *self.mem.get_unchecked_mut(base + mr_offset) = y; + + b = ind!(y >> RAND_SIZE_64_LEN) + x; + *self.rsl.get_unchecked_mut(base + mr_offset) = b; + } + }} + } + + macro_rules! rngstepn { ($j:expr, $shift:expr) => {{ - let base = base + $j; - let mix = a ^ (a >> $shift as uint); - let mix = if $j == 0 {!mix} else {mix}; - - unsafe { - let x = *self.mem.get_unchecked(base + mr_offset); - a = mix + *self.mem.get_unchecked(base + m2_offset); - let y = ind!(x) + a + b; - *self.mem.get_unchecked_mut(base + mr_offset) = y; - - b = ind!(y >> RAND_SIZE_64_LEN) + x; - *self.rsl.get_unchecked_mut(base + mr_offset) = b; - } - }} - ); + let base = base + $j; + let mix = a ^ (a >> $shift as uint); + let mix = if $j == 0 {!mix} else {mix}; + + unsafe { + let x = *self.mem.get_unchecked(base + mr_offset); + a = mix + *self.mem.get_unchecked(base + m2_offset); + let y = ind!(x) + a + b; + *self.mem.get_unchecked_mut(base + mr_offset) = y; + + b = ind!(y >> RAND_SIZE_64_LEN) + x; + *self.rsl.get_unchecked_mut(base + mr_offset) = b; + } + }} + } + rngstepp!(0u, 21); rngstepn!(1u, 5); rngstepp!(2u, 12); diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 69e5b4889c2..c070bed2be2 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -167,21 +167,27 @@ impl LintStore { } pub fn register_builtin(&mut self, sess: Option<&Session>) { - macro_rules! add_builtin ( ( $sess:ident, $($name:ident),*, ) => ( - {$( - self.register_pass($sess, false, box builtin::$name as LintPassObject); - )*} - )); - - macro_rules! add_builtin_with_new ( ( $sess:ident, $($name:ident),*, ) => ( - {$( - self.register_pass($sess, false, box builtin::$name::new() as LintPassObject); - )*} - )); - - macro_rules! add_lint_group ( ( $sess:ident, $name:expr, $($lint:ident),* ) => ( - self.register_group($sess, false, $name, vec![$(LintId::of(builtin::$lint)),*]); - )); + macro_rules! add_builtin { + ($sess:ident, $($name:ident),*,) => ( + {$( + self.register_pass($sess, false, box builtin::$name as LintPassObject); + )*} + ) + } + + macro_rules! add_builtin_with_new { + ($sess:ident, $($name:ident),*,) => ( + {$( + self.register_pass($sess, false, box builtin::$name::new() as LintPassObject); + )*} + ) + } + + macro_rules! add_lint_group { + ($sess:ident, $name:expr, $($lint:ident),*) => ( + self.register_group($sess, false, $name, vec![$(LintId::of(builtin::$lint)),*]); + ) + } add_builtin!(sess, HardwiredLints, diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index 6671f0f72f6..f50d629dae7 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -503,7 +503,7 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result ( $intermediate_ty:ty, @@ -524,7 +524,7 @@ pub fn eval_const_expr_partial(tcx: &ty::ctxt, e: &Expr) -> Result Err("can't cast this type".to_string()) }) - ); + } eval_const_expr_partial(tcx, &**base) .and_then(|val| define_casts!(val, { diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 58348443822..b1098c5d9f7 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -6237,8 +6237,8 @@ pub fn hash_crate_independent<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh) - return state.result(); fn helper<'tcx>(tcx: &ctxt<'tcx>, ty: Ty<'tcx>, svh: &Svh, state: &mut sip::SipState) { - macro_rules! byte( ($b:expr) => { ($b as u8).hash(state) } ); - macro_rules! hash( ($e:expr) => { $e.hash(state) } ); + macro_rules! byte { ($b:expr) => { ($b as u8).hash(state) } } + macro_rules! hash { ($e:expr) => { $e.hash(state) } } let region = |&: state: &mut sip::SipState, r: Region| { match r { diff --git a/src/librustc_back/sha2.rs b/src/librustc_back/sha2.rs index 1e55f442fb9..d606c5158d0 100644 --- a/src/librustc_back/sha2.rs +++ b/src/librustc_back/sha2.rs @@ -346,12 +346,12 @@ impl Engine256State { // Sha-512 and Sha-256 use basically the same calculations which are implemented // by these macros. Inlining the calculations seems to result in better generated code. - macro_rules! schedule_round( ($t:expr) => ( + macro_rules! schedule_round { ($t:expr) => ( w[$t] = sigma1(w[$t - 2]) + w[$t - 7] + sigma0(w[$t - 15]) + w[$t - 16]; ) - ); + } - macro_rules! sha2_round( + macro_rules! sha2_round { ($A:ident, $B:ident, $C:ident, $D:ident, $E:ident, $F:ident, $G:ident, $H:ident, $K:ident, $t:expr) => ( { @@ -360,7 +360,7 @@ impl Engine256State { $H += sum0($A) + maj($A, $B, $C); } ) - ); + } read_u32v_be(w.slice_mut(0, 16), data); diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index d53f97c3a04..f14583bb9aa 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -239,7 +239,7 @@ impl Target { options: Default::default(), }; - macro_rules! key ( + macro_rules! key { ($key_name:ident) => ( { let name = (stringify!($key_name)).replace("_", "-"); obj.find(name[]).map(|o| o.as_string() @@ -257,7 +257,7 @@ impl Target { ) ); } ); - ); + } key!(cpu); key!(linker); @@ -305,7 +305,7 @@ impl Target { } // this would use a match if stringify! were allowed in pattern position - macro_rules! load_specific ( + macro_rules! load_specific { ( $($name:ident),+ ) => ( { let target = target.replace("-", "_"); @@ -326,7 +326,7 @@ impl Target { } } ) - ); + } load_specific!( x86_64_unknown_linux_gnu, diff --git a/src/librustc_trans/trans/context.rs b/src/librustc_trans/trans/context.rs index e5a0e2e9234..b121dbec011 100644 --- a/src/librustc_trans/trans/context.rs +++ b/src/librustc_trans/trans/context.rs @@ -741,7 +741,7 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { } fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option { - macro_rules! ifn ( + macro_rules! ifn { ($name:expr fn() -> $ret:expr) => ( if *key == $name { let f = base::decl_cdecl_fn( @@ -759,10 +759,10 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option (Type::struct_(ccx, &[$($field_ty),*], false)) - ); + } let i8p = Type::i8p(ccx); let void = Type::void(ccx); @@ -883,7 +883,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option $ret:expr) => ( if unsafe { llvm::LLVMVersionMinor() >= 4 } { // The `if key == $name` is already in ifn! @@ -896,7 +896,7 @@ fn declare_intrinsic(ccx: &CrateContext, key: & &'static str) -> Option t_f32); compatible_ifn!("llvm.copysign.f64", copysign(t_f64, t_f64) -> t_f64); diff --git a/src/libstd/path/posix.rs b/src/libstd/path/posix.rs index ae82e201cb8..a78dfe3edce 100644 --- a/src/libstd/path/posix.rs +++ b/src/libstd/path/posix.rs @@ -558,7 +558,7 @@ mod tests { t!(b"foo/\xFFbar", filename_display, "\u{FFFD}bar"); t!(b"/", filename_display, ""); - macro_rules! t( + macro_rules! t { ($path:expr, $exp:expr) => ( { let path = Path::new($path); @@ -573,7 +573,7 @@ mod tests { assert!(mo.as_slice() == $exp); } ) - ); + } t!("foo", "foo"); t!(b"foo\x80", "foo\u{FFFD}"); @@ -585,7 +585,7 @@ mod tests { #[test] fn test_display() { - macro_rules! t( + macro_rules! t { ($path:expr, $exp:expr, $expf:expr) => ( { let path = Path::new($path); @@ -595,7 +595,7 @@ mod tests { assert!(f == $expf); } ) - ); + } t!(b"foo", "foo", "foo"); t!(b"foo/bar", "foo/bar", "bar"); @@ -608,7 +608,7 @@ mod tests { #[test] fn test_components() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $op:ident, $exp:expr) => ( { let path = Path::new($path); @@ -629,7 +629,7 @@ mod tests { assert!(path.$op() == $exp); } ); - ); + } t!(v: b"a/b/c", filename, Some(b"c")); t!(v: b"a/b/c\xFF", filename, Some(b"c\xFF")); @@ -692,7 +692,7 @@ mod tests { #[test] fn test_push() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $join:expr) => ( { let path = $path; @@ -703,7 +703,7 @@ mod tests { assert!(p1 == p2.join(join)); } ) - ); + } t!(s: "a/b/c", ".."); t!(s: "/a/b/c", "d"); @@ -713,7 +713,7 @@ mod tests { #[test] fn test_push_path() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $push:expr, $exp:expr) => ( { let mut p = Path::new($path); @@ -722,7 +722,7 @@ mod tests { assert!(p.as_str() == Some($exp)); } ) - ); + } t!(s: "a/b/c", "d", "a/b/c/d"); t!(s: "/a/b/c", "d", "/a/b/c/d"); @@ -734,7 +734,7 @@ mod tests { #[test] fn test_push_many() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $push:expr, $exp:expr) => ( { let mut p = Path::new($path); @@ -749,7 +749,7 @@ mod tests { assert!(p.as_vec() == $exp); } ) - ); + } t!(s: "a/b/c", ["d", "e"], "a/b/c/d/e"); t!(s: "a/b/c", ["d", "/e"], "/e"); @@ -762,7 +762,7 @@ mod tests { #[test] fn test_pop() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $left:expr, $right:expr) => ( { let mut p = Path::new($path); @@ -779,7 +779,7 @@ mod tests { assert!(result == $right); } ) - ); + } t!(b: b"a/b/c", b"a/b", true); t!(b: b"a", b".", true); @@ -818,7 +818,7 @@ mod tests { #[test] fn test_join_path() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $join:expr, $exp:expr) => ( { let path = Path::new($path); @@ -827,7 +827,7 @@ mod tests { assert!(res.as_str() == Some($exp)); } ) - ); + } t!(s: "a/b/c", "..", "a/b"); t!(s: "/a/b/c", "d", "/a/b/c/d"); @@ -839,7 +839,7 @@ mod tests { #[test] fn test_join_many() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $join:expr, $exp:expr) => ( { let path = Path::new($path); @@ -854,7 +854,7 @@ mod tests { assert!(res.as_vec() == $exp); } ) - ); + } t!(s: "a/b/c", ["d", "e"], "a/b/c/d/e"); t!(s: "a/b/c", ["..", "d"], "a/b/d"); @@ -917,7 +917,7 @@ mod tests { #[test] fn test_setters() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $set:ident, $with:ident, $arg:expr) => ( { let path = $path; @@ -938,7 +938,7 @@ mod tests { assert!(p1 == p2.$with(arg)); } ) - ); + } t!(v: b"a/b/c", set_filename, with_filename, b"d"); t!(v: b"/", set_filename, with_filename, b"foo"); @@ -961,7 +961,7 @@ mod tests { #[test] fn test_getters() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $filename:expr, $dirname:expr, $filestem:expr, $ext:expr) => ( { let path = $path; @@ -992,7 +992,7 @@ mod tests { assert!(path.extension() == $ext); } ) - ); + } t!(v: Path::new(b"a/b/c"), Some(b"c"), b"a/b", Some(b"c"), None); t!(v: Path::new(b"a/b/\xFF"), Some(b"\xFF"), b"a/b", Some(b"\xFF"), None); @@ -1031,7 +1031,7 @@ mod tests { #[test] fn test_is_absolute() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $abs:expr, $rel:expr) => ( { let path = Path::new($path); @@ -1039,7 +1039,7 @@ mod tests { assert_eq!(path.is_relative(), $rel); } ) - ); + } t!(s: "a/b/c", false, true); t!(s: "/a/b/c", true, false); t!(s: "a", false, true); @@ -1052,7 +1052,7 @@ mod tests { #[test] fn test_is_ancestor_of() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $dest:expr, $exp:expr) => ( { let path = Path::new($path); @@ -1060,7 +1060,7 @@ mod tests { assert_eq!(path.is_ancestor_of(&dest), $exp); } ) - ); + } t!(s: "a/b/c", "a/b/c/d", true); t!(s: "a/b/c", "a/b/c", true); @@ -1086,7 +1086,7 @@ mod tests { #[test] fn test_ends_with_path() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $child:expr, $exp:expr) => ( { let path = Path::new($path); @@ -1101,7 +1101,7 @@ mod tests { assert_eq!(path.ends_with_path(&child), $exp); } ) - ); + } t!(s: "a/b/c", "c", true); t!(s: "a/b/c", "d", false); @@ -1125,7 +1125,7 @@ mod tests { #[test] fn test_path_relative_from() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $other:expr, $exp:expr) => ( { let path = Path::new($path); @@ -1134,7 +1134,7 @@ mod tests { assert_eq!(res.as_ref().and_then(|x| x.as_str()), $exp); } ) - ); + } t!(s: "a/b/c", "a/b", Some("c")); t!(s: "a/b/c", "a/b/d", Some("../c")); @@ -1170,7 +1170,7 @@ mod tests { #[test] fn test_components_iter() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $exp:expr) => ( { let path = Path::new($path); @@ -1196,7 +1196,7 @@ mod tests { assert_eq!(comps, exp) } ) - ); + } t!(b: b"a/b/c", [b"a", b"b", b"c"]); t!(b: b"/\xFF/a/\x80", [b"\xFF", b"a", b"\x80"]); @@ -1216,7 +1216,7 @@ mod tests { #[test] fn test_str_components() { - macro_rules! t( + macro_rules! t { (b: $arg:expr, $exp:expr) => ( { let path = Path::new($arg); @@ -1228,7 +1228,7 @@ mod tests { assert_eq!(comps, exp); } ) - ); + } t!(b: b"a/b/c", [Some("a"), Some("b"), Some("c")]); t!(b: b"/\xFF/a/\x80", [None, Some("a"), None]); diff --git a/src/libstd/path/windows.rs b/src/libstd/path/windows.rs index cf8bc0e6242..30ed07446a4 100644 --- a/src/libstd/path/windows.rs +++ b/src/libstd/path/windows.rs @@ -1149,7 +1149,7 @@ mod tests { #[test] fn test_parse_prefix() { - macro_rules! t( + macro_rules! t { ($path:expr, $exp:expr) => ( { let path = $path; @@ -1159,7 +1159,7 @@ mod tests { "parse_prefix(\"{}\"): expected {}, found {}", path, exp, res); } ) - ); + } t!("\\\\SERVER\\share\\foo", Some(UNCPrefix(6,5))); t!("\\\\", None); @@ -1348,7 +1348,7 @@ mod tests { #[test] fn test_display() { - macro_rules! t( + macro_rules! t { ($path:expr, $exp:expr, $expf:expr) => ( { let path = Path::new($path); @@ -1358,7 +1358,7 @@ mod tests { assert_eq!(f, $expf); } ) - ); + } t!("foo", "foo", "foo"); t!("foo\\bar", "foo\\bar", "bar"); @@ -1367,7 +1367,7 @@ mod tests { #[test] fn test_components() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $op:ident, $exp:expr) => ( { let path = $path; @@ -1390,7 +1390,7 @@ mod tests { assert!(path.$op() == $exp); } ) - ); + } t!(v: b"a\\b\\c", filename, Some(b"c")); t!(s: "a\\b\\c", filename_str, "c"); @@ -1490,7 +1490,7 @@ mod tests { #[test] fn test_push() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $join:expr) => ( { let path = $path; @@ -1501,7 +1501,7 @@ mod tests { assert!(p1 == p2.join(join)); } ) - ); + } t!(s: "a\\b\\c", ".."); t!(s: "\\a\\b\\c", "d"); @@ -1525,7 +1525,7 @@ mod tests { #[test] fn test_push_path() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $push:expr, $exp:expr) => ( { let mut p = Path::new($path); @@ -1534,7 +1534,7 @@ mod tests { assert_eq!(p.as_str(), Some($exp)); } ) - ); + } t!(s: "a\\b\\c", "d", "a\\b\\c\\d"); t!(s: "\\a\\b\\c", "d", "\\a\\b\\c\\d"); @@ -1577,7 +1577,7 @@ mod tests { #[test] fn test_push_many() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $push:expr, $exp:expr) => ( { let mut p = Path::new($path); @@ -1592,7 +1592,7 @@ mod tests { assert_eq!(p.as_vec(), $exp); } ) - ); + } t!(s: "a\\b\\c", ["d", "e"], "a\\b\\c\\d\\e"); t!(s: "a\\b\\c", ["d", "\\e"], "\\e"); @@ -1606,7 +1606,7 @@ mod tests { #[test] fn test_pop() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $left:expr, $right:expr) => ( { let pstr = $path; @@ -1627,7 +1627,7 @@ mod tests { assert!(result == $right); } ) - ); + } t!(s: "a\\b\\c", "a\\b", true); t!(s: "a", ".", true); @@ -1695,7 +1695,7 @@ mod tests { #[test] fn test_join_path() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $join:expr, $exp:expr) => ( { let path = Path::new($path); @@ -1704,7 +1704,7 @@ mod tests { assert_eq!(res.as_str(), Some($exp)); } ) - ); + } t!(s: "a\\b\\c", "..", "a\\b"); t!(s: "\\a\\b\\c", "d", "\\a\\b\\c\\d"); @@ -1718,7 +1718,7 @@ mod tests { #[test] fn test_join_many() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $join:expr, $exp:expr) => ( { let path = Path::new($path); @@ -1733,7 +1733,7 @@ mod tests { assert_eq!(res.as_vec(), $exp); } ) - ); + } t!(s: "a\\b\\c", ["d", "e"], "a\\b\\c\\d\\e"); t!(s: "a\\b\\c", ["..", "d"], "a\\b\\d"); @@ -1746,7 +1746,7 @@ mod tests { #[test] fn test_with_helpers() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $op:ident, $arg:expr, $res:expr) => ( { let pstr = $path; @@ -1759,7 +1759,7 @@ mod tests { pstr, stringify!($op), arg, exp, res.as_str().unwrap()); } ) - ); + } t!(s: "a\\b\\c", with_filename, "d", "a\\b\\d"); t!(s: ".", with_filename, "foo", "foo"); @@ -1831,7 +1831,7 @@ mod tests { #[test] fn test_setters() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $set:ident, $with:ident, $arg:expr) => ( { let path = $path; @@ -1852,7 +1852,7 @@ mod tests { assert!(p1 == p2.$with(arg)); } ) - ); + } t!(v: b"a\\b\\c", set_filename, with_filename, b"d"); t!(v: b"\\", set_filename, with_filename, b"foo"); @@ -1876,7 +1876,7 @@ mod tests { #[test] fn test_getters() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $filename:expr, $dirname:expr, $filestem:expr, $ext:expr) => ( { let path = $path; @@ -1907,7 +1907,7 @@ mod tests { assert!(path.extension() == $ext); } ) - ); + } t!(v: Path::new(b"a\\b\\c"), Some(b"c"), b"a\\b", Some(b"c"), None); t!(s: Path::new("a\\b\\c"), Some("c"), Some("a\\b"), Some("c"), None); @@ -1942,7 +1942,7 @@ mod tests { #[test] fn test_is_absolute() { - macro_rules! t( + macro_rules! t { ($path:expr, $abs:expr, $vol:expr, $cwd:expr, $rel:expr) => ( { let path = Path::new($path); @@ -1961,7 +1961,7 @@ mod tests { path.as_str().unwrap(), rel, b); } ) - ); + } t!("a\\b\\c", false, false, false, true); t!("\\a\\b\\c", false, true, false, false); t!("a", false, false, false, true); @@ -1982,7 +1982,7 @@ mod tests { #[test] fn test_is_ancestor_of() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $dest:expr, $exp:expr) => ( { let path = Path::new($path); @@ -1994,7 +1994,7 @@ mod tests { path.as_str().unwrap(), dest.as_str().unwrap(), exp, res); } ) - ); + } t!(s: "a\\b\\c", "a\\b\\c\\d", true); t!(s: "a\\b\\c", "a\\b\\c", true); @@ -2085,7 +2085,7 @@ mod tests { #[test] fn test_ends_with_path() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $child:expr, $exp:expr) => ( { let path = Path::new($path); @@ -2093,7 +2093,7 @@ mod tests { assert_eq!(path.ends_with_path(&child), $exp); } ); - ); + } t!(s: "a\\b\\c", "c", true); t!(s: "a\\b\\c", "d", false); @@ -2117,7 +2117,7 @@ mod tests { #[test] fn test_path_relative_from() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $other:expr, $exp:expr) => ( { let path = Path::new($path); @@ -2130,7 +2130,7 @@ mod tests { res.as_ref().and_then(|x| x.as_str())); } ) - ); + } t!(s: "a\\b\\c", "a\\b", Some("c")); t!(s: "a\\b\\c", "a\\b\\d", Some("..\\c")); @@ -2251,7 +2251,7 @@ mod tests { #[test] fn test_str_components() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $exp:expr) => ( { let path = Path::new($path); @@ -2265,7 +2265,7 @@ mod tests { assert_eq!(comps, exp); } ); - ); + } t!(s: b"a\\b\\c", ["a", "b", "c"]); t!(s: "a\\b\\c", ["a", "b", "c"]); @@ -2309,7 +2309,7 @@ mod tests { #[test] fn test_components_iter() { - macro_rules! t( + macro_rules! t { (s: $path:expr, $exp:expr) => ( { let path = Path::new($path); @@ -2321,7 +2321,7 @@ mod tests { assert_eq!(comps, exp); } ) - ); + } t!(s: "a\\b\\c", [b"a", b"b", b"c"]); t!(s: ".", [b"."]); @@ -2330,7 +2330,7 @@ mod tests { #[test] fn test_make_non_verbatim() { - macro_rules! t( + macro_rules! t { ($path:expr, $exp:expr) => ( { let path = Path::new($path); @@ -2339,7 +2339,7 @@ mod tests { assert!(make_non_verbatim(&path) == exp); } ) - ); + } t!(r"\a\b\c", Some(r"\a\b\c")); t!(r"a\b\c", Some(r"a\b\c")); diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index 7a67fab820d..1b1bc6d281a 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -61,7 +61,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt, cx, span, substr) } - macro_rules! md ( + macro_rules! md { ($name:expr, $f:ident) => { { let inline = cx.meta_word(span, InternedString::new("inline")); let attrs = vec!(cx.attribute(span, inline)); @@ -77,7 +77,7 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt, }) } } } - ); + } let trait_def = TraitDef { span: span, diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index c02416bfbea..7353ddc1720 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -27,7 +27,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt, push: F) where F: FnOnce(P), { - macro_rules! md ( + macro_rules! md { ($name:expr, $op:expr, $equal:expr) => { { let inline = cx.meta_word(span, InternedString::new("inline")); let attrs = vec!(cx.attribute(span, inline)); @@ -43,7 +43,7 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt, }) } } } - ); + } let ordering_ty = Literal(Path::new(vec!["std", "cmp", "Ordering"])); let ret_ty = Literal(Path::new_(vec!["std", "option", "Option"], diff --git a/src/libsyntax/ext/deriving/mod.rs b/src/libsyntax/ext/deriving/mod.rs index 14b19fee3df..e72c83b67c8 100644 --- a/src/libsyntax/ext/deriving/mod.rs +++ b/src/libsyntax/ext/deriving/mod.rs @@ -71,9 +71,11 @@ pub fn expand_meta_derive(cx: &mut ExtCtxt, MetaNameValue(ref tname, _) | MetaList(ref tname, _) | MetaWord(ref tname) => { - macro_rules! expand(($func:path) => ($func(cx, titem.span, - &**titem, item, - |i| push.call_mut((i,))))); + macro_rules! expand { + ($func:path) => ($func(cx, titem.span, &**titem, item, + |i| push.call_mut((i,)))) + } + match tname.get() { "Clone" => expand!(clone::expand_deriving_clone), diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index cf0d2c6474b..9837c8088fa 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -38,8 +38,8 @@ impl<'a> ParserAnyMacro<'a> { /// Make sure we don't have any tokens left to parse, so we don't /// silently drop anything. `allow_semi` is so that "optional" /// semicolons at the end of normal expressions aren't complained - /// about e.g. the semicolon in `macro_rules! kapow( () => { - /// panic!(); } )` doesn't get picked up by .parse_expr(), but it's + /// about e.g. the semicolon in `macro_rules! kapow { () => { + /// panic!(); } }` doesn't get picked up by .parse_expr(), but it's /// allowed to be there. fn ensure_complete_parse(&self, allow_semi: bool) { let mut parser = self.parser.borrow_mut(); diff --git a/src/libterm/terminfo/parser/compiled.rs b/src/libterm/terminfo/parser/compiled.rs index fe96d7b8b7d..5f0111c7d7a 100644 --- a/src/libterm/terminfo/parser/compiled.rs +++ b/src/libterm/terminfo/parser/compiled.rs @@ -160,12 +160,12 @@ pub static stringnames: &'static[&'static str] = &[ "cbt", "_", "cr", "csr", "tb /// Parse a compiled terminfo entry, using long capability names if `longnames` is true pub fn parse(file: &mut io::Reader, longnames: bool) -> Result, String> { - macro_rules! try( ($e:expr) => ( + macro_rules! try { ($e:expr) => ( match $e { Ok(e) => e, Err(e) => return Err(format!("{}", e)) } - ) ); + ) } let bnames; let snames; diff --git a/src/test/auxiliary/lint_stability.rs b/src/test/auxiliary/lint_stability.rs index 5ef1acae6c7..5eb6b0de3de 100644 --- a/src/test/auxiliary/lint_stability.rs +++ b/src/test/auxiliary/lint_stability.rs @@ -180,16 +180,16 @@ pub struct FrozenTupleStruct(pub int); pub struct LockedTupleStruct(pub int); #[macro_export] -macro_rules! macro_test( +macro_rules! macro_test { () => (deprecated()); -); +} #[macro_export] -macro_rules! macro_test_arg( +macro_rules! macro_test_arg { ($func:expr) => ($func); -); +} #[macro_export] -macro_rules! macro_test_arg_nested( +macro_rules! macro_test_arg_nested { ($func:ident) => (macro_test_arg!($func())); -); +} diff --git a/src/test/auxiliary/macro_crate_def_only.rs b/src/test/auxiliary/macro_crate_def_only.rs index ad3e72f5fa2..c323eb0c446 100644 --- a/src/test/auxiliary/macro_crate_def_only.rs +++ b/src/test/auxiliary/macro_crate_def_only.rs @@ -11,6 +11,6 @@ #![feature(macro_rules)] #[macro_export] -macro_rules! make_a_5( +macro_rules! make_a_5 { () => (5) -); +} diff --git a/src/test/auxiliary/macro_crate_test.rs b/src/test/auxiliary/macro_crate_test.rs index b82cfcbc8fc..418a7c6e538 100644 --- a/src/test/auxiliary/macro_crate_test.rs +++ b/src/test/auxiliary/macro_crate_test.rs @@ -24,9 +24,9 @@ use syntax::ptr::P; use rustc::plugin::Registry; #[macro_export] -macro_rules! exported_macro (() => (2i)); +macro_rules! exported_macro { () => (2i) } -macro_rules! unexported_macro (() => (3i)); +macro_rules! unexported_macro { () => (3i) } #[plugin_registrar] pub fn plugin_registrar(reg: &mut Registry) { diff --git a/src/test/auxiliary/macro_export_inner_module.rs b/src/test/auxiliary/macro_export_inner_module.rs index 9b4b1ceb5c1..fb98637811d 100644 --- a/src/test/auxiliary/macro_export_inner_module.rs +++ b/src/test/auxiliary/macro_export_inner_module.rs @@ -12,7 +12,7 @@ pub mod inner { #[macro_export] - macro_rules! foo( + macro_rules! foo { () => (1) - ); + } } diff --git a/src/test/bench/core-std.rs b/src/test/bench/core-std.rs index ee7c442da19..21e55384f46 100644 --- a/src/test/bench/core-std.rs +++ b/src/test/bench/core-std.rs @@ -28,11 +28,12 @@ fn main() { let argv = os::args(); let _tests = argv.slice(1, argv.len()); - macro_rules! bench ( + macro_rules! bench { ($id:ident) => (maybe_run_test(argv.as_slice(), stringify!($id).to_string(), - $id))); + $id)) + } bench!(shift_push); bench!(read_line); diff --git a/src/test/compile-fail/gated-macro-rules.rs b/src/test/compile-fail/gated-macro-rules.rs index ae2f03fd5f7..dea0c60d91b 100644 --- a/src/test/compile-fail/gated-macro-rules.rs +++ b/src/test/compile-fail/gated-macro-rules.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -macro_rules! foo(() => ()); +macro_rules! foo { () => () } //~^ ERROR: macro definitions are not stable enough for use fn main() {} diff --git a/src/test/compile-fail/infinite-macro-expansion.rs b/src/test/compile-fail/infinite-macro-expansion.rs index 22ac2eb1f7d..22011f19235 100644 --- a/src/test/compile-fail/infinite-macro-expansion.rs +++ b/src/test/compile-fail/infinite-macro-expansion.rs @@ -10,11 +10,9 @@ #![feature(macro_rules)] -macro_rules! recursive( - () => ( - recursive!() //~ ERROR recursion limit reached while expanding the macro `recursive` - ) - ); +macro_rules! recursive { + () => (recursive!()) //~ ERROR recursion limit reached while expanding the macro `recursive` +} fn main() { recursive!() diff --git a/src/test/compile-fail/issue-15167.rs b/src/test/compile-fail/issue-15167.rs index 300831b1007..cb107919733 100644 --- a/src/test/compile-fail/issue-15167.rs +++ b/src/test/compile-fail/issue-15167.rs @@ -17,7 +17,7 @@ #![feature(macro_rules)] -macro_rules! f(() => (n)) +macro_rules! f { () => (n) } fn main() -> (){ for n in range(0i, 1) { diff --git a/src/test/compile-fail/issue-6596.rs b/src/test/compile-fail/issue-6596.rs index 3222b2cd537..b237b425918 100644 --- a/src/test/compile-fail/issue-6596.rs +++ b/src/test/compile-fail/issue-6596.rs @@ -12,11 +12,11 @@ // error-pattern: unexpected token -macro_rules! e( +macro_rules! e { ($inp:ident) => ( $nonexistent ); -); +} fn main() { e!(foo); diff --git a/src/test/compile-fail/liveness-return-last-stmt-semi.rs b/src/test/compile-fail/liveness-return-last-stmt-semi.rs index e92faa6bdaf..cdcb0859ed9 100644 --- a/src/test/compile-fail/liveness-return-last-stmt-semi.rs +++ b/src/test/compile-fail/liveness-return-last-stmt-semi.rs @@ -12,7 +12,7 @@ #![feature(macro_rules)] -macro_rules! test ( () => { fn foo() -> int { 1i; } } ); +macro_rules! test { () => { fn foo() -> int { 1i; } } } //~^ ERROR not all control paths return a value //~^^ HELP consider removing this semicolon diff --git a/src/test/compile-fail/macro-inner-attributes.rs b/src/test/compile-fail/macro-inner-attributes.rs index f64b7be50e3..8d2f49ecc7f 100644 --- a/src/test/compile-fail/macro-inner-attributes.rs +++ b/src/test/compile-fail/macro-inner-attributes.rs @@ -10,9 +10,9 @@ #![feature(macro_rules)] -macro_rules! test ( ($nm:ident, +macro_rules! test { ($nm:ident, #[$a:meta], - $i:item) => (mod $nm { #![$a] $i }); ); + $i:item) => (mod $nm { #![$a] $i }); } test!(a, #[cfg(qux)], diff --git a/src/test/compile-fail/macro-match-nonterminal.rs b/src/test/compile-fail/macro-match-nonterminal.rs index 150187aa07d..8bfaac1770d 100644 --- a/src/test/compile-fail/macro-match-nonterminal.rs +++ b/src/test/compile-fail/macro-match-nonterminal.rs @@ -10,7 +10,7 @@ #![feature(macro_rules)] -macro_rules! test ( ($a, $b) => (()); ); //~ ERROR Cannot transcribe +macro_rules! test { ($a, $b) => (()); } //~ ERROR Cannot transcribe fn main() { test!() diff --git a/src/test/compile-fail/macro-outer-attributes.rs b/src/test/compile-fail/macro-outer-attributes.rs index 6d59c203d14..4f2c097eca9 100644 --- a/src/test/compile-fail/macro-outer-attributes.rs +++ b/src/test/compile-fail/macro-outer-attributes.rs @@ -10,9 +10,9 @@ #![feature(macro_rules)] -macro_rules! test ( ($nm:ident, +macro_rules! test { ($nm:ident, #[$a:meta], - $i:item) => (mod $nm { #[$a] $i }); ); + $i:item) => (mod $nm { #[$a] $i }); } test!(a, #[cfg(qux)], diff --git a/src/test/compile-fail/macros-no-semicolon-items.rs b/src/test/compile-fail/macros-no-semicolon-items.rs index f1f31a99e97..314292085df 100644 --- a/src/test/compile-fail/macros-no-semicolon-items.rs +++ b/src/test/compile-fail/macros-no-semicolon-items.rs @@ -12,4 +12,3 @@ macro_rules! foo() //~ ERROR semicolon fn main() { } - diff --git a/src/test/compile-fail/method-macro-backtrace.rs b/src/test/compile-fail/method-macro-backtrace.rs index 747b4815ac2..56087c79799 100644 --- a/src/test/compile-fail/method-macro-backtrace.rs +++ b/src/test/compile-fail/method-macro-backtrace.rs @@ -12,9 +12,9 @@ #![feature(macro_rules)] -macro_rules! make_method ( ($name:ident) => ( - fn $name(&self) { } -)); +macro_rules! make_method { + ($name:ident) => ( fn $name(&self) { } ) +} struct S; diff --git a/src/test/compile-fail/pattern-macro-hygiene.rs b/src/test/compile-fail/pattern-macro-hygiene.rs index 3322fecf950..64f810c1c95 100644 --- a/src/test/compile-fail/pattern-macro-hygiene.rs +++ b/src/test/compile-fail/pattern-macro-hygiene.rs @@ -10,7 +10,7 @@ #![feature(macro_rules)] -macro_rules! foo ( () => ( x ) ); +macro_rules! foo { () => ( x ) } fn main() { let foo!() = 2; diff --git a/src/test/run-pass/borrowck-macro-interaction-issue-6304.rs b/src/test/run-pass/borrowck-macro-interaction-issue-6304.rs index 822db63971e..bd42cc94a33 100644 --- a/src/test/run-pass/borrowck-macro-interaction-issue-6304.rs +++ b/src/test/run-pass/borrowck-macro-interaction-issue-6304.rs @@ -24,12 +24,12 @@ pub enum Bar { impl Foo { fn elaborate_stm(&mut self, s: Box) -> Box { - macro_rules! declare( + macro_rules! declare { ($id:expr, $rest:expr) => ({ self.check_id($id); box Bar::Bar2($id, $rest) }) - ); + } match s { box Bar::Bar2(id, rest) => declare!(id, self.elaborate_stm(rest)), _ => panic!() diff --git a/src/test/run-pass/cleanup-rvalue-scopes.rs b/src/test/run-pass/cleanup-rvalue-scopes.rs index 42f6914e081..fe74956fd1e 100644 --- a/src/test/run-pass/cleanup-rvalue-scopes.rs +++ b/src/test/run-pass/cleanup-rvalue-scopes.rs @@ -61,7 +61,7 @@ impl Drop for AddFlags { } } -macro_rules! end_of_block( +macro_rules! end_of_block { ($pat:pat, $expr:expr) => ( { println!("end_of_block({})", stringify!({let $pat = $expr;})); @@ -74,9 +74,9 @@ macro_rules! end_of_block( check_flags(1); } ) -); +} -macro_rules! end_of_stmt( +macro_rules! end_of_stmt { ($pat:pat, $expr:expr) => ( { println!("end_of_stmt({})", stringify!($expr)); @@ -91,7 +91,7 @@ macro_rules! end_of_stmt( check_flags(0); } ) -); +} pub fn main() { diff --git a/src/test/run-pass/const-binops.rs b/src/test/run-pass/const-binops.rs index cac805189b8..51647aebcf8 100644 --- a/src/test/run-pass/const-binops.rs +++ b/src/test/run-pass/const-binops.rs @@ -10,14 +10,14 @@ #![feature(macro_rules)] -macro_rules! assert_approx_eq( +macro_rules! assert_approx_eq { ($a:expr, $b:expr) => ({ use std::num::Float; let (a, b) = (&$a, &$b); assert!((*a - *b).abs() < 1.0e-6, "{} is not approximately equal to {}", *a, *b); }) -); +} static A: int = -4 + 3; static A2: uint = 3 + 3; diff --git a/src/test/run-pass/core-run-destroy.rs b/src/test/run-pass/core-run-destroy.rs index c1db8a6eb13..33564af2d7d 100644 --- a/src/test/run-pass/core-run-destroy.rs +++ b/src/test/run-pass/core-run-destroy.rs @@ -26,9 +26,9 @@ use std::str; use std::sync::mpsc::channel; use std::thread::Thread; -macro_rules! succeed( ($e:expr) => ( +macro_rules! succeed { ($e:expr) => ( match $e { Ok(..) => {}, Err(e) => panic!("panic: {}", e) } -) ); +) } fn test_destroy_once() { let mut p = sleeper(); diff --git a/src/test/run-pass/deriving-in-macro.rs b/src/test/run-pass/deriving-in-macro.rs index 97f6ee341a7..162de18f581 100644 --- a/src/test/run-pass/deriving-in-macro.rs +++ b/src/test/run-pass/deriving-in-macro.rs @@ -10,14 +10,14 @@ #![feature(macro_rules)] -macro_rules! define_vec ( +macro_rules! define_vec { () => ( mod foo { #[derive(PartialEq)] pub struct bar; } ) -); +} define_vec!(); diff --git a/src/test/run-pass/exponential-notation.rs b/src/test/run-pass/exponential-notation.rs index 38d10937624..6addbf69354 100644 --- a/src/test/run-pass/exponential-notation.rs +++ b/src/test/run-pass/exponential-notation.rs @@ -15,7 +15,9 @@ use std::num::strconv::SignificantDigits::DigMax; use std::num::strconv::SignFormat::{SignAll, SignNeg}; use std::num::strconv::float_to_str_common as to_string; -macro_rules! t(($a:expr, $b:expr) => { { let (r, _) = $a; assert_eq!(r, $b.to_string()); } }); +macro_rules! t { + ($a:expr, $b:expr) => { { let (r, _) = $a; assert_eq!(r, $b.to_string()); } } +} pub fn main() { // Basic usage diff --git a/src/test/run-pass/html-literals.rs b/src/test/run-pass/html-literals.rs index 0d56f28e8fa..6f6a429db17 100644 --- a/src/test/run-pass/html-literals.rs +++ b/src/test/run-pass/html-literals.rs @@ -27,13 +27,13 @@ left. */ use HTMLFragment::{tag, text}; -macro_rules! html ( +macro_rules! html { ( $($body:tt)* ) => ( parse_node!( []; []; $($body)* ) ) -); +} -macro_rules! parse_node ( +macro_rules! parse_node { ( [:$head:ident ($(:$head_nodes:expr),*) $(:$tags:ident ($(:$tag_nodes:expr),*))*]; @@ -85,7 +85,7 @@ macro_rules! parse_node ( ); ( []; [:$e:expr]; ) => ( $e ); -); +} pub fn main() { let _page = html! ( diff --git a/src/test/run-pass/ifmt.rs b/src/test/run-pass/ifmt.rs index 1efae89f665..6f050e7db05 100644 --- a/src/test/run-pass/ifmt.rs +++ b/src/test/run-pass/ifmt.rs @@ -37,7 +37,9 @@ impl fmt::Show for C { } } -macro_rules! t(($a:expr, $b:expr) => { assert_eq!($a.as_slice(), $b) }); +macro_rules! t { + ($a:expr, $b:expr) => { assert_eq!($a.as_slice(), $b) } +} pub fn main() { // Various edge cases without formats diff --git a/src/test/run-pass/intrinsics-math.rs b/src/test/run-pass/intrinsics-math.rs index 9f2fe155cdf..4c86cb0049a 100644 --- a/src/test/run-pass/intrinsics-math.rs +++ b/src/test/run-pass/intrinsics-math.rs @@ -11,14 +11,14 @@ #![feature(globs, macro_rules, intrinsics)] -macro_rules! assert_approx_eq( +macro_rules! assert_approx_eq { ($a:expr, $b:expr) => ({ use std::num::Float; let (a, b) = (&$a, &$b); assert!((*a - *b).abs() < 1.0e-6, "{} is not approximately equal to {}", *a, *b); }) -); +} mod rusti { extern "rust-intrinsic" { diff --git a/src/test/run-pass/issue-15189.rs b/src/test/run-pass/issue-15189.rs index 01c96b7563a..60083c25480 100644 --- a/src/test/run-pass/issue-15189.rs +++ b/src/test/run-pass/issue-15189.rs @@ -12,7 +12,9 @@ #![feature(macro_rules)] -macro_rules! third(($e:expr)=>({let x = 2; $e[x]})); +macro_rules! third { + ($e:expr) => ({let x = 2; $e[x]}) +} fn main() { let x = vec!(10u,11u,12u,13u); diff --git a/src/test/run-pass/issue-15221.rs b/src/test/run-pass/issue-15221.rs index a11b34e4762..f778af7ebcf 100644 --- a/src/test/run-pass/issue-15221.rs +++ b/src/test/run-pass/issue-15221.rs @@ -10,11 +10,13 @@ #![feature(macro_rules)] -macro_rules! inner ( - ($e:pat ) => ($e)); +macro_rules! inner { + ($e:pat ) => ($e) +} -macro_rules! outer ( - ($e:pat ) => (inner!($e))); +macro_rules! outer { + ($e:pat ) => (inner!($e)) +} fn main() { let outer!(g1) = 13i; diff --git a/src/test/run-pass/issue-5060.rs b/src/test/run-pass/issue-5060.rs index 0cd25bc2c71..18ebe35dcdf 100644 --- a/src/test/run-pass/issue-5060.rs +++ b/src/test/run-pass/issue-5060.rs @@ -10,7 +10,7 @@ #![feature(macro_rules)] -macro_rules! print_hd_tl ( +macro_rules! print_hd_tl { ($field_hd:ident, $($field_tl:ident),+) => ({ print!("{}", stringify!($field_hd)); print!("::["); @@ -21,7 +21,7 @@ macro_rules! print_hd_tl ( // FIXME: #9970 print!("{}", "]\n"); }) -); +} pub fn main() { print_hd_tl!(x, y, z, w) diff --git a/src/test/run-pass/issue-7911.rs b/src/test/run-pass/issue-7911.rs index c69b66f4dbd..8cc507d8855 100644 --- a/src/test/run-pass/issue-7911.rs +++ b/src/test/run-pass/issue-7911.rs @@ -27,7 +27,7 @@ trait Test { fn get_mut(&mut self) -> &mut FooBar; } -macro_rules! generate_test(($type_:path, $slf:ident, $field:expr) => ( +macro_rules! generate_test { ($type_:path, $slf:ident, $field:expr) => ( impl Test for $type_ { fn get_immut(&$slf) -> &FooBar { &$field as &FooBar @@ -37,7 +37,7 @@ macro_rules! generate_test(($type_:path, $slf:ident, $field:expr) => ( &mut $field as &mut FooBar } } -)); +)} generate_test!(Foo, self, self.bar); diff --git a/src/test/run-pass/issue-8709.rs b/src/test/run-pass/issue-8709.rs index d4ea05004a0..4e7d42f6b0b 100644 --- a/src/test/run-pass/issue-8709.rs +++ b/src/test/run-pass/issue-8709.rs @@ -10,13 +10,13 @@ #![feature(macro_rules)] -macro_rules! sty( +macro_rules! sty { ($t:ty) => (stringify!($t)) -); +} -macro_rules! spath( +macro_rules! spath { ($t:path) => (stringify!($t)) -); +} fn main() { assert_eq!(sty!(int), "int"); diff --git a/src/test/run-pass/issue-8851.rs b/src/test/run-pass/issue-8851.rs index 5826a5f9919..765e696cd55 100644 --- a/src/test/run-pass/issue-8851.rs +++ b/src/test/run-pass/issue-8851.rs @@ -20,7 +20,7 @@ enum T { B(uint) } -macro_rules! test( +macro_rules! test { ($id:ident, $e:expr) => ( fn foo(t: T) -> int { match t { @@ -29,7 +29,7 @@ macro_rules! test( } } ) -); +} test!(y, 10 + (y as int)); diff --git a/src/test/run-pass/issue-9110.rs b/src/test/run-pass/issue-9110.rs index 60011281d42..26390d8da7d 100644 --- a/src/test/run-pass/issue-9110.rs +++ b/src/test/run-pass/issue-9110.rs @@ -10,14 +10,14 @@ #![feature(macro_rules)] -macro_rules! silly_macro( +macro_rules! silly_macro { () => ( pub mod Qux { pub struct Foo { x : u8 } pub fn bar(_foo : Foo) {} } ); -); +} silly_macro!(); diff --git a/src/test/run-pass/issue-9129.rs b/src/test/run-pass/issue-9129.rs index a6746f45206..2ac1a42a246 100644 --- a/src/test/run-pass/issue-9129.rs +++ b/src/test/run-pass/issue-9129.rs @@ -19,8 +19,8 @@ impl bomb for S { fn boom(&self, _: Ident) { } } pub struct Ident { name: uint } -// macro_rules! int3( () => ( unsafe { asm!( "int3" ); } ) ) -macro_rules! int3( () => ( { } ) ); +// macro_rules! int3 { () => ( unsafe { asm!( "int3" ); } ) } +macro_rules! int3 { () => ( { } ) } fn Ident_new() -> Ident { int3!(); diff --git a/src/test/run-pass/issue-9737.rs b/src/test/run-pass/issue-9737.rs index 1f385b2fb15..2bd251ca587 100644 --- a/src/test/run-pass/issue-9737.rs +++ b/src/test/run-pass/issue-9737.rs @@ -12,7 +12,9 @@ #![feature(macro_rules)] -macro_rules! f((v: $x:expr) => ( println!("{}", $x) )) +macro_rules! f { + (v: $x:expr) => ( println!("{}", $x) ) +} fn main () { let v = 5; diff --git a/src/test/run-pass/lambda-var-hygiene.rs b/src/test/run-pass/lambda-var-hygiene.rs index 5dfc4208554..ebd3e3c6641 100644 --- a/src/test/run-pass/lambda-var-hygiene.rs +++ b/src/test/run-pass/lambda-var-hygiene.rs @@ -13,7 +13,9 @@ #![feature(macro_rules)] // shouldn't affect evaluation of $ex: -macro_rules! bad_macro (($ex:expr) => ({(|_x| { $ex }) (9) })) +macro_rules! bad_macro { + ($ex:expr) => ({(|_x| { $ex }) (9) }) +} fn takes_x(_x : int) { assert_eq!(bad_macro!(_x),8); diff --git a/src/test/run-pass/let-var-hygiene.rs b/src/test/run-pass/let-var-hygiene.rs index 5eed791e058..e0388407571 100644 --- a/src/test/run-pass/let-var-hygiene.rs +++ b/src/test/run-pass/let-var-hygiene.rs @@ -11,7 +11,10 @@ #![feature(macro_rules)] // shouldn't affect evaluation of $ex: -macro_rules! bad_macro (($ex:expr) => ({let _x = 9i; $ex})); +macro_rules! bad_macro { + ($ex:expr) => ({let _x = 9i; $ex}) +} + pub fn main() { let _x = 8i; assert_eq!(bad_macro!(_x),8i) diff --git a/src/test/run-pass/macro-2.rs b/src/test/run-pass/macro-2.rs index 7b4d376993a..07667de4716 100644 --- a/src/test/run-pass/macro-2.rs +++ b/src/test/run-pass/macro-2.rs @@ -14,12 +14,12 @@ pub fn main() { - macro_rules! mylambda_tt( + macro_rules! mylambda_tt { ($x:ident, $body:expr) => ({ fn f($x: int) -> int { return $body; }; f }) - ); + } assert!(mylambda_tt!(y, y * 2)(8) == 16); } diff --git a/src/test/run-pass/macro-interpolation.rs b/src/test/run-pass/macro-interpolation.rs index 45712f5c62a..e531eb9dbc4 100644 --- a/src/test/run-pass/macro-interpolation.rs +++ b/src/test/run-pass/macro-interpolation.rs @@ -10,7 +10,7 @@ #![feature(macro_rules)] -macro_rules! overly_complicated ( +macro_rules! overly_complicated { ($fnname:ident, $arg:ident, $ty:ty, $body:block, $val:expr, $pat:pat, $res:path) => ({ fn $fnname($arg: $ty) -> Option<$ty> $body @@ -22,7 +22,7 @@ macro_rules! overly_complicated ( } }) -); +} pub fn main() { assert!(overly_complicated!(f, x, Option, { return Some(x); }, diff --git a/src/test/run-pass/macro-invocation-in-count-expr-fixed-array-type.rs b/src/test/run-pass/macro-invocation-in-count-expr-fixed-array-type.rs index ecd7c0458f7..5103c50f5cf 100644 --- a/src/test/run-pass/macro-invocation-in-count-expr-fixed-array-type.rs +++ b/src/test/run-pass/macro-invocation-in-count-expr-fixed-array-type.rs @@ -10,9 +10,9 @@ #![feature(macro_rules)] -macro_rules! four ( +macro_rules! four { () => (4) -); +} fn main() { let _x: [u16; four!()]; diff --git a/src/test/run-pass/macro-multiple-items.rs b/src/test/run-pass/macro-multiple-items.rs index 4fb130f0e13..40f41447aa8 100644 --- a/src/test/run-pass/macro-multiple-items.rs +++ b/src/test/run-pass/macro-multiple-items.rs @@ -12,7 +12,7 @@ #![feature(macro_rules)] -macro_rules! make_foo( +macro_rules! make_foo { () => ( struct Foo; @@ -20,7 +20,7 @@ macro_rules! make_foo( fn bar(&self) {} } ) -); +} make_foo!(); diff --git a/src/test/run-pass/macro-nt-list.rs b/src/test/run-pass/macro-nt-list.rs index 9367a231d4f..91f0a3b607c 100644 --- a/src/test/run-pass/macro-nt-list.rs +++ b/src/test/run-pass/macro-nt-list.rs @@ -10,15 +10,15 @@ #![feature(macro_rules)] -macro_rules! list ( +macro_rules! list { ( ($($id:ident),*) ) => (()); ( [$($id:ident),*] ) => (()); ( {$($id:ident),*} ) => (()); -); +} -macro_rules! tt_list ( +macro_rules! tt_list { ( ($($tt:tt),*) ) => (()); -); +} pub fn main() { list!( () ); diff --git a/src/test/run-pass/macro-of-higher-order.rs b/src/test/run-pass/macro-of-higher-order.rs index c47b5e11089..a7c0ca56d60 100644 --- a/src/test/run-pass/macro-of-higher-order.rs +++ b/src/test/run-pass/macro-of-higher-order.rs @@ -10,12 +10,12 @@ #![feature(macro_rules)] -macro_rules! higher_order ( +macro_rules! higher_order { (subst $lhs:tt => $rhs:tt) => ({ - macro_rules! anon ( $lhs => $rhs ); + macro_rules! anon { $lhs => $rhs } anon!(1u, 2u, "foo") }); -); +} fn main() { let val = higher_order!(subst ($x:expr, $y:expr, $foo:expr) => (($x + $y, $foo))); diff --git a/src/test/run-pass/macro-pat.rs b/src/test/run-pass/macro-pat.rs index 496cef9d644..d3e32923075 100644 --- a/src/test/run-pass/macro-pat.rs +++ b/src/test/run-pass/macro-pat.rs @@ -10,35 +10,35 @@ #![feature(macro_rules)] -macro_rules! mypat( +macro_rules! mypat { () => ( Some('y') ) -); +} -macro_rules! char_x( +macro_rules! char_x { () => ( 'x' ) -); +} -macro_rules! some( +macro_rules! some { ($x:pat) => ( Some($x) ) -); +} -macro_rules! indirect( +macro_rules! indirect { () => ( some!(char_x!()) ) -); +} -macro_rules! ident_pat( +macro_rules! ident_pat { ($x:ident) => ( $x ) -); +} fn f(c: Option) -> uint { match c { diff --git a/src/test/run-pass/macro-stmt.rs b/src/test/run-pass/macro-stmt.rs index 7be49e1acd8..77d6b59f8bf 100644 --- a/src/test/run-pass/macro-stmt.rs +++ b/src/test/run-pass/macro-stmt.rs @@ -12,21 +12,21 @@ #![feature(macro_rules)] -macro_rules! myfn( +macro_rules! myfn { ( $f:ident, ( $( $x:ident ),* ), $body:block ) => ( fn $f( $( $x : int),* ) -> int $body ) -); +} myfn!(add, (a,b), { return a+b; } ); pub fn main() { - macro_rules! mylet( + macro_rules! mylet { ($x:ident, $val:expr) => ( let $x = $val; ) - ); + } mylet!(y, 8i*2); assert_eq!(y, 16i); @@ -35,9 +35,9 @@ pub fn main() { assert_eq!(mult(2, add(4,4)), 16); - macro_rules! actually_an_expr_macro ( + macro_rules! actually_an_expr_macro { () => ( 16i ) - ); + } assert_eq!({ actually_an_expr_macro!() }, 16i); diff --git a/src/test/run-pass/macro-with-attrs1.rs b/src/test/run-pass/macro-with-attrs1.rs index 631fc866671..23a3a037497 100644 --- a/src/test/run-pass/macro-with-attrs1.rs +++ b/src/test/run-pass/macro-with-attrs1.rs @@ -13,10 +13,10 @@ #![feature(macro_rules)] #[cfg(foo)] -macro_rules! foo( () => (1i) ); +macro_rules! foo { () => (1i) } #[cfg(not(foo))] -macro_rules! foo( () => (2i) ); +macro_rules! foo { () => (2i) } pub fn main() { assert_eq!(foo!(), 1i); diff --git a/src/test/run-pass/macro-with-attrs2.rs b/src/test/run-pass/macro-with-attrs2.rs index 3ac0d47e61a..038931551a8 100644 --- a/src/test/run-pass/macro-with-attrs2.rs +++ b/src/test/run-pass/macro-with-attrs2.rs @@ -11,10 +11,10 @@ #![feature(macro_rules)] #[cfg(foo)] -macro_rules! foo( () => (1i) ); +macro_rules! foo { () => (1i) } #[cfg(not(foo))] -macro_rules! foo( () => (2i) ); +macro_rules! foo { () => (2i) } pub fn main() { assert_eq!(foo!(), 2i); diff --git a/src/test/run-pass/macro-with-braces-in-expr-position.rs b/src/test/run-pass/macro-with-braces-in-expr-position.rs index a6e579ddff3..b4170c27ec2 100644 --- a/src/test/run-pass/macro-with-braces-in-expr-position.rs +++ b/src/test/run-pass/macro-with-braces-in-expr-position.rs @@ -12,7 +12,7 @@ use std::thread::Thread; -macro_rules! expr (($e: expr) => { $e }); +macro_rules! expr { ($e: expr) => { $e } } macro_rules! spawn { ($($code: tt)*) => { diff --git a/src/test/run-pass/match-in-macro.rs b/src/test/run-pass/match-in-macro.rs index a776999ec8a..7dde322ead6 100644 --- a/src/test/run-pass/match-in-macro.rs +++ b/src/test/run-pass/match-in-macro.rs @@ -14,13 +14,13 @@ enum Foo { B { b1: int, bb1: int}, } -macro_rules! match_inside_expansion( +macro_rules! match_inside_expansion { () => ( match (Foo::B { b1:29 , bb1: 100}) { Foo::B { b1:b2 , bb1:bb2 } => b2+bb2 } ) -); +} pub fn main() { assert_eq!(match_inside_expansion!(),129); diff --git a/src/test/run-pass/match-var-hygiene.rs b/src/test/run-pass/match-var-hygiene.rs index 482fdf5b1d0..da15f911e8b 100644 --- a/src/test/run-pass/match-var-hygiene.rs +++ b/src/test/run-pass/match-var-hygiene.rs @@ -13,9 +13,9 @@ #![feature(macro_rules)] // shouldn't affect evaluation of $ex. -macro_rules! bad_macro (($ex:expr) => ( +macro_rules! bad_macro { ($ex:expr) => ( {match 9 {_x => $ex}} -)) +)} fn main() { match 8 { diff --git a/src/test/run-pass/non-built-in-quote.rs b/src/test/run-pass/non-built-in-quote.rs index 9151564b340..e4a3ac8cd91 100644 --- a/src/test/run-pass/non-built-in-quote.rs +++ b/src/test/run-pass/non-built-in-quote.rs @@ -10,7 +10,7 @@ #![feature(macro_rules)] -macro_rules! quote_tokens ( () => (()) ); +macro_rules! quote_tokens { () => (()) } pub fn main() { quote_tokens!(); diff --git a/src/test/run-pass/syntax-extension-source-utils.rs b/src/test/run-pass/syntax-extension-source-utils.rs index f6708536a9d..939d20ddc27 100644 --- a/src/test/run-pass/syntax-extension-source-utils.rs +++ b/src/test/run-pass/syntax-extension-source-utils.rs @@ -21,7 +21,7 @@ pub mod m1 { } } -macro_rules! indirect_line( () => ( line!() ) ); +macro_rules! indirect_line { () => ( line!() ) } pub fn main() { assert_eq!(line!(), 27); diff --git a/src/test/run-pass/typeck-macro-interaction-issue-8852.rs b/src/test/run-pass/typeck-macro-interaction-issue-8852.rs index 4dec227d520..ce6122aad00 100644 --- a/src/test/run-pass/typeck-macro-interaction-issue-8852.rs +++ b/src/test/run-pass/typeck-macro-interaction-issue-8852.rs @@ -20,7 +20,7 @@ enum T { // doesn't cause capture. Making this macro hygienic (as I've done) // could very well make this test case completely pointless.... -macro_rules! test( +macro_rules! test { ($id1:ident, $id2:ident, $e:expr) => ( fn foo(a:T, b:T) -> T { match (a, b) { @@ -30,7 +30,7 @@ macro_rules! test( } } ) -); +} test!(x,y,x + y); -- cgit 1.4.1-3-g733a5