diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2024-07-05 17:24:23 +0000 | 
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2024-07-22 22:04:49 +0000 | 
| commit | b30fdec5fb283641fc0452fa6ca60193a16bb30d (patch) | |
| tree | c360a87a4f13502e1e033c9ae1a545d07be73fcc /compiler/rustc_hir_analysis/src/errors | |
| parent | 5c2b36a21cabafb1f08e278f4c6ed61753a654cf (diff) | |
| download | rust-b30fdec5fb283641fc0452fa6ca60193a16bb30d.tar.gz rust-b30fdec5fb283641fc0452fa6ca60193a16bb30d.zip | |
On generic and lifetime removal suggestion, do not leave behind stray `,`
Diffstat (limited to 'compiler/rustc_hir_analysis/src/errors')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs | 26 | 
1 files changed, 17 insertions, 9 deletions
| diff --git a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs index 6c2ec1acdf9..7443070b9de 100644 --- a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs @@ -939,17 +939,20 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } } - let span_lo_redundant_lt_args = lt_arg_spans[self.num_expected_lifetime_args()]; + let span_lo_redundant_lt_args = if self.num_expected_lifetime_args() == 0 { + lt_arg_spans[0] + } else { + lt_arg_spans[self.num_expected_lifetime_args() - 1] + }; let span_hi_redundant_lt_args = lt_arg_spans[lt_arg_spans.len() - 1]; - let span_redundant_lt_args = span_lo_redundant_lt_args.to(span_hi_redundant_lt_args); + let span_redundant_lt_args = + span_lo_redundant_lt_args.shrink_to_hi().to(span_hi_redundant_lt_args); debug!("span_redundant_lt_args: {:?}", span_redundant_lt_args); let num_redundant_lt_args = lt_arg_spans.len() - self.num_expected_lifetime_args(); - let msg_lifetimes = format!( - "remove the lifetime argument{s}", - s = pluralize!(num_redundant_lt_args), - ); + let msg_lifetimes = + format!("remove the lifetime argument{s}", s = pluralize!(num_redundant_lt_args)); err.span_suggestion_verbose( span_redundant_lt_args, @@ -978,11 +981,16 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { } let span_lo_redundant_type_or_const_args = - gen_arg_spans[self.num_expected_type_or_const_args()]; + if self.num_expected_type_or_const_args() == 0 { + gen_arg_spans[0] + } else { + gen_arg_spans[self.num_expected_type_or_const_args() - 1] + }; let span_hi_redundant_type_or_const_args = gen_arg_spans[gen_arg_spans.len() - 1]; + let span_redundant_type_or_const_args = span_lo_redundant_type_or_const_args + .shrink_to_hi() + .to(span_hi_redundant_type_or_const_args); - let span_redundant_type_or_const_args = - span_lo_redundant_type_or_const_args.to(span_hi_redundant_type_or_const_args); debug!("span_redundant_type_or_const_args: {:?}", span_redundant_type_or_const_args); let num_redundant_gen_args = | 
