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

+17-9
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+6-6
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

+2-2
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

tests/ui/generics/bad-mid-path-type-params.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | fn new<U>(x: T, _: U) -> S<T> {
1212
help: remove the unnecessary generic argument
1313
|
1414
LL - let _ = S::new::<isize,f64>(1, 1.0);
15-
LL + let _ = S::new::<isize,>(1, 1.0);
15+
LL + let _ = S::new::<isize>(1, 1.0);
1616
|
1717

1818
error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supplied
@@ -46,7 +46,7 @@ LL | fn new<U>(x: T, y: U) -> Self;
4646
help: remove the unnecessary generic argument
4747
|
4848
LL - let _: S2 = Trait::new::<isize,f64>(1, 1.0);
49-
LL + let _: S2 = Trait::new::<isize,>(1, 1.0);
49+
LL + let _: S2 = Trait::new::<isize>(1, 1.0);
5050
|
5151

5252
error[E0107]: trait takes 0 lifetime arguments but 1 lifetime argument was supplied
@@ -80,7 +80,7 @@ LL | fn new<U>(x: T, y: U) -> Self;
8080
help: remove the unnecessary generic argument
8181
|
8282
LL - let _: S2 = Trait::<'a,isize>::new::<f64,f64>(1, 1.0);
83-
LL + let _: S2 = Trait::<'a,isize>::new::<f64,>(1, 1.0);
83+
LL + let _: S2 = Trait::<'a,isize>::new::<f64>(1, 1.0);
8484
|
8585

8686
error: aborting due to 5 previous errors

tests/ui/generics/foreign-generic-mismatch.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ LL | pub fn lt_arg<'a: 'a>() {}
3030
help: remove the lifetime argument
3131
|
3232
LL - foreign_generic_mismatch::lt_arg::<'static, 'static>();
33-
LL + foreign_generic_mismatch::lt_arg::<'static, >();
33+
LL + foreign_generic_mismatch::lt_arg::<'static>();
3434
|
3535

3636
error: aborting due to 2 previous errors

tests/ui/generics/generic-arg-mismatch-recover.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | struct Foo<'a, T: 'a>(&'a T);
1212
help: remove the lifetime argument
1313
|
1414
LL - Foo::<'static, 'static, ()>(&0);
15-
LL + Foo::<'static, , ()>(&0);
15+
LL + Foo::<'static, ()>(&0);
1616
|
1717

1818
error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were supplied
@@ -29,7 +29,7 @@ LL | struct Bar<'a>(&'a ());
2929
help: remove the lifetime argument
3030
|
3131
LL - Bar::<'static, 'static, ()>(&());
32-
LL + Bar::<'static, , ()>(&());
32+
LL + Bar::<'static, ()>(&());
3333
|
3434

3535
error[E0107]: struct takes 0 generic arguments but 1 generic argument was supplied

tests/ui/generics/generic-impl-more-params-with-defaults.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | struct Vec<T, A = Heap>(
1212
help: remove the unnecessary generic argument
1313
|
1414
LL - Vec::<isize, Heap, bool>::new();
15-
LL + Vec::<isize, Heap, >::new();
15+
LL + Vec::<isize, Heap>::new();
1616
|
1717

1818
error: aborting due to 1 previous error

tests/ui/generics/generic-type-more-params-with-defaults.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | struct Vec<T, A = Heap>(
1212
help: remove the unnecessary generic argument
1313
|
1414
LL - let _: Vec<isize, Heap, bool>;
15-
LL + let _: Vec<isize, Heap, >;
15+
LL + let _: Vec<isize, Heap>;
1616
|
1717

1818
error: aborting due to 1 previous error

0 commit comments

Comments
 (0)