-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
run rustfmt on libsyntax_ext folder #34114
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<base::MacResult+'cx> { | ||
pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, | ||
sp: Span, | ||
tts: &[ast::TokenTree]) | ||
-> Box<base::MacResult + 'cx> { | ||
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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @nrc I would love if rustfmt would avoid this kind of indentation (when you have a multi-line closure in the middle of a method chain). |
||
.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 { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is less readable |
||
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 { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. less readable |
||
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 { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also less readable |
||
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, | ||
} | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
// | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This extra |
||
|
||
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<base::MacResult+'cx> { | ||
pub fn expand_option_env<'cx>(cx: &'cx mut ExtCtxt, | ||
sp: Span, | ||
tts: &[ast::TokenTree]) | ||
-> Box<base::MacResult + 'cx> { | ||
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<base::MacResult+'cx> { | ||
pub fn expand_env<'cx>(cx: &'cx mut ExtCtxt, | ||
sp: Span, | ||
tts: &[ast::TokenTree]) | ||
-> Box<base::MacResult + 'cx> { | ||
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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is removing the alignment like this ok?