mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-12 20:16:49 +00:00
Merge pull request #132 from cassiersg/fix-tup-lit
Fix bug in rewrite_tup_lit
This commit is contained in:
commit
337c5b5fba
17
src/expr.rs
17
src/expr.rs
@ -239,7 +239,13 @@ fn rewrite_tuple_lit(context: &RewriteContext,
|
||||
width: usize,
|
||||
offset: usize)
|
||||
-> Option<String> {
|
||||
debug!("rewrite_tuple_lit: width: {}, offset: {}", width, offset);
|
||||
let indent = offset + 1;
|
||||
// In case of length 1, need a trailing comma
|
||||
if items.len() == 1 {
|
||||
// 3 = "(" + ",)"
|
||||
return items[0].rewrite(context, width - 3, indent).map(|s| format!("({},)", s));
|
||||
}
|
||||
|
||||
let items = itemize_list(context.codemap,
|
||||
Vec::new(),
|
||||
@ -249,23 +255,16 @@ fn rewrite_tuple_lit(context: &RewriteContext,
|
||||
|item| item.span.lo,
|
||||
|item| item.span.hi,
|
||||
|item| item.rewrite(context,
|
||||
context.config.max_width - indent - 2,
|
||||
context.config.max_width - indent - 1,
|
||||
indent)
|
||||
.unwrap_or(context.codemap.span_to_snippet(item.span)
|
||||
.unwrap()),
|
||||
span.lo + BytePos(1), // Remove parens
|
||||
span.hi - BytePos(1));
|
||||
|
||||
// In case of length 1, need a trailing comma
|
||||
let trailing_separator_tactic = if items.len() == 1 {
|
||||
SeparatorTactic::Always
|
||||
} else {
|
||||
SeparatorTactic::Never
|
||||
};
|
||||
|
||||
let fmt = ListFormatting { tactic: ListTactic::HorizontalVertical,
|
||||
separator: ",",
|
||||
trailing_separator: trailing_separator_tactic,
|
||||
trailing_separator: SeparatorTactic::Never,
|
||||
indent: indent,
|
||||
h_width: width - 2,
|
||||
v_width: width - 2,
|
||||
|
@ -13,3 +13,17 @@ fn foo() {
|
||||
b, // Comment
|
||||
b /* Trailing comment */);
|
||||
}
|
||||
|
||||
fn a() {
|
||||
((aaaaaaaa,
|
||||
aaaaaaaaaaaaa,
|
||||
aaaaaaaaaaaaaaaaa,
|
||||
aaaaaaaaaaaaaa,
|
||||
aaaaaaaaaaaaaaaa,
|
||||
aaaaaaaaaaaaaa),)
|
||||
}
|
||||
|
||||
fn b() {
|
||||
((bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb),
|
||||
bbbbbbbbbbbbbbbbbb)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user