mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-13 04:26:48 +00:00
Fix some bugs
This commit is contained in:
parent
018fa85453
commit
a32b0e7627
19
src/expr.rs
19
src/expr.rs
@ -192,14 +192,17 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
|
||||
}
|
||||
|
||||
let path_str = pprust::path_to_string(path);
|
||||
// Foo { a: Foo } - indent is +3, width is -5.
|
||||
let (indent, budget) = match context.config.struct_lit_style {
|
||||
let (indent, h_budget, v_budget) = match context.config.struct_lit_style {
|
||||
StructLitStyle::VisualIndent => {
|
||||
(offset + path_str.len() + 3, width - (path_str.len() + 5))
|
||||
// Foo { a: Foo } - indent is +3, width is -5.
|
||||
let budget = width - (path_str.len() + 5);
|
||||
(offset + path_str.len() + 3, budget, budget)
|
||||
}
|
||||
StructLitStyle::BlockIndent => {
|
||||
// If we are all on one line, then we'll ignore the indent, and we
|
||||
// have a smaller budget.
|
||||
let indent = context.block_indent + context.config.tab_spaces;
|
||||
(indent, width - indent)
|
||||
(indent, width - (path_str.len() + 5), width - indent)
|
||||
}
|
||||
};
|
||||
|
||||
@ -227,13 +230,13 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
|
||||
|item| {
|
||||
match *item {
|
||||
StructLitField::Regular(ref field) => {
|
||||
rewrite_field(context, &field, budget, indent)
|
||||
rewrite_field(context, &field, h_budget, indent)
|
||||
.unwrap_or(context.codemap.span_to_snippet(field.span)
|
||||
.unwrap())
|
||||
},
|
||||
StructLitField::Base(ref expr) => {
|
||||
// 2 = ..
|
||||
expr.rewrite(context, budget - 2, indent + 2)
|
||||
expr.rewrite(context, h_budget - 2, indent + 2)
|
||||
.map(|s| format!("..{}", s))
|
||||
.unwrap_or(context.codemap.span_to_snippet(expr.span)
|
||||
.unwrap())
|
||||
@ -252,8 +255,8 @@ fn rewrite_struct_lit<'a>(context: &RewriteContext,
|
||||
context.config.struct_lit_trailing_comma
|
||||
},
|
||||
indent: indent,
|
||||
h_width: budget,
|
||||
v_width: budget,
|
||||
h_width: h_budget,
|
||||
v_width: v_budget,
|
||||
ends_with_newline: true,
|
||||
};
|
||||
let fields_str = write_list(&items, &fmt);
|
||||
|
@ -8,7 +8,9 @@ fn main() {
|
||||
|
||||
Foo { a: foo() /* comment*/, /* comment*/ b: bar(), ..something };
|
||||
|
||||
Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: foo(), b: bar(), };
|
||||
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: foo(), b: bar(), };
|
||||
|
||||
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: foo(), b: bar(), };
|
||||
|
||||
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
|
||||
// Comment
|
||||
|
@ -13,33 +13,25 @@ fn main() {
|
||||
..something
|
||||
};
|
||||
|
||||
Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
|
||||
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: foo(), b: bar() };
|
||||
|
||||
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
|
||||
a: foo(),
|
||||
b: bar(),
|
||||
};
|
||||
|
||||
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { // Comment
|
||||
a: foo(), /* C
|
||||
* o
|
||||
* m
|
||||
* m
|
||||
* e
|
||||
* n
|
||||
* t */
|
||||
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
|
||||
// Comment
|
||||
b: bar(), /* C
|
||||
* o
|
||||
* m
|
||||
* m
|
||||
* e
|
||||
* n
|
||||
* t */
|
||||
a: foo(), // Comment
|
||||
// Comment
|
||||
b: bar(), /* Comment */
|
||||
};
|
||||
|
||||
Foo { a: Bar, b: foo() };
|
||||
|
||||
A { // Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit
|
||||
// amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante
|
||||
A {
|
||||
// Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed
|
||||
// sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante
|
||||
// hendrerit. Donec et mollis dolor.
|
||||
first: item(),
|
||||
// Praesent et diam eget libero egestas mattis sit amet vitae augue.
|
||||
@ -47,11 +39,12 @@ fn main() {
|
||||
second: Item,
|
||||
};
|
||||
|
||||
Diagram { // o This graph demonstrates how
|
||||
// / \ significant whitespace is
|
||||
// o o preserved.
|
||||
// /|\ \
|
||||
// o o o o
|
||||
Diagram {
|
||||
// o This graph demonstrates how
|
||||
// / \ significant whitespace is
|
||||
// o o preserved.
|
||||
// /|\ \
|
||||
// o o o o
|
||||
graph: G,
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user