diff --git a/src/chains.rs b/src/chains.rs index 87100c7be419..f65a6916af5b 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -251,7 +251,7 @@ pub fn rewrite_chain(expr: &ast::Expr, context: &RewriteContext, shape: Shape) - Cow::from("") } else { // Use new lines. - if context.force_one_line_chain { + if *context.force_one_line_chain.borrow() { return None; } nested_shape.indent.to_string_with_newline(context.config) diff --git a/src/rewrite.rs b/src/rewrite.rs index 708e31d86dd9..01671227e39b 100644 --- a/src/rewrite.rs +++ b/src/rewrite.rs @@ -17,6 +17,8 @@ use config::{Config, IndentStyle}; use shape::Shape; use visitor::SnippetProvider; +use std::cell::RefCell; + pub trait Rewrite { /// Rewrite self into shape. fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option; @@ -29,12 +31,12 @@ pub struct RewriteContext<'a> { pub config: &'a Config, pub inside_macro: bool, // Force block indent style even if we are using visual indent style. - pub use_block: bool, + pub use_block: RefCell, // When `format_if_else_cond_comment` is true, unindent the comment on top // of the `else` or `else if`. pub is_if_else_block: bool, // When rewriting chain, veto going multi line except the last element - pub force_one_line_chain: bool, + pub force_one_line_chain: RefCell, pub snippet_provider: &'a SnippetProvider<'a>, } @@ -45,7 +47,7 @@ impl<'a> RewriteContext<'a> { /// Return true if we should use block indent style for rewriting function call. pub fn use_block_indent(&self) -> bool { - self.config.indent_style() == IndentStyle::Block || self.use_block + self.config.indent_style() == IndentStyle::Block || *self.use_block.borrow() } pub fn budget(&self, used_width: usize) -> usize { diff --git a/src/visitor.rs b/src/visitor.rs index 35102f586090..f1b50e19b610 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -26,6 +26,8 @@ use shape::{Indent, Shape}; use spanned::Spanned; use utils::{self, contains_skip, count_newlines, inner_attributes, mk_sp, ptr_vec_to_ref_vec}; +use std::cell::RefCell; + /// Creates a string slice corresponding to the specified span. pub struct SnippetProvider<'a> { /// A pointer to the content of the file we are formatting. @@ -691,9 +693,9 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { codemap: self.codemap, config: self.config, inside_macro: false, - use_block: false, + use_block: RefCell::new(false), is_if_else_block: false, - force_one_line_chain: false, + force_one_line_chain: RefCell::new(false), snippet_provider: self.snippet_provider, } }