impl<T> CharClasses<T> where T: Iterator, T::Item: RichChar {
fn new(base: T) -> CharClasses<T> {
- CharClasses { base: base.peekable(), status: CharClassesStatus::Normal }
+ CharClasses {
+ base: base.peekable(),
+ status: CharClassesStatus::Normal,
+ }
}
}
ideal_width: usize, "Ideal width of each line (only used for comments)",
leeway: usize, "Leeway of line width (deprecated)",
tab_spaces: usize, "Number of spaces per tab",
- list_width: usize, "Maximum width in a struct literal or function \
- call before faling back to vertical formatting",
+ fn_call_width: usize, "Maximum width of the args of a function call\
+ before faling back to vertical formatting",
+ struct_lit_width: usize, "Maximum width in the body of a struct lit\
+ before faling back to vertical formatting",
newline_style: NewlineStyle, "Unix or Windows line endings",
fn_brace_style: BraceStyle, "Brace style for functions",
fn_return_indent: ReturnIndent, "Location of return type in function declaration",
ideal_width: 80,
leeway: 5,
tab_spaces: 4,
- list_width: 50,
+ fn_call_width: 50,
+ struct_lit_width: 12,
newline_style: NewlineStyle::Unix,
fn_brace_style: BraceStyle::SameLineWhere,
fn_return_indent: ReturnIndent::WithArgs,
span_after(span, "{", context.codemap),
span.hi);
- let tactic = match (context.config.struct_lit_style, fields.len()) {
+ let mut tactic = match (context.config.struct_lit_style, fields.len()) {
(StructLitStyle::Visual, 1) => ListTactic::HorizontalVertical,
_ => context.config.struct_lit_multiline_style.to_list_tactic(),
};
+ if tactic == ListTactic::HorizontalVertical && fields.len() > 1 {
+ tactic = ListTactic::LimitedHorizontalVertical(context.config.struct_lit_width);
+ }
+
let fmt = ListFormatting {
tactic: tactic,
separator: ",",
impl BadIssueSeeker {
pub fn new(report_todo: ReportTactic, report_fixme: ReportTactic) -> BadIssueSeeker {
BadIssueSeeker {
- state: Seeking::Issue { todo_idx: 0, fixme_idx: 0 },
+ state: Seeking::Issue {
+ todo_idx: 0,
+ fixme_idx: 0,
+ },
report_todo: report_todo,
report_fixme: report_fixme,
}
return None;
}
- self.state = Seeking::Issue { todo_idx: 0, fixme_idx: 0 };
+ self.state = Seeking::Issue {
+ todo_idx: 0,
+ fixme_idx: 0,
+ };
if let IssueClassification::Bad(issue) = result {
return Some(issue);
fixme_idx = 0;
}
- Seeking::Issue { todo_idx: todo_idx, fixme_idx: fixme_idx }
+ Seeking::Issue {
+ todo_idx: todo_idx,
+ fixme_idx: fixme_idx,
+ }
}
fn inspect_number(&mut self,
NumberPart::CloseParen => {}
}
- self.state = Seeking::Number { part: part, issue: issue };
+ self.state = Seeking::Number {
+ part: part,
+ issue: issue,
+ };
IssueClassification::None
}
#[test]
fn issue_type() {
let mut seeker = BadIssueSeeker::new(ReportTactic::Always, ReportTactic::Never);
- let expected = Some(Issue { issue_type: IssueType::Todo, missing_number: false });
+ let expected = Some(Issue {
+ issue_type: IssueType::Todo,
+ missing_number: false,
+ });
assert_eq!(expected,
"TODO(#100): more awesomeness"
.unwrap());
let mut seeker = BadIssueSeeker::new(ReportTactic::Never, ReportTactic::Unnumbered);
- let expected = Some(Issue { issue_type: IssueType::Fixme, missing_number: true });
+ let expected = Some(Issue {
+ issue_type: IssueType::Fixme,
+ missing_number: true,
+ });
assert_eq!(expected,
"Test. FIXME: bad, bad, not good"
impl Indent {
pub fn new(block_indent: usize, alignment: usize) -> Indent {
- Indent { block_indent: block_indent, alignment: alignment }
+ Indent {
+ block_indent: block_indent,
+ alignment: alignment,
+ }
}
pub fn empty() -> Indent {
// Add warnings for bad todos/ fixmes
if let Some(issue) = issue_seeker.inspect(c) {
- errors.push(FormattingError { line: cur_line, kind: ErrorKind::BadIssue(issue) });
+ errors.push(FormattingError {
+ line: cur_line,
+ kind: ErrorKind::BadIssue(issue),
+ });
}
if c == '\n' {
}
// Check for any line width errors we couldn't correct.
if line_len > config.max_width {
- errors.push(FormattingError { line: cur_line, kind: ErrorKind::LineOverflow });
+ errors.push(FormattingError {
+ line: cur_line,
+ kind: ErrorKind::LineOverflow,
+ });
}
line_len = 0;
cur_line += 1;
}
for &(l, _, _) in &trims {
- errors.push(FormattingError { line: l, kind: ErrorKind::TrailingWhitespace });
+ errors.push(FormattingError {
+ line: l,
+ kind: ErrorKind::TrailingWhitespace,
+ });
}
report.file_error_map.insert(f.to_owned(), errors);
{
let config = Rc::new(config.clone());
- let mut call_ctxt = RustFmtCalls { config: config, result: result.clone() };
+ let mut call_ctxt = RustFmtCalls {
+ config: config,
+ result: result.clone(),
+ };
rustc_driver::run_compiler(&args, &mut call_ctxt);
}
impl<'a> ListFormatting<'a> {
pub fn for_fn(width: usize, offset: Indent, config: &'a Config) -> ListFormatting<'a> {
ListFormatting {
- tactic: ListTactic::LimitedHorizontalVertical(config.list_width),
+ tactic: ListTactic::LimitedHorizontalVertical(config.fn_call_width),
separator: ",",
trailing_separator: SeparatorTactic::Never,
indent: offset,
}
pub fn from_str<S: Into<String>>(s: S) -> ListItem {
- ListItem { pre_comment: None, item: s.into(), post_comment: None, new_lines: false }
+ ListItem {
+ pre_comment: None,
+ item: s.into(),
+ post_comment: None,
+ new_lines: false,
+ }
}
}
impl Mismatch {
fn new(line_number: u32) -> Mismatch {
- Mismatch { line_number: line_number, lines: Vec::new() }
+ Mismatch {
+ line_number: line_number,
+ lines: Vec::new(),
+ }
}
}
codemap: codemap,
buffer: StringBuffer::new(),
last_pos: BytePos(0),
- block_indent: Indent { block_indent: 0, alignment: 0 },
+ block_indent: Indent {
+ block_indent: 0,
+ alignment: 0,
+ },
config: config,
}
}
Foo { a: foo() /* comment*/, /* comment*/ b: bar(), ..something };
- Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: foo(), b: bar(), };
+ Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: f(), b: b(), };
- Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: foo(), b: bar(), };
+ Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: f(), b: b(), };
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
// Comment
};
Foo { a:Bar,
- b:foo() };
+ b:f() };
Quux { x: if cond { bar(); }, y: baz() };
LoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongStruct { ..base };
IntrinsicISizesContribution { content_intrinsic_sizes: IntrinsicISizes { minimum_inline_size: 0, }, };
}
+
+fn issue123() {
+ Foo { a: b, c: d, e: f };
+
+ Foo { a: bb, c: dd, e: ff };
+
+ Foo { a: ddddddddddddddddddddd, b: cccccccccccccccccccccccccccccccccccccc };
+}
Foo { a: foo() /* comment*/, /* comment*/ b: bar(), ..something };
- Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: foo(), b: bar(), };
+ Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: f(), b: b(), };
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
// Comment
};
Foo { a:Bar,
- b:foo() };
+ b:f() };
Quux { x: if cond { bar(); }, y: baz() };
..something
};
- Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: foo(), b: bar() };
+ Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: f(), b: b() };
- Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
- a: foo(),
- b: bar(),
+ Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
+ a: f(),
+ b: b(),
};
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo {
b: bar(), /* Comment */
};
- Foo { a: Bar, b: foo() };
+ Foo { a: Bar, b: f() };
Quux {
x: if cond {
fn matcher() {
TagTerminatedByteMatcher {
- matcher: ByteMatcher { pattern: b"<HTML", mask: b"\xFF\xDF\xDF\xDF\xDF\xFF" },
+ matcher: ByteMatcher {
+ pattern: b"<HTML",
+ mask: b"\xFF\xDF\xDF\xDF\xDF\xFF",
+ },
};
}
fn struct_exprs() {
Foo { a: 1, b: f(2) };
- Foo { a: 1, b: f(2), ..g(3) };
+ Foo {
+ a: 1,
+ b: f(2),
+ ..g(3)
+ };
LoooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooongStruct {
..base
};
content_intrinsic_sizes: IntrinsicISizes { minimum_inline_size: 0 },
};
}
+
+fn issue123() {
+ Foo { a: b, c: d, e: f };
+
+ Foo {
+ a: bb,
+ c: dd,
+ e: ff,
+ };
+
+ Foo {
+ a: ddddddddddddddddddddd,
+ b: cccccccccccccccccccccccccccccccccccccc,
+ };
+}
b: bar(),
..something };
- Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: foo(), b: bar() };
+ Fooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { a: f(), b: b() };
Foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo { // Commen
// t
* n
* t */ };
- Foo { a: Bar, b: foo() };
+ Foo { a: Bar, b: f() };
Quux { x: if cond {
bar();