Skip to content

Commit b30fdec

Browse files
committed
On generic and lifetime removal suggestion, do not leave behind stray ,
1 parent 5c2b36a commit b30fdec

26 files changed

+71
-62
lines changed

compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -939,17 +939,20 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
939939
}
940940
}
941941

942-
let span_lo_redundant_lt_args = lt_arg_spans[self.num_expected_lifetime_args()];
942+
let span_lo_redundant_lt_args = if self.num_expected_lifetime_args() == 0 {
943+
lt_arg_spans[0]
944+
} else {
945+
lt_arg_spans[self.num_expected_lifetime_args() - 1]
946+
};
943947
let span_hi_redundant_lt_args = lt_arg_spans[lt_arg_spans.len() - 1];
944948

945-
let span_redundant_lt_args = span_lo_redundant_lt_args.to(span_hi_redundant_lt_args);
949+
let span_redundant_lt_args =
950+
span_lo_redundant_lt_args.shrink_to_hi().to(span_hi_redundant_lt_args);
946951
debug!("span_redundant_lt_args: {:?}", span_redundant_lt_args);
947952

948953
let num_redundant_lt_args = lt_arg_spans.len() - self.num_expected_lifetime_args();
949-
let msg_lifetimes = format!(
950-
"remove the lifetime argument{s}",
951-
s = pluralize!(num_redundant_lt_args),
952-
);
954+
let msg_lifetimes =
955+
format!("remove the lifetime argument{s}", s = pluralize!(num_redundant_lt_args));
953956

954957
err.span_suggestion_verbose(
955958
span_redundant_lt_args,
@@ -978,11 +981,16 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
978981
}
979982

980983
let span_lo_redundant_type_or_const_args =
981-
gen_arg_spans[self.num_expected_type_or_const_args()];
984+
if self.num_expected_type_or_const_args() == 0 {
985+
gen_arg_spans[0]
986+
} else {
987+
gen_arg_spans[self.num_expected_type_or_const_args() - 1]
988+
};
982989
let span_hi_redundant_type_or_const_args = gen_arg_spans[gen_arg_spans.len() - 1];
990+
let span_redundant_type_or_const_args = span_lo_redundant_type_or_const_args
991+
.shrink_to_hi()
992+
.to(span_hi_redundant_type_or_const_args);
983993

984-
let span_redundant_type_or_const_args =
985-
span_lo_redundant_type_or_const_args.to(span_hi_redundant_type_or_const_args);
986994
debug!("span_redundant_type_or_const_args: {:?}", span_redundant_type_or_const_args);
987995

988996
let num_redundant_gen_args =

tests/rustdoc-ui/mismatched_arg_count.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type Alias<'a, T> = <T as Trait<'a>>::Assoc;
1212
help: remove the lifetime argument
1313
|
1414
LL - fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {}
15-
LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, , T>) {}
15+
LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, T>) {}
1616
|
1717

1818
error: aborting due to 1 previous error

tests/ui/const-generics/adt_const_params/transmutable-ice-110969.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
77
help: remove the unnecessary generic argument
88
|
99
LL - Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
10-
LL + Dst: BikeshedIntrinsicFrom<Src, Context, >,
10+
LL + Dst: BikeshedIntrinsicFrom<Src, Context>,
1111
|
1212

1313
error[E0308]: mismatched types

tests/ui/const-generics/generic_arg_infer/infer-arg-test.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ LL | struct All<'a, T, const N: usize> {
3333
help: remove the unnecessary generic argument
3434
|
3535
LL - let a: All<_, _, _>;
36-
LL + let a: All<_, _, >;
36+
LL + let a: All<_, _>;
3737
|
3838

3939
error: aborting due to 4 previous errors

tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | fn foo<const N: usize>(
1212
help: remove the unnecessary generic argument
1313
|
1414
LL - foo::<_, L>([(); L + 1 + L]);
15-
LL + foo::<_, >([(); L + 1 + L]);
15+
LL + foo::<_>([(); L + 1 + L]);
1616
|
1717

1818
error[E0308]: mismatched types

tests/ui/const-generics/incorrect-number-of-const-args.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LL | fn foo<const X: usize, const Y: usize>() -> usize {
3030
help: remove the unnecessary generic argument
3131
|
3232
LL - foo::<0, 0, 0>();
33-
LL + foo::<0, 0, >();
33+
LL + foo::<0, 0>();
3434
|
3535

3636
error: aborting due to 2 previous errors

tests/ui/const-generics/invalid-constant-in-args.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | let _: Cell<&str, "a"> = Cell::new("");
77
help: remove the unnecessary generic argument
88
|
99
LL - let _: Cell<&str, "a"> = Cell::new("");
10-
LL + let _: Cell<&str, > = Cell::new("");
10+
LL + let _: Cell<&str> = Cell::new("");
1111
|
1212

1313
error: aborting due to 1 previous error

tests/ui/constructor-lifetime-args.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LL | struct S<'a, 'b>(&'a u8, &'b u8);
3030
help: remove the lifetime argument
3131
|
3232
LL - S::<'static, 'static, 'static>(&0, &0);
33-
LL + S::<'static, 'static, >(&0, &0);
33+
LL + S::<'static, 'static>(&0, &0);
3434
|
3535

3636
error[E0107]: enum takes 2 lifetime arguments but 1 lifetime argument was supplied
@@ -65,7 +65,7 @@ LL | enum E<'a, 'b> {
6565
help: remove the lifetime argument
6666
|
6767
LL - E::V::<'static, 'static, 'static>(&0);
68-
LL + E::V::<'static, 'static, >(&0);
68+
LL + E::V::<'static, 'static>(&0);
6969
|
7070

7171
error: aborting due to 4 previous errors

tests/ui/error-codes/E0107.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ LL | struct Foo<'a>(&'a str);
4747
help: remove the lifetime arguments
4848
|
4949
LL - foo2: Foo<'a, 'b, 'c>,
50-
LL + foo2: Foo<'a, >,
50+
LL + foo2: Foo<'a>,
5151
|
5252

5353
error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were supplied
@@ -64,7 +64,7 @@ LL | struct Qux<'a, T>(&'a T);
6464
help: remove the lifetime argument
6565
|
6666
LL - qux1: Qux<'a, 'b, i32>,
67-
LL + qux1: Qux<'a, , i32>,
67+
LL + qux1: Qux<'a, i32>,
6868
|
6969

7070
error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were supplied
@@ -81,7 +81,7 @@ LL | struct Qux<'a, T>(&'a T);
8181
help: remove the lifetime argument
8282
|
8383
LL - qux2: Qux<'a, i32, 'b>,
84-
LL + qux2: Qux<'a, i32, >,
84+
LL + qux2: Qux<'a>,
8585
|
8686

8787
error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied
@@ -98,7 +98,7 @@ LL | struct Qux<'a, T>(&'a T);
9898
help: remove the lifetime arguments
9999
|
100100
LL - qux3: Qux<'a, 'b, 'c, i32>,
101-
LL + qux3: Qux<'a, , i32>,
101+
LL + qux3: Qux<'a, i32>,
102102
|
103103

104104
error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied
@@ -115,7 +115,7 @@ LL | struct Qux<'a, T>(&'a T);
115115
help: remove the lifetime arguments
116116
|
117117
LL - qux4: Qux<'a, i32, 'b, 'c>,
118-
LL + qux4: Qux<'a, i32, >,
118+
LL + qux4: Qux<'a>,
119119
|
120120

121121
error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were supplied
@@ -132,7 +132,7 @@ LL | struct Qux<'a, T>(&'a T);
132132
help: remove the lifetime argument
133133
|
134134
LL - qux5: Qux<'a, 'b, i32, 'c>,
135-
LL + qux5: Qux<'a, , i32, 'c>,
135+
LL + qux5: Qux<'a, i32, 'c>,
136136
|
137137

138138
error[E0107]: struct takes 0 lifetime arguments but 2 lifetime arguments were supplied

tests/ui/generic-associated-types/parameter_number_and_kind.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | type E<'a, T>;
1212
help: remove the lifetime argument
1313
|
1414
LL - type FErr1 = Self::E<'static, 'static>;
15-
LL + type FErr1 = Self::E<'static, >;
15+
LL + type FErr1 = Self::E<'static>;
1616
|
1717

1818
error[E0107]: associated type takes 1 generic argument but 0 generic arguments were supplied
@@ -45,7 +45,7 @@ LL | type E<'a, T>;
4545
help: remove the unnecessary generic argument
4646
|
4747
LL - type FErr2<T> = Self::E<'static, T, u32>;
48-
LL + type FErr2<T> = Self::E<'static, T, >;
48+
LL + type FErr2<T> = Self::E<'static, T>;
4949
|
5050

5151
error: aborting due to 3 previous errors

0 commit comments

Comments
 (0)