Rebase onto master
This commit is contained in:
parent
a9814149c9
commit
48d17f54d3
3 changed files with 85 additions and 97 deletions
28
src/expr.rs
28
src/expr.rs
|
@ -723,11 +723,8 @@ impl Rewrite for ast::Arm {
|
||||||
// Let's try and get the arm body on the same line as the condition.
|
// Let's try and get the arm body on the same line as the condition.
|
||||||
// 4 = ` => `.len()
|
// 4 = ` => `.len()
|
||||||
if context.config.max_width > line_start + comma.len() + 4 {
|
if context.config.max_width > line_start + comma.len() + 4 {
|
||||||
let inner_offset = line_start + 4;
|
|
||||||
let budget = context.config.max_width - line_start - comma.len() - 4;
|
let budget = context.config.max_width - line_start - comma.len() - 4;
|
||||||
if let Some(ref body_str) = body.rewrite(context,
|
if let Some(ref body_str) = body.rewrite(context, budget, line_start + 4) {
|
||||||
budget,
|
|
||||||
line_start + 4) {
|
|
||||||
if first_line_width(body_str) <= budget {
|
if first_line_width(body_str) <= budget {
|
||||||
return Some(format!("{}{} => {}{}",
|
return Some(format!("{}{} => {}{}",
|
||||||
attr_str.trim_left(),
|
attr_str.trim_left(),
|
||||||
|
@ -928,8 +925,12 @@ fn rewrite_call_inner<R>(context: &RewriteContext,
|
||||||
None => return Err(Ordering::Greater),
|
None => return Err(Ordering::Greater),
|
||||||
};
|
};
|
||||||
let offset = offset + extra_offset + 1;
|
let offset = offset + extra_offset + 1;
|
||||||
let inner_indent = expr_indent(context, offset);
|
let block_indent = if args.len() == 1 {
|
||||||
let inner_context = context.overflow_context(inner_indent - context.block_indent);
|
context.block_indent
|
||||||
|
} else {
|
||||||
|
offset
|
||||||
|
};
|
||||||
|
let inner_context = &RewriteContext { block_indent: block_indent, ..*context };
|
||||||
|
|
||||||
let items = itemize_list(context.codemap,
|
let items = itemize_list(context.codemap,
|
||||||
args.iter(),
|
args.iter(),
|
||||||
|
@ -953,21 +954,6 @@ fn rewrite_call_inner<R>(context: &RewriteContext,
|
||||||
Ok(format!("{}({})", callee_str, list_str))
|
Ok(format!("{}({})", callee_str, list_str))
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! block_indent_helper {
|
|
||||||
($name:ident, $option:ident) => (
|
|
||||||
fn $name(context: &RewriteContext, offset: usize) -> usize {
|
|
||||||
match context.config.$option {
|
|
||||||
BlockIndentStyle::Inherit => context.block_indent,
|
|
||||||
BlockIndentStyle::Tabbed => context.block_indent + context.config.tab_spaces,
|
|
||||||
BlockIndentStyle::Visual => offset,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
block_indent_helper!(expr_indent, expr_indent_style);
|
|
||||||
block_indent_helper!(closure_indent, closure_indent_style);
|
|
||||||
|
|
||||||
fn rewrite_paren(context: &RewriteContext,
|
fn rewrite_paren(context: &RewriteContext,
|
||||||
subexpr: &ast::Expr,
|
subexpr: &ast::Expr,
|
||||||
width: usize,
|
width: usize,
|
||||||
|
|
152
src/lists.rs
152
src/lists.rs
|
@ -269,18 +269,21 @@ impl<'a, T, I, F1, F2, F3> Iterator for ListItems<'a, I, F1, F2, F3>
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let white_space: &[_] = &[' ', '\t'];
|
let white_space: &[_] = &[' ', '\t'];
|
||||||
|
|
||||||
self.inner.next().map(|item| {
|
self.inner
|
||||||
let mut new_lines = false;
|
.next()
|
||||||
// Pre-comment
|
.map(|item| {
|
||||||
let pre_snippet = self.codemap.span_to_snippet(codemap::mk_sp(self.prev_span_end,
|
let mut new_lines = false;
|
||||||
(self.get_lo)(&item)))
|
// Pre-comment
|
||||||
.unwrap();
|
let pre_snippet = self.codemap
|
||||||
let trimmed_pre_snippet = pre_snippet.trim();
|
.span_to_snippet(codemap::mk_sp(self.prev_span_end,
|
||||||
let pre_comment = if !trimmed_pre_snippet.is_empty() {
|
(self.get_lo)(&item)))
|
||||||
Some(trimmed_pre_snippet.to_owned())
|
.unwrap();
|
||||||
} else {
|
let trimmed_pre_snippet = pre_snippet.trim();
|
||||||
None
|
let pre_comment = if !trimmed_pre_snippet.is_empty() {
|
||||||
};
|
Some(trimmed_pre_snippet.to_owned())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
// Post-comment
|
// Post-comment
|
||||||
let next_start = match self.inner.peek() {
|
let next_start = match self.inner.peek() {
|
||||||
|
@ -300,76 +303,75 @@ impl<'a, T, I, F1, F2, F3> Iterator for ListItems<'a, I, F1, F2, F3>
|
||||||
|
|
||||||
match (block_open_index, newline_index) {
|
match (block_open_index, newline_index) {
|
||||||
// Separator before comment, with the next item on same line.
|
// Separator before comment, with the next item on same line.
|
||||||
// Comment belongs to next item.
|
// Comment belongs to next item.
|
||||||
(Some(i), None) if i > separator_index => {
|
(Some(i), None) if i > separator_index => {
|
||||||
separator_index + 1
|
separator_index + 1
|
||||||
|
}
|
||||||
|
// Block-style post-comment before the separator.
|
||||||
|
(Some(i), None) => {
|
||||||
|
cmp::max(find_comment_end(&post_snippet[i..]).unwrap() + i,
|
||||||
|
separator_index + 1)
|
||||||
|
}
|
||||||
|
// Block-style post-comment. Either before or after the separator.
|
||||||
|
(Some(i), Some(j)) if i < j => {
|
||||||
|
cmp::max(find_comment_end(&post_snippet[i..]).unwrap() + i,
|
||||||
|
separator_index + 1)
|
||||||
|
}
|
||||||
|
// Potential *single* line comment.
|
||||||
|
(_, Some(j)) => j + 1,
|
||||||
|
_ => post_snippet.len(),
|
||||||
}
|
}
|
||||||
// Block-style post-comment before the separator.
|
|
||||||
(Some(i), None) => {
|
|
||||||
cmp::max(find_comment_end(&post_snippet[i..]).unwrap() + i,
|
|
||||||
separator_index + 1)
|
|
||||||
}
|
|
||||||
// Block-style post-comment. Either before or after the separator.
|
|
||||||
(Some(i), Some(j)) if i < j => {
|
|
||||||
cmp::max(find_comment_end(&post_snippet[i..]).unwrap() + i,
|
|
||||||
separator_index + 1)
|
|
||||||
}
|
|
||||||
// Potential *single* line comment.
|
|
||||||
(_, Some(j)) => j + 1,
|
|
||||||
_ => post_snippet.len()
|
|
||||||
}
|
}
|
||||||
},
|
None => {
|
||||||
None => {
|
post_snippet.find_uncommented(self.terminator).unwrap_or(post_snippet.len())
|
||||||
post_snippet.find_uncommented(self.terminator)
|
}
|
||||||
.unwrap_or(post_snippet.len())
|
};
|
||||||
|
|
||||||
|
if !post_snippet.is_empty() && comment_end > 0 {
|
||||||
|
// Account for extra whitespace between items. This is fiddly
|
||||||
|
// because of the way we divide pre- and post- comments.
|
||||||
|
|
||||||
|
// Everything from the separator to the next item.
|
||||||
|
let test_snippet = &post_snippet[comment_end-1..];
|
||||||
|
let first_newline = test_snippet.find('\n').unwrap_or(test_snippet.len());
|
||||||
|
// From the end of the first line of comments.
|
||||||
|
let test_snippet = &test_snippet[first_newline..];
|
||||||
|
let first = test_snippet.find(|c: char| !c.is_whitespace())
|
||||||
|
.unwrap_or(test_snippet.len());
|
||||||
|
// From the end of the first line of comments to the next non-whitespace char.
|
||||||
|
let test_snippet = &test_snippet[..first];
|
||||||
|
|
||||||
|
if test_snippet.chars().filter(|c| c == &'\n').count() > 1 {
|
||||||
|
// There were multiple line breaks which got trimmed to nothing.
|
||||||
|
new_lines = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
if !post_snippet.is_empty() && comment_end > 0 {
|
// Cleanup post-comment: strip separators and whitespace.
|
||||||
// Account for extra whitespace between items. This is fiddly
|
self.prev_span_end = (self.get_hi)(&item) + BytePos(comment_end as u32);
|
||||||
// because of the way we divide pre- and post- comments.
|
let post_snippet = post_snippet[..comment_end].trim();
|
||||||
|
|
||||||
// Everything from the separator to the next item.
|
let post_snippet_trimmed = if post_snippet.starts_with(',') {
|
||||||
let test_snippet = &post_snippet[comment_end-1..];
|
post_snippet[1..].trim_matches(white_space)
|
||||||
let first_newline = test_snippet.find('\n').unwrap_or(test_snippet.len());
|
} else if post_snippet.ends_with(",") {
|
||||||
// From the end of the first line of comments.
|
post_snippet[..(post_snippet.len() - 1)].trim_matches(white_space)
|
||||||
let test_snippet = &test_snippet[first_newline..];
|
} else {
|
||||||
let first = test_snippet.find(|c: char| !c.is_whitespace())
|
post_snippet
|
||||||
.unwrap_or(test_snippet.len());
|
};
|
||||||
// From the end of the first line of comments to the next non-whitespace char.
|
|
||||||
let test_snippet = &test_snippet[..first];
|
|
||||||
|
|
||||||
if test_snippet.chars().filter(|c| c == &'\n').count() > 1 {
|
let post_comment = if !post_snippet_trimmed.is_empty() {
|
||||||
// There were multiple line breaks which got trimmed to nothing.
|
Some(post_snippet_trimmed.to_owned())
|
||||||
new_lines = true;
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
|
||||||
|
ListItem {
|
||||||
|
pre_comment: pre_comment,
|
||||||
|
item: (self.get_item_string)(&item),
|
||||||
|
post_comment: post_comment,
|
||||||
|
new_lines: new_lines,
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
|
|
||||||
// Cleanup post-comment: strip separators and whitespace.
|
|
||||||
self.prev_span_end = (self.get_hi)(&item) + BytePos(comment_end as u32);
|
|
||||||
let post_snippet = post_snippet[..comment_end].trim();
|
|
||||||
|
|
||||||
let post_snippet_trimmed = if post_snippet.starts_with(',') {
|
|
||||||
post_snippet[1..].trim_matches(white_space)
|
|
||||||
} else if post_snippet.ends_with(",") {
|
|
||||||
post_snippet[..(post_snippet.len() - 1)].trim_matches(white_space)
|
|
||||||
} else {
|
|
||||||
post_snippet
|
|
||||||
};
|
|
||||||
|
|
||||||
let post_comment = if !post_snippet_trimmed.is_empty() {
|
|
||||||
Some(post_snippet_trimmed.to_owned())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
ListItem {
|
|
||||||
pre_comment: pre_comment,
|
|
||||||
item: (self.get_item_string)(&item),
|
|
||||||
post_comment: post_comment,
|
|
||||||
new_lines: new_lines,
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ fn foo() {
|
||||||
// Test that a match on an overflow line is laid out properly.
|
// Test that a match on an overflow line is laid out properly.
|
||||||
fn main() {
|
fn main() {
|
||||||
let sub_span =
|
let sub_span =
|
||||||
match self.span.sub_span_after_keywooooooooooooooooooooord(use_item.span, keywords::As) {
|
match xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx {
|
||||||
Some(sub_span) => Some(sub_span),
|
Some(sub_span) => Some(sub_span),
|
||||||
None => sub_span,
|
None => sub_span,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue