let trial = self.rewrite_single_line(&pat_expr_string, context, shape.width);
if let Some(cond_str) = trial {
- if cond_str.len() <= context
- .config
- .width_heuristics()
- .single_line_if_else_max_width
+ if cond_str.len()
+ <= context
+ .config
+ .width_heuristics()
+ .single_line_if_else_max_width
{
return Some((cond_str, 0));
}
}
pub fn is_different_group(&self) -> bool {
- self.inner_as_ref().contains('\n') || self.pre_comment.is_some() || self
- .post_comment
- .as_ref()
- .map_or(false, |s| s.contains('\n'))
+ self.inner_as_ref().contains('\n')
+ || self.pre_comment.is_some()
+ || self
+ .post_comment
+ .as_ref()
+ .map_or(false, |s| s.contains('\n'))
}
pub fn is_multiline(&self) -> bool {
.min()?;
Some(
- first_line + "\n" + &trimmed_lines
- .iter()
- .map(
- |&(trimmed, ref line, prefix_space_width)| match prefix_space_width {
- _ if !trimmed => line.to_owned(),
- Some(original_indent_width) => {
- let new_indent_width = indent.width() + original_indent_width
- .saturating_sub(min_prefix_space_width);
- let new_indent = Indent::from_width(context.config, new_indent_width);
- format!("{}{}", new_indent.to_string(context.config), line)
- }
- None => String::new(),
- },
- )
- .collect::<Vec<_>>()
- .join("\n"),
+ first_line
+ + "\n"
+ + &trimmed_lines
+ .iter()
+ .map(
+ |&(trimmed, ref line, prefix_space_width)| match prefix_space_width {
+ _ if !trimmed => line.to_owned(),
+ Some(original_indent_width) => {
+ let new_indent_width = indent.width()
+ + original_indent_width.saturating_sub(min_prefix_space_width);
+ let new_indent = Indent::from_width(context.config, new_indent_width);
+ format!("{}{}", new_indent.to_string(context.config), line)
+ }
+ None => String::new(),
+ },
+ )
+ .collect::<Vec<_>>()
+ .join("\n"),
)
}
// If the length of the lhs is equal to or shorter than the tab width or
// the rhs looks like block expression, we put the rhs on the same
// line with the lhs even if the rhs is multi-lined.
- let allow_same_line = lhs_result.len() <= tab_spaces || rhs_result
- .lines()
- .next()
- .map(|first_line| first_line.ends_with('{'))
- .unwrap_or(false);
+ let allow_same_line = lhs_result.len() <= tab_spaces
+ || rhs_result
+ .lines()
+ .next()
+ .map(|first_line| first_line.ends_with('{'))
+ .unwrap_or(false);
if !rhs_result.contains('\n') || allow_same_line {
let one_line_width = last_line_width(&lhs_result)
+ pp.infix.len()
}
assert_eq!(list.len() - 1, separators.len());
- Some(PairList {
- list,
- separators,
- })
+ Some(PairList { list, separators })
}
}
return break_at(max_chars - 1);
}
if let Some(url_index_end) = detect_url(input, max_chars) {
- let index_plus_ws = url_index_end + input[url_index_end..]
- .iter()
- .skip(1)
- .position(|grapheme| not_whitespace_except_line_feed(grapheme))
- .unwrap_or(0);
+ let index_plus_ws = url_index_end
+ + input[url_index_end..]
+ .iter()
+ .skip(1)
+ .position(|grapheme| not_whitespace_except_line_feed(grapheme))
+ .unwrap_or(0);
return if trim_end {
SnippetState::LineEnd(
input[..=url_index_end].join("").to_string(),
// Return true if the given span does not intersect with file lines.
macro_rules! out_of_file_lines_range {
($self:ident, $span:expr) => {
- !$self.config.file_lines().is_all() && !$self
- .config
- .file_lines()
- .intersects(&$self.source_map.lookup_line_range($span))
+ !$self.config.file_lines().is_all()
+ && !$self
+ .config
+ .file_lines()
+ .intersects(&$self.source_map.lookup_line_range($span))
};
}