From 59554dd5e1121d39cc9c1d716277de03c153a46b Mon Sep 17 00:00:00 2001 From: defyrlt Date: Fri, 1 May 2015 14:08:22 +0300 Subject: [PATCH] Resolved #56 -- `mut` was eaten out of `mut self` in fn args. --- src/functions.rs | 17 ++++++++++++++++- tests/idem/fn.rs | 6 ++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/functions.rs b/src/functions.rs index 3d6fcb88c25..d4f06c1c7ac 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -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; } _ => {} diff --git a/tests/idem/fn.rs b/tests/idem/fn.rs index aec27597b7a..62a059dc464 100644 --- a/tests/idem/fn.rs +++ b/tests/idem/fn.rs @@ -39,6 +39,12 @@ fn with_no_errors(&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, -- 2.44.0