Skip to content

Commit a4da1e9

Browse files
authored
Merge pull request #3430 from rchaser53/no-arg-with-comment
fix not to remove comment in the case of no arg
2 parents 51af195 + 8e3ef3e commit a4da1e9

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/items.rs

+11-4
Original file line numberDiff line numberDiff line change
@@ -2285,6 +2285,17 @@ fn rewrite_args(
22852285
let separator = ",";
22862286
let next_span_start = span.hi();
22872287

2288+
if args.len() == 0 {
2289+
let comment = context
2290+
.snippet(mk_sp(
2291+
span.lo(),
2292+
// to remove ')'
2293+
span.hi() - BytePos(1),
2294+
))
2295+
.trim();
2296+
return Some(comment.to_owned());
2297+
}
2298+
22882299
let mut arg_item_strs = args
22892300
.iter()
22902301
.map(|arg| {
@@ -2318,10 +2329,6 @@ fn rewrite_args(
23182329
arg_items.push(ListItem::from_str(""));
23192330
}
23202331

2321-
// FIXME(#21): if there are no args, there might still be a comment, but
2322-
// without spans for the comment or parens, there is no chance of
2323-
// getting it right. You also don't get to put a comment on self, unless
2324-
// it is explicit.
23252332
if args.len() >= min_args || variadic {
23262333
let comment_span_start = if min_args == 2 {
23272334
let remove_comma_byte_pos = context

tests/source/no_arg_with_commnet.rs

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fn foo( /* cooment */
2+
) {}

tests/target/no_arg_with_commnet.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn foo(/* cooment */) {}

0 commit comments

Comments
 (0)