mirror of
https://github.com/rust-lang/rust.git
synced 2024-12-04 12:44:40 +00:00
Reduce code duplication for block indentation helpers
This commit is contained in:
parent
c8fd23ca68
commit
e0ae162ae1
26
src/expr.rs
26
src/expr.rs
@ -762,22 +762,20 @@ fn rewrite_call(context: &RewriteContext,
|
||||
Some(format!("{}({})", callee_str, write_list(&items.collect::<Vec<_>>(), &fmt)))
|
||||
}
|
||||
|
||||
fn expr_block_indent(context: &RewriteContext, offset: usize) -> usize {
|
||||
match context.config.expr_indent_style {
|
||||
BlockIndentStyle::Inherit => context.block_indent,
|
||||
BlockIndentStyle::Tabbed => context.block_indent + context.config.tab_spaces,
|
||||
BlockIndentStyle::Visual => offset,
|
||||
}
|
||||
macro_rules! block_indent_helper {
|
||||
($name:ident, $option:ident) => (
|
||||
fn $name(context: &RewriteContext, offset: usize) -> usize {
|
||||
match context.config.$option {
|
||||
BlockIndentStyle::Inherit => context.block_indent,
|
||||
BlockIndentStyle::Tabbed => context.block_indent + context.config.tab_spaces,
|
||||
BlockIndentStyle::Visual => offset,
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// FIXME: Code duplication; is there a better solution?
|
||||
fn closure_block_indent(context: &RewriteContext, offset: usize) -> usize {
|
||||
match context.config.closure_indent_style {
|
||||
BlockIndentStyle::Inherit => context.block_indent,
|
||||
BlockIndentStyle::Tabbed => context.block_indent + context.config.tab_spaces,
|
||||
BlockIndentStyle::Visual => offset,
|
||||
}
|
||||
}
|
||||
block_indent_helper!(expr_block_indent, expr_indent_style);
|
||||
block_indent_helper!(closure_block_indent, closure_indent_style);
|
||||
|
||||
fn rewrite_paren(context: &RewriteContext,
|
||||
subexpr: &ast::Expr,
|
||||
|
Loading…
Reference in New Issue
Block a user