Skip to content

Commit 287cd59

Browse files
committed
Avoid trailing commas
1 parent fb61f5d commit 287cd59

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -932,17 +932,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
932932
labels
933933
.push((provided_span, format!("argument{} unexpected", provided_ty_name)));
934934
let mut span = provided_span;
935-
if let Some((_, next)) = provided_arg_tys.get(
936-
ProvidedIdx::from_usize(arg_idx.index() + 1),
937-
) {
938-
// Include next comma
939-
span = span.until(*next);
940-
} else if arg_idx.index() > 0
935+
if arg_idx.index() > 0
941936
&& let Some((_, prev)) = provided_arg_tys
942937
.get(ProvidedIdx::from_usize(arg_idx.index() - 1)
943938
) {
944-
// Last argument, include previous comma
939+
// Include previous comma
945940
span = span.with_lo(prev.hi());
941+
} else if let Some((_, next)) = provided_arg_tys.get(
942+
ProvidedIdx::from_usize(arg_idx.index() + 1),
943+
) {
944+
// Include next comma
945+
span = span.until(*next);
946946
}
947947
suggestions.push((span, String::new()));
948948

tests/ui/argument-suggestions/extra_arguments.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ LL | fn one_arg(_a: i32) {}
6565
help: remove the extra arguments
6666
|
6767
LL - one_arg(1, "", 1.0);
68-
LL + one_arg(1, );
68+
LL + one_arg(1);
6969
|
7070

7171
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
@@ -171,7 +171,7 @@ LL | fn two_arg_diff(_a: i32, _b: &str) {}
171171
help: remove the extra arguments
172172
|
173173
LL - two_arg_diff(1, "", 1, "");
174-
LL + two_arg_diff(1, "", );
174+
LL + two_arg_diff(1, "");
175175
|
176176

177177
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
@@ -205,7 +205,7 @@ LL | fn two_arg_diff(_a: i32, _b: &str) {}
205205
help: remove the extra argument
206206
|
207207
LL - two_arg_diff(1, 1, "");
208-
LL + two_arg_diff(1, "");
208+
LL + two_arg_diff(1, "");
209209
|
210210

211211
error[E0061]: this function takes 2 arguments but 3 arguments were supplied
@@ -245,7 +245,7 @@ LL | fn two_arg_diff(_a: i32, _b: &str) {}
245245
help: remove the extra argument
246246
|
247247
LL - 1,
248-
LL + ""
248+
LL + 1,
249249
|
250250

251251
error: aborting due to 14 previous errors

tests/ui/typeck/struct-enum-wrong-args.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ note: tuple variant defined here
2525
help: remove the extra arguments
2626
|
2727
LL - let _ = Ok(3, 6, 2);
28-
LL + let _ = Ok(3, );
28+
LL + let _ = Ok(3);
2929
|
3030

3131
error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied

0 commit comments

Comments
 (0)