From 03bf1ceeb9e015fb8a3aca88e49b33b73158f0d4 Mon Sep 17 00:00:00 2001 From: Marcus Klaas Date: Sun, 27 Mar 2016 13:07:28 +0200 Subject: [PATCH] Fix tuple destructuring in impl fns --- Cargo.lock | 12 ++++++------ src/items.rs | 24 +++++++++++++++++++++--- tests/source/impls.rs | 6 ++++++ tests/target/impls.rs | 4 ++++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 689ed8db10b..ce3e5701ad2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6,7 +6,7 @@ dependencies = [ "env_logger 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "getopts 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.1.58 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)", "strings 0.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "syntex_syntax 0.29.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -39,7 +39,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.1.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -52,7 +52,7 @@ name = "kernel32-sys" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -79,7 +79,7 @@ dependencies = [ [[package]] name = "regex" -version = "0.1.56" +version = "0.1.58" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -125,7 +125,7 @@ version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -153,7 +153,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.2.5" +version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] diff --git a/src/items.rs b/src/items.rs index 688e4759832..97f12df8187 100644 --- a/src/items.rs +++ b/src/items.rs @@ -20,9 +20,8 @@ use comment::{FindUncommented, contains_comment}; use visitor::FmtVisitor; use rewrite::{Rewrite, RewriteContext}; use config::{Config, BlockIndentStyle, Density, ReturnIndent, BraceStyle, StructLitStyle}; -use syntax::codemap; -use syntax::{ast, abi, ptr}; +use syntax::{ast, abi, ptr, codemap}; use syntax::codemap::{Span, BytePos, mk_sp}; use syntax::parse::token; use syntax::ast::ImplItem; @@ -1477,7 +1476,13 @@ fn rewrite_args(context: &RewriteContext, // it is explicit. if args.len() >= min_args || variadic { let comment_span_start = if min_args == 2 { - let reduced_span = mk_sp(span.lo, args[1].ty.span.lo); + let second_arg_start = if arg_has_pattern(&args[1]) { + args[1].pat.span.lo + } else { + args[1].ty.span.lo + }; + let reduced_span = mk_sp(span.lo, second_arg_start); + context.codemap.span_after_last(reduced_span, ",") } else { span.lo @@ -1562,6 +1567,19 @@ fn rewrite_args(context: &RewriteContext, write_list(&arg_items, &fmt) } +fn arg_has_pattern(arg: &ast::Arg) -> bool { + if let ast::PatKind::Ident(_, + codemap::Spanned { + node: ast::Ident { name: ast::Name(0u32), .. }, + .. + }, + _) = arg.pat.node { + false + } else { + true + } +} + fn compute_budgets_for_args(context: &RewriteContext, result: &str, indent: Indent, diff --git a/tests/source/impls.rs b/tests/source/impls.rs index a3a8033b07f..e96baa91473 100644 --- a/tests/source/impls.rs +++ b/tests/source/impls.rs @@ -73,6 +73,12 @@ impl X { fn do_parse( mut self : X ) {} } impl Y5000 { fn bar(self: X< 'a , 'b >, y: Y) {} + + fn bad(&self, ( x, y): CoorT) {} + + fn turbo_bad(self: X< 'a , 'b > , ( x, y): CoorT) { + + } } pub impl Foo for Bar where T: Foo diff --git a/tests/target/impls.rs b/tests/target/impls.rs index c81de4d40fe..c592ab6f9f9 100644 --- a/tests/target/impls.rs +++ b/tests/target/impls.rs @@ -93,6 +93,10 @@ impl X { impl Y5000 { fn bar(self: X<'a, 'b>, y: Y) {} + + fn bad(&self, (x, y): CoorT) {} + + fn turbo_bad(self: X<'a, 'b>, (x, y): CoorT) {} } pub impl Foo for Bar