From f0fe9c3c4acb4eafba5a552a2823e6997e75a3f4 Mon Sep 17 00:00:00 2001 From: Nick Cameron Date: Wed, 11 Jul 2018 21:01:40 +1200 Subject: 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)) } } ``` --- src/utils.rs | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src/utils.rs') 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)) +} -- cgit 1.4.1-3-g733a5