3 ms·
> the default automated Rust formating tool is very eager to adds lot of lines by basically keeping only one word per line. This is not my experience. Lifetim
by strager 4y ago
> the default automated Rust formating tool is very eager to adds lot of lines by basically keeping only one word per line.
This is not my experience.
Lifetime and '&mut self' noise (and four-space indentation) did cause rustfmt to sometimes split function signatures across multiple lines, but overall, I think rustfmt did a good job.
C++: https://github.com/quick-lint/cpp-vs-rust/blob/f8d31341f5cac5d0e676ead553a3610284d47a3e/cpp/src/quick-lint-js/fe/lex.cpp#L1592-L1607 https://github.com/quick-lint/cpp-vs-rust/blob/f8d31341f5cac...
lexer::parsed_identifier lexer::parse_identifier(const char8* input,
identifier_kind kind) {
const char8* begin = input;
const char8* end = this->parse_identifier_fast_only(input);
if (*end == u8'\\' || (kind == identifier_kind::jsx && *end == u8'-') ||
!this->is_ascii_character(*end)) {
return this->parse_identifier_slow(end,
/*identifier_begin=*/begin, kind);
} else {
return parsed_identifier{
.after = end,
.normalized = make_string_view(begin, end),
.escape_sequences = {},
};
}
}
Rust: https://github.com/quick-lint/cpp-vs-rust/blob/f8d31341f5cac5d0e676ead553a3610284d47a3e/rust/libs/fe/src/lex.rs#L1996-L2016 https://github.com/quick-lint/cpp-vs-rust/blob/f8d31341f5cac...
fn parse_identifier(
&mut self,
input: *const u8,
kind: IdentifierKind,
) -> ParsedIdentifier<'alloc, 'code> {
let begin: *const u8 = input;
let end: *const u8 = self.parse_identifier_fast_only(input);
let end_c: u8 = unsafe { *end };
if end_c == b'\\'
|| (kind == IdentifierKind::JSX && end_c == b'-')
|| !is_ascii_code_unit(end_c)
{
self.parse_identifier_slow(end, /*identifier_begin=*/ begin, kind)
} else {
ParsedIdentifier {
after: end,
normalized: unsafe { slice_from_begin_end(begin, end) },
escape_sequences: None,
}
}
}