Merge pull request #3430 from rchaser53/no-arg-with-comment

fix not to remove comment in the case of no arg
This commit is contained in:
Seiichi Uchida 2019-03-05 20:43:11 +09:00 committed by GitHub
commit a4da1e9466
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 4 deletions

View File

@ -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

View File

@ -0,0 +1,2 @@
fn foo( /* cooment */
) {}

View File

@ -0,0 +1 @@
fn foo(/* cooment */) {}