Skip to content

Commit c807ac0

Browse files
committed
Use verbose suggestion for "wrong # of generics"
1 parent 2a1c384 commit c807ac0

File tree

52 files changed

+811
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+811
-401
lines changed

compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
888888
let comma = if args.len() > 0 { ", " } else { "" };
889889
let trait_path = self.tcx.def_path_str(trait_def_id);
890890
let method_name = self.tcx.item_name(self.def_id);
891-
err.span_suggestion(
891+
err.span_suggestion_verbose(
892892
expr.span,
893893
msg,
894894
format!("{trait_path}::{generics}::{method_name}({rcvr}{comma}{rest})"),
@@ -952,7 +952,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
952952
s = pluralize!(num_redundant_lt_args),
953953
);
954954

955-
err.span_suggestion(
955+
err.span_suggestion_verbose(
956956
span_redundant_lt_args,
957957
msg_lifetimes,
958958
"",
@@ -994,7 +994,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
994994
s = pluralize!(num_redundant_gen_args),
995995
);
996996

997-
err.span_suggestion(
997+
err.span_suggestion_verbose(
998998
span_redundant_type_or_const_args,
999999
msg_types_or_consts,
10001000
"",
@@ -1044,7 +1044,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
10441044
},
10451045
);
10461046

1047-
err.span_suggestion(span, msg, "", Applicability::MaybeIncorrect);
1047+
err.span_suggestion_verbose(span, msg, "", Applicability::MaybeIncorrect);
10481048
} else if redundant_lifetime_args && redundant_type_or_const_args {
10491049
remove_lifetime_args(err);
10501050
remove_type_or_const_args(err);

tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr

+18-9
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w
1818
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
1919
|
2020
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
21-
| ^--- help: remove these generics
22-
| |
23-
| expected 0 generic arguments
21+
| ^ expected 0 generic arguments
2422
|
2523
note: associated type defined here, with 0 generic parameters
2624
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
2725
|
2826
LL | type Y<'a>;
2927
| ^
28+
help: remove these generics
29+
|
30+
LL - fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
31+
LL + fn f<'a>(arg : Box<dyn X<Y = &'a ()>>) {}
32+
|
3033

3134
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
3235
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
@@ -49,16 +52,19 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w
4952
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
5053
|
5154
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
52-
| ^--- help: remove these generics
53-
| |
54-
| expected 0 generic arguments
55+
| ^ expected 0 generic arguments
5556
|
5657
note: associated type defined here, with 0 generic parameters
5758
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
5859
|
5960
LL | type Y<'a>;
6061
| ^
6162
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
63+
help: remove these generics
64+
|
65+
LL - fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
66+
LL + fn f<'a>(arg : Box<dyn X<Y = &'a ()>>) {}
67+
|
6268

6369
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
6470
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
@@ -81,16 +87,19 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w
8187
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
8288
|
8389
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
84-
| ^--- help: remove these generics
85-
| |
86-
| expected 0 generic arguments
90+
| ^ expected 0 generic arguments
8791
|
8892
note: associated type defined here, with 0 generic parameters
8993
--> $DIR/invalid_const_in_lifetime_position.rs:2:10
9094
|
9195
LL | type Y<'a>;
9296
| ^
9397
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
98+
help: remove these generics
99+
|
100+
LL - fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
101+
LL + fn f<'a>(arg : Box<dyn X<Y = &'a ()>>) {}
102+
|
94103

95104
error[E0038]: the trait `X` cannot be made into an object
96105
--> $DIR/invalid_const_in_lifetime_position.rs:4:20

tests/rustdoc-ui/mismatched_arg_count.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ error[E0107]: type alias takes 1 lifetime argument but 2 lifetime arguments were
22
--> $DIR/mismatched_arg_count.rs:7:29
33
|
44
LL | fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {}
5-
| ^^^^^ -- help: remove this lifetime argument
6-
| |
7-
| expected 1 lifetime argument
5+
| ^^^^^ expected 1 lifetime argument
86
|
97
note: type alias defined here, with 1 lifetime parameter: `'a`
108
--> $DIR/mismatched_arg_count.rs:5:6
119
|
1210
LL | type Alias<'a, T> = <T as Trait<'a>>::Assoc;
1311
| ^^^^^ --
12+
help: remove this lifetime argument
13+
|
14+
LL - fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {}
15+
LL + fn bar<'a, T: Trait<'a>>(_: Alias<'a, , T>) {}
16+
|
1417

1518
error: aborting due to 1 previous error
1619

tests/ui/argument-suggestions/issue-100154.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,19 @@ error[E0107]: function takes 0 generic arguments but 1 generic argument was supp
22
--> $DIR/issue-100154.rs:4:5
33
|
44
LL | foo::<()>(());
5-
| ^^^------ help: remove these generics
6-
| |
7-
| expected 0 generic arguments
5+
| ^^^ expected 0 generic arguments
86
|
97
note: function defined here, with 0 generic parameters
108
--> $DIR/issue-100154.rs:1:4
119
|
1210
LL | fn foo(i: impl std::fmt::Display) {}
1311
| ^^^
1412
= note: `impl Trait` cannot be explicitly specified as a generic argument
13+
help: remove these generics
14+
|
15+
LL - foo::<()>(());
16+
LL + foo(());
17+
|
1518

1619
error[E0277]: `()` doesn't implement `std::fmt::Display`
1720
--> $DIR/issue-100154.rs:4:11

tests/ui/borrowck/issue-82126-mismatched-subst-and-hir.stderr

+12-6
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp
22
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59
33
|
44
LL | async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> {
5-
| ^^^^^^^^^^^^---- help: remove these generics
6-
| |
7-
| expected 0 lifetime arguments
5+
| ^^^^^^^^^^^^ expected 0 lifetime arguments
86
|
97
note: struct defined here, with 0 lifetime parameters
108
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:24:8
119
|
1210
LL | struct LockedMarket<T>(T);
1311
| ^^^^^^^^^^^^
12+
help: remove these generics
13+
|
14+
LL - async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> {
15+
LL + async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket {
16+
|
1417

1518
error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied
1619
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59
@@ -32,16 +35,19 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp
3235
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59
3336
|
3437
LL | async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> {
35-
| ^^^^^^^^^^^^---- help: remove these generics
36-
| |
37-
| expected 0 lifetime arguments
38+
| ^^^^^^^^^^^^ expected 0 lifetime arguments
3839
|
3940
note: struct defined here, with 0 lifetime parameters
4041
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:24:8
4142
|
4243
LL | struct LockedMarket<T>(T);
4344
| ^^^^^^^^^^^^
4445
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
46+
help: remove these generics
47+
|
48+
LL - async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> {
49+
LL + async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket {
50+
|
4551

4652
error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied
4753
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ error[E0107]: trait takes at most 2 generic arguments but 3 generic arguments we
22
--> $DIR/transmutable-ice-110969.rs:11:14
33
|
44
LL | Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
5-
| ^^^^^^^^^^^^^^^^^^^^^ ------ help: remove this generic argument
6-
| |
7-
| expected at most 2 generic arguments
5+
| ^^^^^^^^^^^^^^^^^^^^^ expected at most 2 generic arguments
6+
|
7+
help: remove this generic argument
8+
|
9+
LL - Dst: BikeshedIntrinsicFrom<Src, Context, ASSUME>,
10+
LL + Dst: BikeshedIntrinsicFrom<Src, Context, >,
11+
|
812

913
error[E0308]: mismatched types
1014
--> $DIR/transmutable-ice-110969.rs:25:74

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,18 @@ error[E0107]: struct takes 2 generic arguments but 3 generic arguments were supp
2323
--> $DIR/infer-arg-test.rs:18:10
2424
|
2525
LL | let a: All<_, _, _>;
26-
| ^^^ - help: remove this generic argument
27-
| |
28-
| expected 2 generic arguments
26+
| ^^^ expected 2 generic arguments
2927
|
3028
note: struct defined here, with 2 generic parameters: `T`, `N`
3129
--> $DIR/infer-arg-test.rs:3:8
3230
|
3331
LL | struct All<'a, T, const N: usize> {
3432
| ^^^ - --------------
33+
help: remove this generic argument
34+
|
35+
LL - let a: All<_, _, _>;
36+
LL + let a: All<_, _, >;
37+
|
3538

3639
error: aborting due to 4 previous errors
3740

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ error[E0107]: function takes 1 generic argument but 2 generic arguments were sup
22
--> $DIR/issue_114151.rs:17:5
33
|
44
LL | foo::<_, L>([(); L + 1 + L]);
5-
| ^^^ - help: remove this generic argument
6-
| |
7-
| expected 1 generic argument
5+
| ^^^ expected 1 generic argument
86
|
97
note: function defined here, with 1 generic parameter: `N`
108
--> $DIR/issue_114151.rs:4:4
119
|
1210
LL | fn foo<const N: usize>(
1311
| ^^^ --------------
12+
help: remove this generic argument
13+
|
14+
LL - foo::<_, L>([(); L + 1 + L]);
15+
LL + foo::<_, >([(); L + 1 + L]);
16+
|
1417

1518
error[E0308]: mismatched types
1619
--> $DIR/issue_114151.rs:17:18

tests/ui/const-generics/generic_const_exprs/issue-102768.stderr

+18-9
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w
1818
--> $DIR/issue-102768.rs:9:30
1919
|
2020
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
21-
| ^--- help: remove these generics
22-
| |
23-
| expected 0 generic arguments
21+
| ^ expected 0 generic arguments
2422
|
2523
note: associated type defined here, with 0 generic parameters
2624
--> $DIR/issue-102768.rs:5:10
2725
|
2826
LL | type Y<'a>;
2927
| ^
28+
help: remove these generics
29+
|
30+
LL - fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
31+
LL + fn f2<'a>(arg: Box<dyn X<Y = &'a ()>>) {}
32+
|
3033

3134
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
3235
--> $DIR/issue-102768.rs:9:30
@@ -49,16 +52,19 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w
4952
--> $DIR/issue-102768.rs:9:30
5053
|
5154
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
52-
| ^--- help: remove these generics
53-
| |
54-
| expected 0 generic arguments
55+
| ^ expected 0 generic arguments
5556
|
5657
note: associated type defined here, with 0 generic parameters
5758
--> $DIR/issue-102768.rs:5:10
5859
|
5960
LL | type Y<'a>;
6061
| ^
6162
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
63+
help: remove these generics
64+
|
65+
LL - fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
66+
LL + fn f2<'a>(arg: Box<dyn X<Y = &'a ()>>) {}
67+
|
6268

6369
error[E0107]: associated type takes 1 lifetime argument but 0 lifetime arguments were supplied
6470
--> $DIR/issue-102768.rs:9:30
@@ -81,16 +87,19 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w
8187
--> $DIR/issue-102768.rs:9:30
8288
|
8389
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
84-
| ^--- help: remove these generics
85-
| |
86-
| expected 0 generic arguments
90+
| ^ expected 0 generic arguments
8791
|
8892
note: associated type defined here, with 0 generic parameters
8993
--> $DIR/issue-102768.rs:5:10
9094
|
9195
LL | type Y<'a>;
9296
| ^
9397
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
98+
help: remove these generics
99+
|
100+
LL - fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
101+
LL + fn f2<'a>(arg: Box<dyn X<Y = &'a ()>>) {}
102+
|
94103

95104
error[E0038]: the trait `X` cannot be made into an object
96105
--> $DIR/issue-102768.rs:9:24

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,18 @@ error[E0107]: function takes 2 generic arguments but 3 generic arguments were su
2020
--> $DIR/incorrect-number-of-const-args.rs:9:5
2121
|
2222
LL | foo::<0, 0, 0>();
23-
| ^^^ - help: remove this generic argument
24-
| |
25-
| expected 2 generic arguments
23+
| ^^^ expected 2 generic arguments
2624
|
2725
note: function defined here, with 2 generic parameters: `X`, `Y`
2826
--> $DIR/incorrect-number-of-const-args.rs:1:4
2927
|
3028
LL | fn foo<const X: usize, const Y: usize>() -> usize {
3129
| ^^^ -------------- --------------
30+
help: remove this generic argument
31+
|
32+
LL - foo::<0, 0, 0>();
33+
LL + foo::<0, 0, >();
34+
|
3235

3336
error: aborting due to 2 previous errors
3437

tests/ui/const-generics/invalid-const-arg-for-type-param.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,18 @@ error[E0107]: struct takes 0 generic arguments but 1 generic argument was suppli
2727
--> $DIR/invalid-const-arg-for-type-param.rs:12:5
2828
|
2929
LL | S::<0>;
30-
| ^----- help: remove these generics
31-
| |
32-
| expected 0 generic arguments
30+
| ^ expected 0 generic arguments
3331
|
3432
note: struct defined here, with 0 generic parameters
3533
--> $DIR/invalid-const-arg-for-type-param.rs:3:8
3634
|
3735
LL | struct S;
3836
| ^
37+
help: remove these generics
38+
|
39+
LL - S::<0>;
40+
LL + S;
41+
|
3942

4043
error: aborting due to 3 previous errors
4144

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ error[E0107]: struct takes 1 generic argument but 2 generic arguments were suppl
22
--> $DIR/invalid-constant-in-args.rs:4:12
33
|
44
LL | let _: Cell<&str, "a"> = Cell::new("");
5-
| ^^^^ --- help: remove this generic argument
6-
| |
7-
| expected 1 generic argument
5+
| ^^^^ expected 1 generic argument
6+
|
7+
help: remove this generic argument
8+
|
9+
LL - let _: Cell<&str, "a"> = Cell::new("");
10+
LL + let _: Cell<&str, > = Cell::new("");
11+
|
812

913
error: aborting due to 1 previous error
1014

0 commit comments

Comments
 (0)