mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-25 13:24:22 +00:00
Merge pull request #1161 from sinkuu/fix550
Fix #550: `if` nested in tuple is indented oddly
This commit is contained in:
commit
fb8a1903cf
@ -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))
|
||||||
}
|
}
|
||||||
|
@ -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
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),
|
((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
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user