Skip to content

Commit

Permalink
fix not to remove comment in the case of no arg
Browse files Browse the repository at this point in the history
  • Loading branch information
rchaser53 committed Mar 4, 2019
1 parent 51af195 commit 8e3ef3e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions tests/source/no_arg_with_commnet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
fn foo( /* cooment */
) {}
1 change: 1 addition & 0 deletions tests/target/no_arg_with_commnet.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fn foo(/* cooment */) {}

0 comments on commit 8e3ef3e

Please sign in to comment.