mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-05 05:04:24 +00:00
Fix indentation in multi lined pattern
This commit is contained in:
parent
a7060f9fdf
commit
b29a3afb96
37
src/expr.rs
37
src/expr.rs
@ -937,21 +937,16 @@ impl<'a> ControlFlow<'a> {
|
||||
let offset = self.keyword.len() + label_string.len() + 1;
|
||||
|
||||
let pat_expr_string = match self.cond {
|
||||
Some(cond) => {
|
||||
let cond_shape = match context.config.indent_style() {
|
||||
IndentStyle::Visual => constr_shape.shrink_left(offset)?,
|
||||
IndentStyle::Block => constr_shape.offset_left(offset)?,
|
||||
};
|
||||
rewrite_pat_expr(
|
||||
context,
|
||||
self.pat,
|
||||
cond,
|
||||
self.matcher,
|
||||
self.connector,
|
||||
self.keyword,
|
||||
cond_shape,
|
||||
)?
|
||||
}
|
||||
Some(cond) => rewrite_pat_expr(
|
||||
context,
|
||||
self.pat,
|
||||
cond,
|
||||
self.matcher,
|
||||
self.connector,
|
||||
self.keyword,
|
||||
constr_shape,
|
||||
offset,
|
||||
)?,
|
||||
None => String::new(),
|
||||
};
|
||||
|
||||
@ -967,8 +962,8 @@ impl<'a> ControlFlow<'a> {
|
||||
.max_width()
|
||||
.checked_sub(constr_shape.used_width() + offset + brace_overhead)
|
||||
.unwrap_or(0);
|
||||
let force_newline_brace = context.config.indent_style() == IndentStyle::Block
|
||||
&& (pat_expr_string.contains('\n') || pat_expr_string.len() > one_line_budget)
|
||||
let force_newline_brace = (pat_expr_string.contains('\n')
|
||||
|| pat_expr_string.len() > one_line_budget)
|
||||
&& !last_line_extendable(&pat_expr_string);
|
||||
|
||||
// Try to format if-else on single line.
|
||||
@ -1704,23 +1699,25 @@ fn rewrite_pat_expr(
|
||||
connector: &str,
|
||||
keyword: &str,
|
||||
shape: Shape,
|
||||
offset: usize,
|
||||
) -> Option<String> {
|
||||
debug!("rewrite_pat_expr {:?} {:?} {:?}", shape, pat, expr);
|
||||
let cond_shape = shape.offset_left(offset)?;
|
||||
if let Some(pat) = pat {
|
||||
let matcher = if matcher.is_empty() {
|
||||
matcher.to_owned()
|
||||
} else {
|
||||
format!("{} ", matcher)
|
||||
};
|
||||
let pat_shape = shape
|
||||
let pat_shape = cond_shape
|
||||
.offset_left(matcher.len())?
|
||||
.sub_width(connector.len())?;
|
||||
let pat_string = pat.rewrite(context, pat_shape)?;
|
||||
let result = format!("{}{}{}", matcher, pat_string, connector);
|
||||
return rewrite_assign_rhs(context, result, expr, shape);
|
||||
return rewrite_assign_rhs(context, result, expr, cond_shape);
|
||||
}
|
||||
|
||||
let expr_rw = expr.rewrite(context, shape);
|
||||
let expr_rw = expr.rewrite(context, cond_shape);
|
||||
// The expression may (partially) fit on the current line.
|
||||
// We do not allow splitting between `if` and condition.
|
||||
if keyword == "if" || expr_rw.is_some() {
|
||||
|
Loading…
Reference in New Issue
Block a user