diff --git a/src/libsyntax_ext/asm.rs b/src/libsyntax_ext/asm.rs index 50d2b9d31fe01..c316d2f122a7d 100644 --- a/src/libsyntax_ext/asm.rs +++ b/src/libsyntax_ext/asm.rs @@ -8,9 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -/* - * Inline assembly support. - */ +// Inline assembly support. +// use self::State::*; use syntax::ast; @@ -30,43 +29,48 @@ enum State { Inputs, Clobbers, Options, - StateNone + StateNone, } impl State { fn next(&self) -> State { match *self { - Asm => Outputs, - Outputs => Inputs, - Inputs => Clobbers, - Clobbers => Options, - Options => StateNone, - StateNone => StateNone + Asm => Outputs, + Outputs => Inputs, + Inputs => Clobbers, + Clobbers => Options, + Options => StateNone, + StateNone => StateNone, } } } const OPTIONS: &'static [&'static str] = &["volatile", "alignstack", "intel"]; -pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> Box { +pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, + sp: Span, + tts: &[ast::TokenTree]) + -> Box { if !cx.ecfg.enable_asm() { - feature_gate::emit_feature_err( - &cx.parse_sess.span_diagnostic, "asm", sp, - feature_gate::GateIssue::Language, - feature_gate::EXPLAIN_ASM); + feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, + "asm", + sp, + feature_gate::GateIssue::Language, + feature_gate::EXPLAIN_ASM); return DummyResult::expr(sp); } // Split the tts before the first colon, to avoid `asm!("x": y)` being // parsed as `asm!(z)` with `z = "x": y` which is type ascription. - let first_colon = tts.iter().position(|tt| { - match *tt { - ast::TokenTree::Token(_, token::Colon) | - ast::TokenTree::Token(_, token::ModSep) => true, - _ => false - } - }).unwrap_or(tts.len()); + let first_colon = tts.iter() + .position(|tt| { + match *tt { + ast::TokenTree::Token(_, token::Colon) | + ast::TokenTree::Token(_, token::ModSep) => true, + _ => false, + } + }) + .unwrap_or(tts.len()); let mut p = cx.new_parser_from_tts(&tts[first_colon..]); let mut asm = token::InternedString::new(""); let mut asm_str_style = None; @@ -90,8 +94,9 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } // Nested parser, stop before the first colon (see above). let mut p2 = cx.new_parser_from_tts(&tts[..first_colon]); - let (s, style) = match expr_to_string(cx, panictry!(p2.parse_expr()), - "inline assembly must be a string literal") { + let (s, style) = match expr_to_string(cx, + panictry!(p2.parse_expr()), + "inline assembly must be a string literal") { Some((s, st)) => (s, st), // let compilation continue None => return DummyResult::expr(sp), @@ -108,9 +113,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) asm_str_style = Some(style); } Outputs => { - while p.token != token::Eof && - p.token != token::Colon && - p.token != token::ModSep { + while p.token != token::Eof && p.token != token::Colon && p.token != token::ModSep { if !outputs.is_empty() { p.eat(&token::Comma); @@ -135,8 +138,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) let output = match ch.next() { Some('=') => None, Some('+') => { - Some(token::intern_and_get_ident(&format!( - "={}", ch.as_str()))) + Some(token::intern_and_get_ident(&format!("={}", ch.as_str()))) } _ => { cx.span_err(span, "output operand constraint lacks '=' or '+'"); @@ -155,9 +157,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } } Inputs => { - while p.token != token::Eof && - p.token != token::Colon && - p.token != token::ModSep { + while p.token != token::Eof && p.token != token::Colon && p.token != token::ModSep { if !inputs.is_empty() { p.eat(&token::Comma); @@ -179,9 +179,7 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) } } Clobbers => { - while p.token != token::Eof && - p.token != token::Colon && - p.token != token::ModSep { + while p.token != token::Eof && p.token != token::Colon && p.token != token::ModSep { if !clobs.is_empty() { p.eat(&token::Comma); @@ -214,25 +212,25 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) p.eat(&token::Comma); } } - StateNone => () + StateNone => (), } loop { // MOD_SEP is a double colon '::' without space in between. // When encountered, the state must be advanced twice. match (&p.token, state.next(), state.next().next()) { - (&token::Colon, StateNone, _) | + (&token::Colon, StateNone, _) | (&token::ModSep, _, StateNone) => { p.bump(); break 'statement; } - (&token::Colon, st, _) | + (&token::Colon, st, _) | (&token::ModSep, _, st) => { p.bump(); state = st; } (&token::Eof, _, _) => break 'statement, - _ => break + _ => break, } } } diff --git a/src/libsyntax_ext/cfg.rs b/src/libsyntax_ext/cfg.rs index bae0462b8d330..3b7fa4974c221 100644 --- a/src/libsyntax_ext/cfg.rs +++ b/src/libsyntax_ext/cfg.rs @@ -24,7 +24,7 @@ use syntax::config::CfgDiagReal; pub fn expand_cfg<'cx>(cx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> Box { + -> Box { let mut p = cx.new_parser_from_tts(tts); let cfg = panictry!(p.parse_meta_item()); diff --git a/src/libsyntax_ext/concat.rs b/src/libsyntax_ext/concat.rs index db731adf7943b..030829ced7b6e 100644 --- a/src/libsyntax_ext/concat.rs +++ b/src/libsyntax_ext/concat.rs @@ -19,10 +19,10 @@ use std::string::String; pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, sp: codemap::Span, tts: &[ast::TokenTree]) - -> Box { + -> Box { let es = match base::get_exprs_from_tts(cx, sp, tts) { Some(e) => e, - None => return base::DummyResult::expr(sp) + None => return base::DummyResult::expr(sp), }; let mut accumulator = String::new(); for e in es { @@ -56,7 +56,5 @@ pub fn expand_syntax_ext(cx: &mut base::ExtCtxt, } } } - base::MacEager::expr(cx.expr_str( - sp, - token::intern_and_get_ident(&accumulator[..]))) + base::MacEager::expr(cx.expr_str(sp, token::intern_and_get_ident(&accumulator[..]))) } diff --git a/src/libsyntax_ext/concat_idents.rs b/src/libsyntax_ext/concat_idents.rs index 09c23682cd73f..d5b273376a217 100644 --- a/src/libsyntax_ext/concat_idents.rs +++ b/src/libsyntax_ext/concat_idents.rs @@ -17,8 +17,10 @@ use syntax::parse::token; use syntax::parse::token::str_to_ident; use syntax::ptr::P; -pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[TokenTree]) - -> Box { +pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt, + sp: Span, + tts: &[TokenTree]) + -> Box { if !cx.ecfg.enable_concat_idents() { feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, "concat_idents", @@ -32,35 +34,40 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[TokenTree]) for (i, e) in tts.iter().enumerate() { if i & 1 == 1 { match *e { - TokenTree::Token(_, token::Comma) => {}, + TokenTree::Token(_, token::Comma) => {} _ => { cx.span_err(sp, "concat_idents! expecting comma."); return DummyResult::expr(sp); - }, + } } } else { match *e { - TokenTree::Token(_, token::Ident(ident)) => { - res_str.push_str(&ident.name.as_str()) - }, + TokenTree::Token(_, token::Ident(ident)) => res_str.push_str(&ident.name.as_str()), _ => { cx.span_err(sp, "concat_idents! requires ident args."); return DummyResult::expr(sp); - }, + } } } } let res = str_to_ident(&res_str); - struct Result { ident: ast::Ident, span: Span }; + struct Result { + ident: ast::Ident, + span: Span, + }; impl Result { fn path(&self) -> ast::Path { let segment = ast::PathSegment { identifier: self.ident, - parameters: ast::PathParameters::none() + parameters: ast::PathParameters::none(), }; - ast::Path { span: self.span, global: false, segments: vec![segment] } + ast::Path { + span: self.span, + global: false, + segments: vec![segment], + } } } @@ -83,5 +90,8 @@ pub fn expand_syntax_ext<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[TokenTree]) } } - Box::new(Result { ident: res, span: sp }) + Box::new(Result { + ident: res, + span: sp, + }) } diff --git a/src/libsyntax_ext/env.rs b/src/libsyntax_ext/env.rs index 63ec9cac07317..0e35ecd8503e9 100644 --- a/src/libsyntax_ext/env.rs +++ b/src/libsyntax_ext/env.rs @@ -8,11 +8,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -/* - * The compiler code necessary to support the env! extension. Eventually this - * should all get sucked into either the compiler syntax extension plugin - * interface. - */ +// The compiler code necessary to support the env! extension. Eventually this +// should all get sucked into either the compiler syntax extension plugin +// interface. +// use syntax::ast; use syntax::codemap::Span; @@ -23,66 +22,65 @@ use syntax::parse::token; use std::env; -pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> Box { +pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, + sp: Span, + tts: &[ast::TokenTree]) + -> Box { let var = match get_single_str_from_tts(cx, sp, tts, "option_env!") { None => return DummyResult::expr(sp), - Some(v) => v + Some(v) => v, }; let e = match env::var(&var[..]) { - Err(..) => { - cx.expr_path(cx.path_all(sp, - true, - cx.std_path(&["option", "Option", "None"]), - Vec::new(), - vec!(cx.ty_rptr(sp, - cx.ty_ident(sp, - cx.ident_of("str")), - Some(cx.lifetime(sp, - cx.ident_of( - "'static").name)), - ast::Mutability::Immutable)), - Vec::new())) - } - Ok(s) => { - cx.expr_call_global(sp, - cx.std_path(&["option", "Option", "Some"]), - vec!(cx.expr_str(sp, - token::intern_and_get_ident( - &s[..])))) - } + Err(..) => { + cx.expr_path(cx.path_all(sp, + true, + cx.std_path(&["option", "Option", "None"]), + Vec::new(), + vec![cx.ty_rptr(sp, + cx.ty_ident(sp, cx.ident_of("str")), + Some(cx.lifetime(sp, + cx.ident_of("'static") + .name)), + ast::Mutability::Immutable)], + Vec::new())) + } + Ok(s) => { + cx.expr_call_global(sp, + cx.std_path(&["option", "Option", "Some"]), + vec![cx.expr_str(sp, token::intern_and_get_ident(&s[..]))]) + } }; MacEager::expr(e) } -pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> Box { +pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt, + sp: Span, + tts: &[ast::TokenTree]) + -> Box { let mut exprs = match get_exprs_from_tts(cx, sp, tts) { Some(ref exprs) if exprs.is_empty() => { cx.span_err(sp, "env! takes 1 or 2 arguments"); return DummyResult::expr(sp); } None => return DummyResult::expr(sp), - Some(exprs) => exprs.into_iter() + Some(exprs) => exprs.into_iter(), }; - let var = match expr_to_string(cx, - exprs.next().unwrap(), - "expected string literal") { + let var = match expr_to_string(cx, exprs.next().unwrap(), "expected string literal") { None => return DummyResult::expr(sp), - Some((v, _style)) => v + Some((v, _style)) => v, }; let msg = match exprs.next() { None => { token::intern_and_get_ident(&format!("environment variable `{}` \ not defined", - var)) + var)) } Some(second) => { match expr_to_string(cx, second, "expected string literal") { None => return DummyResult::expr(sp), - Some((s, _style)) => s + Some((s, _style)) => s, } } }; @@ -100,7 +98,7 @@ pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) cx.span_err(sp, &msg); cx.expr_usize(sp, 0) } - Ok(s) => cx.expr_str(sp, token::intern_and_get_ident(&s)) + Ok(s) => cx.expr_str(sp, token::intern_and_get_ident(&s)), }; MacEager::expr(e) } diff --git a/src/libsyntax_ext/format.rs b/src/libsyntax_ext/format.rs index abfa65580646d..74dadc34964d7 100644 --- a/src/libsyntax_ext/format.rs +++ b/src/libsyntax_ext/format.rs @@ -14,7 +14,7 @@ use self::Position::*; use fmt_macros as parse; use syntax::ast; -use syntax::codemap::{Span, respan, DUMMY_SP}; +use syntax::codemap::{DUMMY_SP, Span, respan}; use syntax::ext::base::*; use syntax::ext::base; use syntax::ext::build::AstBuilder; @@ -27,7 +27,7 @@ use std::collections::HashMap; #[derive(PartialEq)] enum ArgumentType { Known(String), - Unsigned + Unsigned, } enum Position { @@ -35,7 +35,7 @@ enum Position { Named(String), } -struct Context<'a, 'b:'a> { +struct Context<'a, 'b: 'a> { ecx: &'a mut ExtCtxt<'b>, /// The macro's call site. References to unstable formatting internals must /// use this span to pass the stability checker. @@ -80,9 +80,11 @@ struct Context<'a, 'b:'a> { /// Some((fmtstr, unnamed arguments, ordering of named arguments, /// named arguments)) /// ``` -fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) - -> Option<(P, Vec>, Vec, - HashMap>)> { +fn parse_args + (ecx: &mut ExtCtxt, + sp: Span, + tts: &[ast::TokenTree]) + -> Option<(P, Vec>, Vec, HashMap>)> { let mut args = Vec::new(); let mut names = HashMap::>::new(); let mut order = Vec::new(); @@ -100,7 +102,9 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) ecx.span_err(sp, "expected token: `,`"); return None; } - if p.token == token::Eof { break } // accept trailing commas + if p.token == token::Eof { + break; + } // accept trailing commas if named || (p.token.is_ident() && p.look_ahead(1, |t| *t == token::Eq)) { named = true; let ident = match p.token { @@ -117,7 +121,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) _ => { ecx.span_err(p.span, &format!("expected ident for named argument, found `{}`", - p.this_token_to_string())); + p.this_token_to_string())); return None; } }; @@ -128,12 +132,10 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, tts: &[ast::TokenTree]) match names.get(name) { None => {} Some(prev) => { - ecx.struct_span_err(e.span, - &format!("duplicate argument named `{}`", - name)) + ecx.struct_span_err(e.span, &format!("duplicate argument named `{}`", name)) .span_note(prev.span, "previously here") .emit(); - continue + continue; } } order.push(name.to_string()); @@ -206,7 +208,8 @@ impl<'a, 'b> Context<'a, 'b> { Exact(arg) => { if self.args.len() <= arg { let msg = format!("invalid reference to argument `{}` ({})", - arg, self.describe_num_args()); + arg, + self.describe_num_args()); self.ecx.span_err(self.fmtsp, &msg[..]); return; @@ -214,7 +217,7 @@ impl<'a, 'b> Context<'a, 'b> { { let arg_type = match self.arg_types[arg] { None => None, - Some(ref x) => Some(x) + Some(ref x) => Some(x), }; self.verify_same(self.args[arg].span, &ty, arg_type); } @@ -254,24 +257,21 @@ impl<'a, 'b> Context<'a, 'b> { /// /// Obviously `Some(Some(x)) != Some(Some(y))`, but we consider it true /// that: `Some(None) == Some(Some(x))` - fn verify_same(&self, - sp: Span, - ty: &ArgumentType, - before: Option<&ArgumentType>) { + fn verify_same(&self, sp: Span, ty: &ArgumentType, before: Option<&ArgumentType>) { let cur = match before { None => return, Some(t) => t, }; if *ty == *cur { - return + return; } match (cur, ty) { (&Known(ref cur), &Known(ref ty)) => { self.ecx.span_err(sp, &format!("argument redeclared with type `{}` when \ it was previously `{}`", - *ty, - *cur)); + *ty, + *cur)); } (&Known(ref cur), _) => { self.ecx.span_err(sp, @@ -307,9 +307,7 @@ impl<'a, 'b> Context<'a, 'b> { }; match c { parse::CountIs(i) => count("Is", Some(self.ecx.expr_usize(sp, i))), - parse::CountIsParam(i) => { - count("Param", Some(self.ecx.expr_usize(sp, i))) - } + parse::CountIsParam(i) => count("Param", Some(self.ecx.expr_usize(sp, i))), parse::CountImplied => count("Implied", None), parse::CountIsNextParam => count("NextParam", None), parse::CountIsName(n) => { @@ -351,9 +349,7 @@ impl<'a, 'b> Context<'a, 'b> { let arg = self.ecx.expr_usize(sp, i); self.ecx.expr_call_global(sp, path, vec![arg]) } - None => { - self.ecx.expr_path(self.ecx.path_global(sp, path)) - } + None => self.ecx.expr_path(self.ecx.path_global(sp, path)), } }; match arg.position { @@ -382,11 +378,14 @@ impl<'a, 'b> Context<'a, 'b> { flags: 0, precision: parse::CountImplied, width: parse::CountImplied, - ty: arg.format.ty - } + ty: arg.format.ty, + }, }; - let fill = match arg.format.fill { Some(c) => c, None => ' ' }; + let fill = match arg.format.fill { + Some(c) => c, + None => ' ', + }; if *arg != simple_arg || fill != ' ' { self.all_pieces_simple = false; @@ -410,17 +409,38 @@ impl<'a, 'b> Context<'a, 'b> { let prec = self.trans_count(arg.format.precision); let width = self.trans_count(arg.format.width); let path = self.ecx.path_global(sp, Context::rtpath(self.ecx, "FormatSpec")); - let fmt = self.ecx.expr_struct(sp, path, vec!( - self.ecx.field_imm(sp, self.ecx.ident_of("fill"), fill), - self.ecx.field_imm(sp, self.ecx.ident_of("align"), align), - self.ecx.field_imm(sp, self.ecx.ident_of("flags"), flags), - self.ecx.field_imm(sp, self.ecx.ident_of("precision"), prec), - self.ecx.field_imm(sp, self.ecx.ident_of("width"), width))); + let fmt = self.ecx.expr_struct(sp, + path, + vec![self.ecx.field_imm(sp, + self.ecx.ident_of("fill"), + fill), + self.ecx.field_imm(sp, + self.ecx + .ident_of("align"), + align), + self.ecx.field_imm(sp, + self.ecx + .ident_of("flags"), + flags), + self.ecx + .field_imm(sp, + self.ecx + .ident_of("precision"), + prec), + self.ecx.field_imm(sp, + self.ecx + .ident_of("width"), + width)]); let path = self.ecx.path_global(sp, Context::rtpath(self.ecx, "Argument")); - Some(self.ecx.expr_struct(sp, path, vec!( - self.ecx.field_imm(sp, self.ecx.ident_of("position"), pos), - self.ecx.field_imm(sp, self.ecx.ident_of("format"), fmt)))) + Some(self.ecx.expr_struct(sp, + path, + vec![self.ecx.field_imm(sp, + self.ecx.ident_of("position"), + pos), + self.ecx.field_imm(sp, + self.ecx.ident_of("format"), + fmt)])) } } } @@ -432,9 +452,9 @@ impl<'a, 'b> Context<'a, 'b> { -> P { let sp = piece_ty.span; let ty = ecx.ty_rptr(sp, - ecx.ty(sp, ast::TyKind::Vec(piece_ty)), - Some(ecx.lifetime(sp, keywords::StaticLifetime.name())), - ast::Mutability::Immutable); + ecx.ty(sp, ast::TyKind::Vec(piece_ty)), + Some(ecx.lifetime(sp, keywords::StaticLifetime.name())), + ast::Mutability::Immutable); let slice = ecx.expr_vec_slice(sp, pieces); // static instead of const to speed up codegen by not requiring this to be inlined let st = ast::ItemKind::Static(ty, ast::Mutability::Immutable, slice); @@ -445,8 +465,9 @@ impl<'a, 'b> Context<'a, 'b> { // Wrap the declaration in a block so that it forms a single expression. ecx.expr_block(ecx.block(sp, - vec![respan(sp, ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))], - Some(ecx.expr_ident(sp, name)))) + vec![respan(sp, + ast::StmtKind::Decl(P(decl), ast::DUMMY_NODE_ID))], + Some(ecx.expr_ident(sp, name)))) } /// Actually builds the expression which the iformat! block will be expanded @@ -460,15 +481,11 @@ impl<'a, 'b> Context<'a, 'b> { // First, build up the static array which will become our precompiled // format "string" let static_lifetime = self.ecx.lifetime(self.fmtsp, keywords::StaticLifetime.name()); - let piece_ty = self.ecx.ty_rptr( - self.fmtsp, - self.ecx.ty_ident(self.fmtsp, self.ecx.ident_of("str")), - Some(static_lifetime), - ast::Mutability::Immutable); - let pieces = Context::static_array(self.ecx, - "__STATIC_FMTSTR", - piece_ty, - self.str_pieces); + let piece_ty = self.ecx.ty_rptr(self.fmtsp, + self.ecx.ty_ident(self.fmtsp, self.ecx.ident_of("str")), + Some(static_lifetime), + ast::Mutability::Immutable); + let pieces = Context::static_array(self.ecx, "__STATIC_FMTSTR", piece_ty, self.str_pieces); // Right now there is a bug such that for the expression: @@ -481,30 +498,35 @@ impl<'a, 'b> Context<'a, 'b> { for (i, e) in self.args.into_iter().enumerate() { let arg_ty = match self.arg_types[i].as_ref() { Some(ty) => ty, - None => continue // error already generated + None => continue, // error already generated }; let name = self.ecx.ident_of(&format!("__arg{}", i)); pats.push(self.ecx.pat_ident(DUMMY_SP, name)); - locals.push(Context::format_arg(self.ecx, self.macsp, e.span, arg_ty, + locals.push(Context::format_arg(self.ecx, + self.macsp, + e.span, + arg_ty, self.ecx.expr_ident(e.span, name))); heads.push(self.ecx.expr_addr_of(e.span, e)); } for name in &self.name_ordering { let e = match self.names.remove(name) { Some(e) => e, - None => continue + None => continue, }; let arg_ty = match self.name_types.get(name) { Some(ty) => ty, - None => continue + None => continue, }; - let lname = self.ecx.ident_of(&format!("__arg{}", - *name)); + let lname = self.ecx.ident_of(&format!("__arg{}", *name)); pats.push(self.ecx.pat_ident(DUMMY_SP, lname)); names[*self.name_positions.get(name).unwrap()] = - Some(Context::format_arg(self.ecx, self.macsp, e.span, arg_ty, + Some(Context::format_arg(self.ecx, + self.macsp, + e.span, + arg_ty, self.ecx.expr_ident(e.span, lname))); heads.push(self.ecx.expr_addr_of(e.span, e)); } @@ -542,9 +564,9 @@ impl<'a, 'b> Context<'a, 'b> { // But the nested match expression is proved to perform not as well // as series of let's; the first approach does. let pat = self.ecx.pat_tuple(self.fmtsp, pats); - let arm = self.ecx.arm(self.fmtsp, vec!(pat), args_array); + let arm = self.ecx.arm(self.fmtsp, vec![pat], args_array); let head = self.ecx.expr(self.fmtsp, ast::ExprKind::Tup(heads)); - let result = self.ecx.expr_match(self.fmtsp, head, vec!(arm)); + let result = self.ecx.expr_match(self.fmtsp, head, vec![arm]); let args_slice = self.ecx.expr_addr_of(self.fmtsp, result); @@ -554,13 +576,10 @@ impl<'a, 'b> Context<'a, 'b> { } else { // Build up the static array which will store our precompiled // nonstandard placeholders, if there are any. - let piece_ty = self.ecx.ty_path(self.ecx.path_global( - self.macsp, - Context::rtpath(self.ecx, "Argument"))); - let fmt = Context::static_array(self.ecx, - "__STATIC_FMTARGS", - piece_ty, - self.pieces); + let piece_ty = self.ecx.ty_path(self.ecx.path_global(self.macsp, + Context::rtpath(self.ecx, + "Argument"))); + let fmt = Context::static_array(self.ecx, "__STATIC_FMTARGS", piece_ty, self.pieces); ("new_v1_formatted", vec![pieces, args_slice, fmt]) }; @@ -569,13 +588,16 @@ impl<'a, 'b> Context<'a, 'b> { self.ecx.expr_call_global(self.macsp, path, fn_args) } - fn format_arg(ecx: &ExtCtxt, macsp: Span, sp: Span, - ty: &ArgumentType, arg: P) + fn format_arg(ecx: &ExtCtxt, + macsp: Span, + sp: Span, + ty: &ArgumentType, + arg: P) -> P { let trait_ = match *ty { Known(ref tyname) => { match &tyname[..] { - "" => "Display", + "" => "Display", "?" => "Debug", "e" => "LowerExp", "E" => "UpperExp", @@ -585,16 +607,14 @@ impl<'a, 'b> Context<'a, 'b> { "x" => "LowerHex", "X" => "UpperHex", _ => { - ecx.span_err(sp, - &format!("unknown format trait `{}`", - *tyname)); + ecx.span_err(sp, &format!("unknown format trait `{}`", *tyname)); "Dummy" } } } Unsigned => { let path = ecx.std_path(&["fmt", "ArgumentV1", "from_usize"]); - return ecx.expr_call_global(macsp, path, vec![arg]) + return ecx.expr_call_global(macsp, path, vec![arg]); } }; @@ -605,22 +625,23 @@ impl<'a, 'b> Context<'a, 'b> { } } -pub fn expand_format_args<'cx>(ecx: &'cx mut ExtCtxt, sp: Span, +pub fn expand_format_args<'cx>(ecx: &'cx mut ExtCtxt, + sp: Span, tts: &[ast::TokenTree]) - -> Box { + -> Box { match parse_args(ecx, sp, tts) { Some((efmt, args, order, names)) => { - MacEager::expr(expand_preparsed_format_args(ecx, sp, efmt, - args, order, names)) + MacEager::expr(expand_preparsed_format_args(ecx, sp, efmt, args, order, names)) } - None => DummyResult::expr(sp) + None => DummyResult::expr(sp), } } /// Take the various parts of `format_args!(efmt, args..., name=names...)` /// and construct the appropriate formatting expression. -pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span, +pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, + sp: Span, efmt: P, args: Vec>, name_ordering: Vec, @@ -648,11 +669,9 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span, macsp: macsp, fmtsp: efmt.span, }; - let fmt = match expr_to_string(cx.ecx, - efmt, - "format argument must be a string literal.") { + let fmt = match expr_to_string(cx.ecx, efmt, "format argument must be a string literal.") { Some((fmt, _)) => fmt, - None => return DummyResult::raw_expr(sp) + None => return DummyResult::raw_expr(sp), }; let mut parser = parse::Parser::new(&fmt); @@ -660,7 +679,9 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span, loop { match parser.next() { Some(piece) => { - if !parser.errors.is_empty() { break } + if !parser.errors.is_empty() { + break; + } cx.verify_piece(&piece); match cx.trans_piece(&piece) { Some(piece) => { @@ -671,12 +692,12 @@ pub fn expand_preparsed_format_args(ecx: &mut ExtCtxt, sp: Span, None => {} } } - None => break + None => break, } } if !parser.errors.is_empty() { - cx.ecx.span_err(cx.fmtsp, &format!("invalid format string: {}", - parser.errors.remove(0))); + cx.ecx.span_err(cx.fmtsp, + &format!("invalid format string: {}", parser.errors.remove(0))); return DummyResult::raw_expr(sp); } if !cx.literal.is_empty() { diff --git a/src/libsyntax_ext/log_syntax.rs b/src/libsyntax_ext/log_syntax.rs index ee944abb645dc..4a40a310b75ba 100644 --- a/src/libsyntax_ext/log_syntax.rs +++ b/src/libsyntax_ext/log_syntax.rs @@ -17,7 +17,7 @@ use syntax::print; pub fn expand_syntax_ext<'cx>(cx: &'cx mut base::ExtCtxt, sp: codemap::Span, tts: &[ast::TokenTree]) - -> Box { + -> Box { if !cx.ecfg.enable_log_syntax() { feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, "log_syntax", diff --git a/src/libsyntax_ext/trace_macros.rs b/src/libsyntax_ext/trace_macros.rs index 7b1e985442adb..f3651b05542f7 100644 --- a/src/libsyntax_ext/trace_macros.rs +++ b/src/libsyntax_ext/trace_macros.rs @@ -19,7 +19,7 @@ use syntax::parse::token::keywords; pub fn expand_trace_macros(cx: &mut ExtCtxt, sp: Span, tt: &[TokenTree]) - -> Box { + -> Box { if !cx.ecfg.enable_trace_macros() { feature_gate::emit_feature_err(&cx.parse_sess.span_diagnostic, "trace_macros",