Fix #550: if nested in tuple is indented oddly

This commit is contained in:
sinkuu 2016-09-10 14:02:05 +09:00
parent 4418fab4f2
commit 079f39d07f
4 changed files with 55 additions and 6 deletions

View File

@ -425,10 +425,10 @@ impl<'a> Iterator for UngroupedCommentCodeSlices<'a> {
None => &self.slice[start_idx..],
};
Some((if kind.is_comment() {
CodeCharKind::Comment
} else {
CodeCharKind::Normal
},
CodeCharKind::Comment
} else {
CodeCharKind::Normal
},
start_idx,
slice))
}

View File

@ -1716,11 +1716,16 @@ pub fn rewrite_tuple<'a, I>(context: &RewriteContext,
<I::Item as Deref>::Target: Rewrite + Spanned + 'a
{
let indent = offset + 1;
let aligned = RewriteContext { block_indent: indent, ..context.clone() };
// In case of length 1, need a trailing comma
if items.len() == 1 {
// 3 = "(" + ",)"
let budget = try_opt!(width.checked_sub(3));
return items.next().unwrap().rewrite(context, budget, indent).map(|s| format!("({},)", s));
return items.next()
.unwrap()
.rewrite(&aligned, budget, indent)
.map(|s| format!("({},)", s));
}
let list_lo = context.codemap.span_after(span, "(");
@ -1733,7 +1738,7 @@ pub fn rewrite_tuple<'a, I>(context: &RewriteContext,
let inner_width = try_opt!(context.config
.max_width
.checked_sub(indent.width() + 1));
item.rewrite(context, inner_width, indent)
item.rewrite(&aligned, inner_width, indent)
},
list_lo,
span.hi - BytePos(1));

34
tests/source/tuple.rs Normal file
View File

@ -0,0 +1,34 @@
// Test tuple litterals
fn foo() {
let a = (a, a, a, a, a);
let aaaaaaaaaaaaaaaa = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaa, aaaaaaaaaaaaaa);
let aaaaaaaaaaaaaaaaaaaaaa = (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaa,
aaaa);
let a = (a,);
let b = (// This is a comment
b, // Comment
b /* Trailing comment */);
}
fn a() {
((aaaaaaaa,
aaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaa),)
}
fn b() {
((bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb),
bbbbbbbbbbbbbbbbbb)
}
fn issue550() {
self.visitor.visit_volume(self.level.sector_id(sector), (floor_y,
if is_sky_flat(ceil_tex) {from_wad_height(self.height_range.1)} else {ceil_y}));
}

View File

@ -27,3 +27,13 @@ fn b() {
((bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb),
bbbbbbbbbbbbbbbbbb)
}
fn issue550() {
self.visitor.visit_volume(self.level.sector_id(sector),
(floor_y,
if is_sky_flat(ceil_tex) {
from_wad_height(self.height_range.1)
} else {
ceil_y
}));
}