commit
bd32589ff5
@ -382,7 +382,7 @@ fn rewrite_closure(capture: ast::CaptureClause,
|
||||
let rewrite = inner_expr.rewrite(context, budget, offset + extra_offset);
|
||||
|
||||
// Checks if rewrite succeeded and fits on a single line.
|
||||
let accept_rewrite = rewrite.as_ref().map(|result| !result.contains('\n')).unwrap_or(false);
|
||||
let accept_rewrite = rewrite.as_ref().map_or(false, |result| !result.contains('\n'));
|
||||
|
||||
if accept_rewrite {
|
||||
return Some(format!("{}{}{}{}", prefix, spacer, rewrite.unwrap(), closer));
|
||||
|
28
src/items.rs
28
src/items.rs
@ -693,17 +693,15 @@ fn format_tuple_struct(context: &RewriteContext,
|
||||
let where_budget = try_opt!(context.config
|
||||
.max_width
|
||||
.checked_sub(last_line_width(&result)));
|
||||
let where_clause_str = try_opt!(rewrite_where_clause(context,
|
||||
&generics.where_clause,
|
||||
context.config,
|
||||
context.config.item_brace_style,
|
||||
context.block_indent,
|
||||
where_budget,
|
||||
Density::Compressed,
|
||||
";",
|
||||
None));
|
||||
|
||||
where_clause_str
|
||||
try_opt!(rewrite_where_clause(context,
|
||||
&generics.where_clause,
|
||||
context.config,
|
||||
context.config.item_brace_style,
|
||||
context.block_indent,
|
||||
where_budget,
|
||||
Density::Compressed,
|
||||
";",
|
||||
None))
|
||||
}
|
||||
None => "".to_owned(),
|
||||
};
|
||||
@ -1114,8 +1112,7 @@ fn rewrite_fn_base(context: &RewriteContext,
|
||||
// A conservative estimation, to goal is to be over all parens in generics
|
||||
let args_start = generics.ty_params
|
||||
.last()
|
||||
.map(|tp| end_typaram(tp))
|
||||
.unwrap_or(span.lo);
|
||||
.map_or(span.lo, |tp| end_typaram(tp));
|
||||
let args_span = mk_sp(span_after(mk_sp(args_start, span.hi), "(", context.codemap),
|
||||
span_for_return(&fd.output).lo);
|
||||
let arg_str = try_opt!(rewrite_args(context,
|
||||
@ -1243,11 +1240,10 @@ fn rewrite_args(context: &RewriteContext,
|
||||
let min_args = explicit_self.and_then(|explicit_self| {
|
||||
rewrite_explicit_self(explicit_self, args, context)
|
||||
})
|
||||
.map(|self_str| {
|
||||
.map_or(1, |self_str| {
|
||||
arg_item_strs[0] = self_str;
|
||||
2
|
||||
})
|
||||
.unwrap_or(1);
|
||||
});
|
||||
|
||||
// Comments between args.
|
||||
let mut arg_items = Vec::new();
|
||||
|
14
src/lists.rs
14
src/lists.rs
@ -129,9 +129,8 @@ pub struct ListItem {
|
||||
|
||||
impl ListItem {
|
||||
pub fn is_multiline(&self) -> bool {
|
||||
self.item.as_ref().map(|s| s.contains('\n')).unwrap_or(false) ||
|
||||
self.pre_comment.is_some() ||
|
||||
self.post_comment.as_ref().map(|s| s.contains('\n')).unwrap_or(false)
|
||||
self.item.as_ref().map_or(false, |s| s.contains('\n')) || self.pre_comment.is_some() ||
|
||||
self.post_comment.as_ref().map_or(false, |s| s.contains('\n'))
|
||||
}
|
||||
|
||||
pub fn has_line_pre_comment(&self) -> bool {
|
||||
@ -156,10 +155,7 @@ pub enum DefinitiveListTactic {
|
||||
Mixed,
|
||||
}
|
||||
|
||||
pub fn definitive_tactic<'t, I, T>(items: I,
|
||||
tactic: ListTactic,
|
||||
width: usize)
|
||||
-> DefinitiveListTactic
|
||||
pub fn definitive_tactic<I, T>(items: I, tactic: ListTactic, width: usize) -> DefinitiveListTactic
|
||||
where I: IntoIterator<Item = T> + Clone,
|
||||
T: AsRef<ListItem>
|
||||
{
|
||||
@ -493,7 +489,7 @@ fn needs_trailing_separator(separator_tactic: SeparatorTactic,
|
||||
}
|
||||
|
||||
/// Returns the count and total width of the list items.
|
||||
fn calculate_width<'li, I, T>(items: I) -> (usize, usize)
|
||||
fn calculate_width<I, T>(items: I) -> (usize, usize)
|
||||
where I: IntoIterator<Item = T>,
|
||||
T: AsRef<ListItem>
|
||||
{
|
||||
@ -505,7 +501,7 @@ fn calculate_width<'li, I, T>(items: I) -> (usize, usize)
|
||||
fn total_item_width(item: &ListItem) -> usize {
|
||||
comment_len(item.pre_comment.as_ref().map(|x| &(*x)[..])) +
|
||||
comment_len(item.post_comment.as_ref().map(|x| &(*x)[..])) +
|
||||
item.item.as_ref().map(|str| str.len()).unwrap_or(0)
|
||||
item.item.as_ref().map_or(0, |str| str.len())
|
||||
}
|
||||
|
||||
fn comment_len(comment: Option<&str>) -> usize {
|
||||
|
@ -122,8 +122,7 @@ fn replace_chars(string: &str) -> String {
|
||||
.skip_while(|rev_c| [' ', '\t'].contains(&rev_c))
|
||||
.next();
|
||||
|
||||
let fix_indent = last_char.map(|rev_c| ['{', '\n'].contains(&rev_c))
|
||||
.unwrap_or(true);
|
||||
let fix_indent = last_char.map_or(true, |rev_c| ['{', '\n'].contains(&rev_c));
|
||||
|
||||
if rewrite_next_comment && fix_indent {
|
||||
if let Some('{') = last_char {
|
||||
|
@ -30,7 +30,7 @@ pub fn rewrite_path(context: &RewriteContext,
|
||||
width: usize,
|
||||
offset: Indent)
|
||||
-> Option<String> {
|
||||
let skip_count = qself.map(|x| x.position).unwrap_or(0);
|
||||
let skip_count = qself.map_or(0, |x| x.position);
|
||||
|
||||
let mut result = if path.global {
|
||||
"::".to_owned()
|
||||
|
@ -117,13 +117,12 @@ pub fn contains_skip(attrs: &[Attribute]) -> bool {
|
||||
pub fn end_typaram(typaram: &ast::TyParam) -> BytePos {
|
||||
typaram.bounds
|
||||
.last()
|
||||
.map(|bound| {
|
||||
.map_or(typaram.span, |bound| {
|
||||
match *bound {
|
||||
ast::RegionTyParamBound(ref lt) => lt.span,
|
||||
ast::TraitTyParamBound(ref prt, _) => prt.span,
|
||||
}
|
||||
})
|
||||
.unwrap_or(typaram.span)
|
||||
.hi
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user