use config::lists::*;
use syntax::ast::{self, FunctionRetTy, Mutability};
-use syntax::codemap::{self, BytePos, Span};
+use syntax::source_map::{self, BytePos, Span};
use syntax::symbol::keywords;
-use codemap::SpanUtils;
use config::{IndentStyle, TypeDensity};
use expr::{rewrite_assign_rhs, rewrite_tuple, rewrite_unary_prefix, ToExpr};
use lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator};
use pairs::{rewrite_pair, PairParts};
use rewrite::{Rewrite, RewriteContext};
use shape::Shape;
+use source_map::SpanUtils;
use spanned::Spanned;
use utils::{
colon_spaces, extra_offset, first_line_width, format_abi, format_mutability,
ast::GenericArgs::Parenthesized(ref data) => {
let output = match data.output {
Some(ref ty) => FunctionRetTy::Ty(ty.clone()),
- None => FunctionRetTy::Default(codemap::DUMMY_SP),
+ None => FunctionRetTy::Default(source_map::DUMMY_SP),
};
result.push_str(&format_function_type(
data.inputs.iter().map(|x| &**x),
<I as Iterator>::Item: Deref,
<I::Item as Deref>::Target: Rewrite + Spanned + 'a,
{
+ debug!("format_function_type {:#?}", shape);
+
// Code for handling variadics is somewhat duplicated for items, but they
// are different enough to need some serious refactoring to share code.
enum ArgumentKind<T>
Separator::Comma,
budget,
);
-
- let fmt = ListFormatting {
- tactic,
- separator: ",",
- trailing_separator: if !context.use_block_indent() || variadic {
- SeparatorTactic::Never
- } else {
- context.config.trailing_comma()
- },
- separator_place: SeparatorPlace::Back,
- shape: list_shape,
- ends_with_newline: tactic.ends_with_newline(context.config.indent_style()),
- preserve_newline: true,
- nested: false,
- config: context.config,
+ let trailing_separator = if !context.use_block_indent() || variadic {
+ SeparatorTactic::Never
+ } else {
+ context.config.trailing_comma()
};
+ let fmt = ListFormatting::new(list_shape, context.config)
+ .tactic(tactic)
+ .trailing_separator(trailing_separator)
+ .ends_with_newline(tactic.ends_with_newline(context.config.indent_style()))
+ .preserve_newline(true);
let list_str = write_list(&item_vec, &fmt)?;
let ty_shape = match context.config.indent_style() {
shape.block().indent.to_string_with_newline(context.config),
)
};
- if last_line_width(&args) + first_line_width(&output) <= shape.width {
+ if output.is_empty() || last_line_width(&args) + first_line_width(&output) <= shape.width {
Some(format!("{}{}", args, output))
} else {
Some(format!(
impl Rewrite for ast::GenericBounds {
fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
- join_bounds(context, shape, self, true)
+ if self.is_empty() {
+ return Some(String::new());
+ }
+
+ let span = mk_sp(self.get(0)?.span().lo(), self.last()?.span().hi());
+ let has_paren = context.snippet(span).starts_with('(');
+ let bounds_shape = if has_paren {
+ shape.offset_left(1)?.sub_width(1)?
+ } else {
+ shape
+ };
+ join_bounds(context, bounds_shape, self, true).map(|s| {
+ if has_paren {
+ format!("({})", s)
+ } else {
+ s
+ }
+ })
}
}
context: &RewriteContext,
shape: Shape,
) -> Option<String> {
+ debug!("rewrite_bare_fn {:#?}", shape);
+
let mut result = String::with_capacity(128);
if let Some(ref lifetime_str) = rewrite_lifetime_param(context, shape, &bare_fn.generic_params)
result.push_str("fn");
- let func_ty_shape = shape.offset_left(result.len())?;
+ let func_ty_shape = if context.use_block_indent() {
+ shape.offset_left(result.len())?
+ } else {
+ shape.visual_indent(result.len()).sub_width(result.len())?
+ };
let rewrite = format_function_type(
bare_fn.decl.inputs.iter(),