Merge pull request #1161 from sinkuu/fix550

Fix #550: `if` nested in tuple is indented oddly
This commit is contained in:
Nick Cameron 2016-09-19 08:49:38 +12:00 committed by GitHub
commit fb8a1903cf
4 changed files with 55 additions and 6 deletions

View File

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

View File

@ -1732,11 +1732,16 @@ pub fn rewrite_tuple<'a, I>(context: &RewriteContext,
<I::Item as Deref>::Target: Rewrite + Spanned + 'a <I::Item as Deref>::Target: Rewrite + Spanned + 'a
{ {
let indent = offset + 1; let indent = offset + 1;
let aligned = RewriteContext { block_indent: indent, ..context.clone() };
// In case of length 1, need a trailing comma // In case of length 1, need a trailing comma
if items.len() == 1 { if items.len() == 1 {
// 3 = "(" + ",)" // 3 = "(" + ",)"
let budget = try_opt!(width.checked_sub(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, "("); let list_lo = context.codemap.span_after(span, "(");
@ -1749,7 +1754,7 @@ pub fn rewrite_tuple<'a, I>(context: &RewriteContext,
let inner_width = try_opt!(context.config let inner_width = try_opt!(context.config
.max_width .max_width
.checked_sub(indent.width() + 1)); .checked_sub(indent.width() + 1));
item.rewrite(context, inner_width, indent) item.rewrite(&aligned, inner_width, indent)
}, },
list_lo, list_lo,
span.hi - BytePos(1)); 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), ((bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb),
bbbbbbbbbbbbbbbbbb) 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
}));
}