]> git.lizzy.rs Git - rust.git/commitdiff
Resolved #56 -- `mut` was eaten out of `mut self` in fn args.
authordefyrlt <defyrlt@gmail.com>
Fri, 1 May 2015 11:08:22 +0000 (14:08 +0300)
committerMatthew Hall <matthew@quickbeam.me.uk>
Sat, 2 May 2015 19:27:08 +0000 (20:27 +0100)
src/functions.rs
tests/idem/fn.rs

index 3d6fcb88c25462ae52017e45fc5390b61ba6ed50..d4f06c1c7ac0114f679258870c904df23a01d3cb 100644 (file)
@@ -164,7 +164,22 @@ fn rewrite_args(&self,
                     arg_item_strs[0] = format!("self: {}", pprust::ty_to_string(ty));
                 }
                 ast::ExplicitSelf_::SelfValue(_) => {
-                    arg_item_strs[0] = "self".to_owned();
+                    assert!(args.len() >= 1, "&[ast::Arg] shouldn't be empty.");
+
+                    // this hacky solution caused by absence of `Mutability` in `SelfValue`.
+                    let mut_str = {
+                        if let ast::Pat_::PatIdent(ast::BindingMode::BindByValue(mutability), _, _)
+                                = args[0].pat.node {
+                            match mutability {
+                                ast::Mutability::MutMutable => "mut ",
+                                ast::Mutability::MutImmutable => "",
+                            }
+                        } else {
+                            panic!("there is a bug or change in structure of AST, aborting.");
+                        }
+                    };
+
+                    arg_item_strs[0] = format!("{}self", mut_str);
                     min_args = 2;
                 }
                 _ => {}
index aec27597b7a15e5ca42a4850fff3e3387be686b4..62a059dc4644e044f5cb0f4375e2c53de66ff3b3 100644 (file)
@@ -39,6 +39,12 @@ fn with_no_errors<T, F>(&mut self, f: F) -> T
         where F: FnOnce(&mut Resolver) -> T
     {
     }
+
+    fn foo(mut self, mut bar: u32) {
+    }
+
+    fn bar(self, mut bazz: u32) {
+    }
 }
 
 pub fn render<'a,