mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-11 08:05:12 +00:00
Fix #550: if
nested in tuple is indented oddly
This commit is contained in:
parent
4418fab4f2
commit
079f39d07f
@ -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))
|
||||
}
|
||||
|
@ -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
34
tests/source/tuple.rs
Normal 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}));
|
||||
}
|
@ -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
|
||||
}));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user