pub fn rewrite_associated_type(
ident: ast::Ident,
ty_opt: Option<&ptr::P<ast::Ty>>,
+ generics: &ast::Generics,
generic_bounds_opt: Option<&ast::GenericBounds>,
context: &RewriteContext,
indent: Indent,
) -> Option<String> {
- let prefix = format!("type {}", rewrite_ident(context, ident));
+ let ident_str = rewrite_ident(context, ident);
+ // 5 = "type "
+ let generics_shape = Shape::indented(indent, context.config).offset_left(5)?;
+ let generics_str = rewrite_generics(context, ident_str, generics, generics_shape)?;
+ let prefix = format!("type {}", generics_str);
let type_bounds_str = if let Some(bounds) = generic_bounds_opt {
if bounds.is_empty() {
pub fn rewrite_existential_impl_type(
context: &RewriteContext,
ident: ast::Ident,
+ generics: &ast::Generics,
generic_bounds: &ast::GenericBounds,
indent: Indent,
) -> Option<String> {
- rewrite_associated_type(ident, None, Some(generic_bounds), context, indent)
+ rewrite_associated_type(ident, None, generics, Some(generic_bounds), context, indent)
.map(|s| format!("existential {}", s))
}
ident: ast::Ident,
defaultness: ast::Defaultness,
ty_opt: Option<&ptr::P<ast::Ty>>,
+ generics: &ast::Generics,
context: &RewriteContext,
indent: Indent,
) -> Option<String> {
- let result = rewrite_associated_type(ident, ty_opt, None, context, indent)?;
+ let result = rewrite_associated_type(ident, ty_opt, generics, None, context, indent)?;
match defaultness {
ast::Defaultness::Default => Some(format!("default {}", result)),
let used_width = last_line_used_width(&result, indent.width()) + first_line_width(&ret_str);
// Put the closing brace on the next line if it overflows the max width.
// 1 = `)`
- if fd.inputs.is_empty() && used_width + 1 > context.config.max_width() {
- result.push('\n');
- }
+ let closing_paren_overflow_max_width =
+ fd.inputs.is_empty() && used_width + 1 > context.config.max_width();
// If the last line of args contains comment, we cannot put the closing paren
// on the same line.
- if arg_str
+ args_last_line_contains_comment = arg_str
.lines()
.last()
- .map_or(false, |last_line| last_line.contains("//"))
- {
- args_last_line_contains_comment = true;
- result.push_str(&arg_indent.to_string_with_newline(context.config));
+ .map_or(false, |last_line| last_line.contains("//"));
+ if closing_paren_overflow_max_width || args_last_line_contains_comment {
+ result.push_str(&indent.to_string_with_newline(context.config));
}
result.push(')');
}
) -> Option<String> {
let mut arg_item_strs = args
.iter()
- .map(|arg| arg.rewrite(context, Shape::legacy(multi_line_budget, arg_indent)))
- .collect::<Option<Vec<_>>>()?;
+ .map(|arg| {
+ arg.rewrite(context, Shape::legacy(multi_line_budget, arg_indent))
+ .unwrap_or_else(|| context.snippet(arg.span()).to_owned())
+ }).collect::<Vec<_>>();
// Account for sugary self.
// FIXME: the comment for the self argument is dropped. This is blocked