about summary refs log tree commit diff
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2023-01-01 00:37:24 -0800
committerEsteban Küber <esteban@kuber.com.ar>2023-02-14 20:22:10 +0000
commit287cd5974c3fc7c885500036ffc8305ac978bede (patch)
tree485df082cde607c4b1430043474221850b411832
parentfb61f5d781334280ecb1d54aaad04584afac21ec (diff)
downloadrust-287cd5974c3fc7c885500036ffc8305ac978bede.tar.gz
rust-287cd5974c3fc7c885500036ffc8305ac978bede.zip
Avoid trailing commas
-rw-r--r--compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs14
-rw-r--r--tests/ui/argument-suggestions/extra_arguments.stderr8
-rw-r--r--tests/ui/typeck/struct-enum-wrong-args.stderr2
3 files changed, 12 insertions, 12 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
index 67927f1f9a9..af57d1e5120 100644
--- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
+++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs
@@ -932,17 +932,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
                     labels
                         .push((provided_span, format!("argument{} unexpected", provided_ty_name)));
                     let mut span = provided_span;
-                    if let Some((_, next)) = provided_arg_tys.get(
-                        ProvidedIdx::from_usize(arg_idx.index() + 1),
-                    ) {
-                        // Include next comma
-                        span = span.until(*next);
-                    } else if arg_idx.index() > 0
+                    if arg_idx.index() > 0
                         && let Some((_, prev)) = provided_arg_tys
                             .get(ProvidedIdx::from_usize(arg_idx.index() - 1)
                     ) {
-                        // Last argument, include previous comma
+                        // Include previous comma
                         span = span.with_lo(prev.hi());
+                    } else if let Some((_, next)) = provided_arg_tys.get(
+                        ProvidedIdx::from_usize(arg_idx.index() + 1),
+                    ) {
+                        // Include next comma
+                        span = span.until(*next);
                     }
                     suggestions.push((span, String::new()));
 
diff --git a/tests/ui/argument-suggestions/extra_arguments.stderr b/tests/ui/argument-suggestions/extra_arguments.stderr
index 0d4f2239917..2818dbe9341 100644
--- a/tests/ui/argument-suggestions/extra_arguments.stderr
+++ b/tests/ui/argument-suggestions/extra_arguments.stderr
@@ -65,7 +65,7 @@ LL | fn one_arg(_a: i32) {}
 help: remove the extra arguments
    |
 LL -   one_arg(1, "", 1.0);
-LL +   one_arg(1, );
+LL +   one_arg(1);
    |
 
 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) {}
 help: remove the extra arguments
    |
 LL -   two_arg_diff(1, "", 1, "");
-LL +   two_arg_diff(1, "", );
+LL +   two_arg_diff(1, "");
    |
 
 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) {}
 help: remove the extra argument
    |
 LL -   two_arg_diff(1, 1,     "");
-LL +   two_arg_diff(1, "");
+LL +   two_arg_diff(1,     "");
    |
 
 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) {}
 help: remove the extra argument
    |
 LL -     1,
-LL +     ""
+LL +     1,
    |
 
 error: aborting due to 14 previous errors
diff --git a/tests/ui/typeck/struct-enum-wrong-args.stderr b/tests/ui/typeck/struct-enum-wrong-args.stderr
index 71672f984c1..49ff3540027 100644
--- a/tests/ui/typeck/struct-enum-wrong-args.stderr
+++ b/tests/ui/typeck/struct-enum-wrong-args.stderr
@@ -25,7 +25,7 @@ note: tuple variant defined here
 help: remove the extra arguments
    |
 LL -     let _ = Ok(3, 6, 2);
-LL +     let _ = Ok(3, );
+LL +     let _ = Ok(3);
    |
 
 error[E0061]: this enum variant takes 1 argument but 0 arguments were supplied