diff options
| author | Nick Cameron <ncameron@mozilla.com> | 2018-07-11 21:01:40 +1200 |
|---|---|---|
| committer | Nick Cameron <ncameron@mozilla.com> | 2018-07-24 15:43:29 +1200 |
| commit | f0fe9c3c4acb4eafba5a552a2823e6997e75a3f4 (patch) | |
| tree | f28efab727642d68955b9286b9fac80efd76f4fd /src/utils.rs | |
| parent | 5bc27593f44a7c2108ca1a69eba2d34b3db90935 (diff) | |
chains: prefer to use the next line for an expression, if using the same line would introduce an open block or similar
This problem came to light due to the chains changes, but effects other code too. It only happens rarely, e.g.,
before this fix:
```
match foo {
MacroArgKind::Delimited(ref delim_tok, ref args) => rewrite_delimited_inner(
delim_tok,
args,
).map(|(lhs, inner, rhs)| format!("{}{}{}", lhs, inner, rhs)),
};
```
after:
```
match foo {
MacroArgKind::Delimited(ref delim_tok, ref args) => {
rewrite_delimited_inner(delim_tok, args)
.map(|(lhs, inner, rhs)| format!("{}{}{}", lhs, inner, rhs))
}
}
```
Diffstat (limited to 'src/utils.rs')
| -rw-r--r-- | src/utils.rs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/utils.rs b/src/utils.rs index f1b0582b120..b8474792cd3 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -382,6 +382,7 @@ pub fn colon_spaces(before: bool, after: bool) -> &'static str { } } +#[inline] pub fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr { match e.node { ast::ExprKind::Call(ref e, _) @@ -398,6 +399,12 @@ pub fn left_most_sub_expr(e: &ast::Expr) -> &ast::Expr { } } +#[inline] pub fn starts_with_newline(s: &str) -> bool { s.starts_with('\n') || s.starts_with("\r\n") } + +#[inline] +pub fn first_line_ends_with(s: &str, c: char) -> bool { + s.lines().next().map_or(false, |l| l.ends_with(c)) +} |
