Merge pull request #146 from marcusklaas/fix-inverted-span

Format unnamed function arguments
This commit is contained in:
Nick Cameron 2015-07-21 07:38:20 +12:00
commit 8e8a5b3990
2 changed files with 29 additions and 5 deletions

View File

@ -289,10 +289,10 @@ impl<'a> FmtVisitor<'a> {
arg_items = itemize_list(self.codemap, arg_items = itemize_list(self.codemap,
arg_items, arg_items,
args[min_args-1..].iter(), args[min_args-1..].iter().cloned(),
",", ",",
")", ")",
|arg| arg.pat.span.lo, span_lo_for_arg,
|arg| arg.ty.span.hi, |arg| arg.ty.span.hi,
|_| String::new(), |_| String::new(),
comment_span_start, comment_span_start,
@ -780,9 +780,29 @@ impl<'a> FmtVisitor<'a> {
// TODO we farm this out, but this could spill over the column limit, so we // TODO we farm this out, but this could spill over the column limit, so we
// ought to handle it properly. // ought to handle it properly.
fn rewrite_fn_input(&self, arg: &ast::Arg) -> String { fn rewrite_fn_input(&self, arg: &ast::Arg) -> String {
format!("{}: {}", if is_named_arg(arg) {
pprust::pat_to_string(&arg.pat), format!("{}: {}",
pprust::ty_to_string(&arg.ty)) pprust::pat_to_string(&arg.pat),
pprust::ty_to_string(&arg.ty))
} else {
pprust::ty_to_string(&arg.ty)
}
}
}
fn span_lo_for_arg(arg: &ast::Arg) -> BytePos {
if is_named_arg(arg) {
arg.pat.span.lo
} else {
arg.ty.span.lo
}
}
fn is_named_arg(arg: &ast::Arg) -> bool {
if let ast::Pat_::PatIdent(_, ident, _) = arg.pat.node {
ident.node != token::special_idents::invalid
} else {
true
} }
} }

View File

@ -18,3 +18,7 @@ trait Foo {
fn read(&mut self, x: BufReader<R> /* Used to be MemReader */) fn read(&mut self, x: BufReader<R> /* Used to be MemReader */)
where R: Read; where R: Read;
} }
pub trait WriteMessage {
fn write_message(&mut self, &FrontendMessage) -> io::Result<()>;
}