From 8e3ef3e3a9f400699e2c801275a34c948226281e Mon Sep 17 00:00:00 2001 From: rchaser53 Date: Tue, 5 Mar 2019 00:18:33 +0900 Subject: [PATCH] fix not to remove comment in the case of no arg --- src/items.rs | 15 +++++++++++---- tests/source/no_arg_with_commnet.rs | 2 ++ tests/target/no_arg_with_commnet.rs | 1 + 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 tests/source/no_arg_with_commnet.rs create mode 100644 tests/target/no_arg_with_commnet.rs diff --git a/src/items.rs b/src/items.rs index 5f751035f3e9d..51b7239927aee 100644 --- a/src/items.rs +++ b/src/items.rs @@ -2285,6 +2285,17 @@ fn rewrite_args( let separator = ","; let next_span_start = span.hi(); + if args.len() == 0 { + let comment = context + .snippet(mk_sp( + span.lo(), + // to remove ')' + span.hi() - BytePos(1), + )) + .trim(); + return Some(comment.to_owned()); + } + let mut arg_item_strs = args .iter() .map(|arg| { @@ -2318,10 +2329,6 @@ fn rewrite_args( arg_items.push(ListItem::from_str("")); } - // FIXME(#21): if there are no args, there might still be a comment, but - // without spans for the comment or parens, there is no chance of - // getting it right. You also don't get to put a comment on self, unless - // it is explicit. if args.len() >= min_args || variadic { let comment_span_start = if min_args == 2 { let remove_comma_byte_pos = context diff --git a/tests/source/no_arg_with_commnet.rs b/tests/source/no_arg_with_commnet.rs new file mode 100644 index 0000000000000..ea4ee0f1eee0a --- /dev/null +++ b/tests/source/no_arg_with_commnet.rs @@ -0,0 +1,2 @@ +fn foo( /* cooment */ +) {} diff --git a/tests/target/no_arg_with_commnet.rs b/tests/target/no_arg_with_commnet.rs new file mode 100644 index 0000000000000..69f61b60f29fc --- /dev/null +++ b/tests/target/no_arg_with_commnet.rs @@ -0,0 +1 @@ +fn foo(/* cooment */) {}