]> git.lizzy.rs Git - rust.git/commitdiff
Fix for #1255
authorDavid Wickes <dave.wickes@gmail.com>
Sun, 26 Feb 2017 21:43:49 +0000 (21:43 +0000)
committerDavid Wickes <dave.wickes@gmail.com>
Sun, 26 Feb 2017 22:28:21 +0000 (22:28 +0000)
Default annotation incorrectly removed on associated types

Fixed by adding a specific function to perform formatting on `ImplItems`.

src/items.rs
src/visitor.rs

index 4e5dc9d576504b4b81de9539ced28578c3b35964..047855571c579ca175f9b21b9cf0277f3a125de9 100644 (file)
@@ -1267,6 +1267,22 @@ pub fn rewrite_associated_type(ident: ast::Ident,
     }
 }
 
+pub fn rewrite_associated_impl_type(ident: ast::Ident,
+                                    defaultness: ast::Defaultness,
+                                    ty_opt: Option<&ptr::P<ast::Ty>>,
+                                    ty_param_bounds_opt: Option<&ast::TyParamBounds>,
+                                    context: &RewriteContext,
+                                    indent: Indent)
+                                    -> Option<String> {
+    let result =
+        try_opt!(rewrite_associated_type(ident, ty_opt, ty_param_bounds_opt, context, indent));
+
+    match defaultness {
+        ast::Defaultness::Default => Some(format!("default {}", result)),
+        _ => Some(result),
+    }
+}
+
 impl Rewrite for ast::FunctionRetTy {
     fn rewrite(&self, context: &RewriteContext, shape: Shape) -> Option<String> {
         match *self {
index 1344121b5a6982151032bde59753d73f5748966a..6cd00ffc1f49b25023c391b3ed1a1c840b1b173c 100644 (file)
@@ -21,7 +21,8 @@
 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 {
@@ -411,11 +412,12 @@ pub fn visit_impl_item(&mut self, ii: &ast::ImplItem) {
                 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) => {