]> git.lizzy.rs Git - rust.git/blobdiff - src/visitor.rs
Remove BlockIndentStyle::Inherit
[rust.git] / src / visitor.rs
index 95ec54e89eed108c8261c0418efa0e56627f5948..2700287608de6f1944a3648c4f0fcdd5367fb476 100644 (file)
 
 use strings::string_buffer::StringBuffer;
 
-use Indent;
+use {Indent, Shape};
 use utils;
 use codemap::{LineRangeUtils, SpanUtils};
 use config::Config;
 use rewrite::{Rewrite, RewriteContext};
 use comment::rewrite_comment;
 use macros::{rewrite_macro, MacroPosition};
-use items::{rewrite_static, rewrite_associated_type, rewrite_type_alias, format_impl, format_trait};
+use items::{rewrite_static, rewrite_associated_type, rewrite_associated_impl_type,
+            rewrite_type_alias, format_impl, format_trait};
 
 fn is_use_item(item: &ast::Item) -> bool {
     match item.node {
@@ -59,8 +60,9 @@ fn visit_stmt(&mut self, stmt: &ast::Stmt) {
             ast::StmtKind::Expr(..) |
             ast::StmtKind::Semi(..) => {
                 let rewrite = stmt.rewrite(&self.get_context(),
-                                           self.config.max_width - self.block_indent.width(),
-                                           self.block_indent);
+                                           Shape::legacy(self.config.max_width -
+                                                         self.block_indent.width(),
+                                                         self.block_indent));
                 self.push_rewrite(stmt.span, rewrite);
             }
             ast::StmtKind::Mac(ref mac) => {
@@ -263,10 +265,10 @@ pub fn visit_item(&mut self, item: &ast::Item) {
                                            item.span,
                                            indent,
                                            None)
-                        .map(|s| match *def {
-                            ast::VariantData::Tuple(..) => s + ";",
-                            _ => s,
-                        })
+                            .map(|s| match *def {
+                                     ast::VariantData::Tuple(..) => s + ";",
+                                     _ => s,
+                                 })
                 };
                 self.push_rewrite(item.span, rewrite);
             }
@@ -293,6 +295,7 @@ pub fn visit_item(&mut self, item: &ast::Item) {
                                              ty,
                                              mutability,
                                              Some(expr),
+                                             self.block_indent,
                                              &self.get_context());
                 self.push_rewrite(item.span, rewrite);
             }
@@ -303,6 +306,7 @@ pub fn visit_item(&mut self, item: &ast::Item) {
                                              ty,
                                              ast::Mutability::Immutable,
                                              Some(expr),
+                                             self.block_indent,
                                              &self.get_context());
                 self.push_rewrite(item.span, rewrite);
             }
@@ -352,6 +356,7 @@ pub fn visit_trait_item(&mut self, ti: &ast::TraitItem) {
                                              ty,
                                              ast::Mutability::Immutable,
                                              expr_opt.as_ref(),
+                                             self.block_indent,
                                              &self.get_context());
                 self.push_rewrite(ti.span, rewrite);
             }
@@ -402,15 +407,17 @@ pub fn visit_impl_item(&mut self, ii: &ast::ImplItem) {
                                              ty,
                                              ast::Mutability::Immutable,
                                              Some(expr),
+                                             self.block_indent,
                                              &self.get_context());
                 self.push_rewrite(ii.span, rewrite);
             }
             ast::ImplItemKind::Type(ref ty) => {
-                let rewrite = rewrite_associated_type(ii.ident,
-                                                      Some(ty),
-                                                      None,
-                                                      &self.get_context(),
-                                                      self.block_indent);
+                let rewrite = rewrite_associated_impl_type(ii.ident,
+                                                           ii.defaultness,
+                                                           Some(ty),
+                                                           None,
+                                                           &self.get_context(),
+                                                           self.block_indent);
                 self.push_rewrite(ii.span, rewrite);
             }
             ast::ImplItemKind::Macro(ref mac) => {
@@ -425,8 +432,7 @@ fn visit_mac(&mut self, mac: &ast::Mac, ident: Option<ast::Ident>, pos: MacroPos
         let rewrite = rewrite_macro(mac,
                                     ident,
                                     &self.get_context(),
-                                    width,
-                                    self.block_indent,
+                                    Shape::legacy(width, self.block_indent),
                                     pos);
         self.push_rewrite(mac.span, rewrite);
     }
@@ -482,8 +488,9 @@ pub fn visit_attrs(&mut self, attrs: &[ast::Attribute]) -> bool {
         self.format_missing_with_indent(source!(self, first.span).lo);
 
         let rewrite = outers.rewrite(&self.get_context(),
-                     self.config.max_width - self.block_indent.width(),
-                     self.block_indent)
+                                     Shape::legacy(self.config.max_width -
+                                                   self.block_indent.width(),
+                                                   self.block_indent))
             .unwrap();
         self.buffer.push_str(&rewrite);
         let last = outers.last().unwrap();
@@ -560,18 +567,17 @@ pub fn get_context(&self) -> RewriteContext {
             parse_session: self.parse_session,
             codemap: self.codemap,
             config: self.config,
-            block_indent: self.block_indent,
         }
     }
 }
 
 impl<'a> Rewrite for [ast::Attribute] {
-    fn rewrite(&self, context: &RewriteContext, _: usize, offset: Indent) -> Option<String> {
+    fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
         let mut result = String::new();
         if self.is_empty() {
             return Some(result);
         }
-        let indent = offset.to_string(context.config);
+        let indent = shape.indent.to_string(context.config);
 
         for (i, a) in self.iter().enumerate() {
             let mut a_str = context.snippet(a.span);
@@ -587,9 +593,10 @@ fn rewrite(&self, context: &RewriteContext, _: usize, offset: Indent) -> Option<
                 if !comment.is_empty() {
                     let comment = try_opt!(rewrite_comment(comment,
                                                            false,
-                                                           context.config.ideal_width -
-                                                           offset.width(),
-                                                           offset,
+                                                           Shape::legacy(context.config
+                                                                             .comment_width -
+                                                                         shape.indent.width(),
+                                                                         shape.indent),
                                                            context.config));
                     result.push_str(&indent);
                     result.push_str(&comment);
@@ -603,8 +610,9 @@ fn rewrite(&self, context: &RewriteContext, _: usize, offset: Indent) -> Option<
             if a_str.starts_with("//") {
                 a_str = try_opt!(rewrite_comment(&a_str,
                                                  false,
-                                                 context.config.ideal_width - offset.width(),
-                                                 offset,
+                                                 Shape::legacy(context.config.comment_width -
+                                                               shape.indent.width(),
+                                                               shape.indent),
                                                  context.config));
             }