Skip to content

Commit 91c03ef

Browse files
authored
Rollup merge of #127374 - estebank:wrong-generic-args, r=oli-obk
Tweak "wrong # of generics" suggestions Fix incorrect suggestion, make verbose and change message to make more sense when it isn't a span label.
2 parents 720c6f1 + 921de9d commit 91c03ef

File tree

57 files changed

+184
-176
lines changed

Some content is hidden

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

57 files changed

+184
-176
lines changed

compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs

Lines changed: 20 additions & 14 deletions
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})"),
@@ -939,18 +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 {these} lifetime argument{s}",
951-
these = pluralize!("this", num_redundant_lt_args),
952-
s = pluralize!(num_redundant_lt_args),
953-
);
954+
let msg_lifetimes =
955+
format!("remove the lifetime argument{s}", s = pluralize!(num_redundant_lt_args));
954956

955957
err.span_suggestion(
956958
span_redundant_lt_args,
@@ -979,18 +981,22 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
979981
}
980982

981983
let span_lo_redundant_type_or_const_args =
982-
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+
};
983989
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);
984993

985-
let span_redundant_type_or_const_args =
986-
span_lo_redundant_type_or_const_args.to(span_hi_redundant_type_or_const_args);
987994
debug!("span_redundant_type_or_const_args: {:?}", span_redundant_type_or_const_args);
988995

989996
let num_redundant_gen_args =
990997
gen_arg_spans.len() - self.num_expected_type_or_const_args();
991998
let msg_types_or_consts = format!(
992-
"remove {these} generic argument{s}",
993-
these = pluralize!("this", num_redundant_gen_args),
999+
"remove the unnecessary generic argument{s}",
9941000
s = pluralize!(num_redundant_gen_args),
9951001
);
9961002

@@ -1036,7 +1042,7 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> {
10361042
.with_lo(self.path_segment.ident.span.hi());
10371043

10381044
let msg = format!(
1039-
"remove these {}generics",
1045+
"remove the unnecessary {}generics",
10401046
if self.gen_args.parenthesized == hir::GenericArgsParentheses::ParenSugar {
10411047
"parenthetical "
10421048
} else {

tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ 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
21+
| ^--- help: remove the unnecessary generics
2222
| |
2323
| expected 0 generic arguments
2424
|
@@ -49,7 +49,7 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w
4949
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
5050
|
5151
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
52-
| ^--- help: remove these generics
52+
| ^--- help: remove the unnecessary generics
5353
| |
5454
| expected 0 generic arguments
5555
|
@@ -81,7 +81,7 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w
8181
--> $DIR/invalid_const_in_lifetime_position.rs:4:26
8282
|
8383
LL | fn f<'a>(arg : Box<dyn X<Y<1> = &'a ()>>) {}
84-
| ^--- help: remove these generics
84+
| ^--- help: remove the unnecessary generics
8585
| |
8686
| expected 0 generic arguments
8787
|

tests/rustdoc-ui/mismatched_arg_count.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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
5+
| ^^^^^ ---- help: remove the lifetime argument
66
| |
77
| expected 1 lifetime argument
88
|

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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
5+
| ^^^------ help: remove the unnecessary generics
66
| |
77
| expected 0 generic arguments
88
|

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ 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
5+
| ^^^^^^^^^^^^---- help: remove the unnecessary generics
66
| |
77
| expected 0 lifetime arguments
88
|
@@ -32,7 +32,7 @@ error[E0107]: struct takes 0 lifetime arguments but 1 lifetime argument was supp
3232
--> $DIR/issue-82126-mismatched-subst-and-hir.rs:16:59
3333
|
3434
LL | async fn buy_lock(coroutine: &Mutex<MarketMultiplier>) -> LockedMarket<'_> {
35-
| ^^^^^^^^^^^^---- help: remove these generics
35+
| ^^^^^^^^^^^^---- help: remove the unnecessary generics
3636
| |
3737
| expected 0 lifetime arguments
3838
|

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
@@ -2,7 +2,7 @@ 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
5+
| ^^^^^^^^^^^^^^^^^^^^^ -------- help: remove the unnecessary generic argument
66
| |
77
| expected at most 2 generic arguments
88

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
@@ -23,7 +23,7 @@ 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
26+
| ^^^ --- help: remove the unnecessary generic argument
2727
| |
2828
| expected 2 generic arguments
2929
|

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
@@ -2,7 +2,7 @@ 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
5+
| ^^^ --- help: remove the unnecessary generic argument
66
| |
77
| expected 1 generic argument
88
|

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ 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
21+
| ^--- help: remove the unnecessary generics
2222
| |
2323
| expected 0 generic arguments
2424
|
@@ -49,7 +49,7 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w
4949
--> $DIR/issue-102768.rs:9:30
5050
|
5151
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
52-
| ^--- help: remove these generics
52+
| ^--- help: remove the unnecessary generics
5353
| |
5454
| expected 0 generic arguments
5555
|
@@ -81,7 +81,7 @@ error[E0107]: associated type takes 0 generic arguments but 1 generic argument w
8181
--> $DIR/issue-102768.rs:9:30
8282
|
8383
LL | fn f2<'a>(arg: Box<dyn X<Y<1> = &'a ()>>) {}
84-
| ^--- help: remove these generics
84+
| ^--- help: remove the unnecessary generics
8585
| |
8686
| expected 0 generic arguments
8787
|

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ 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
23+
| ^^^ --- help: remove the unnecessary generic argument
2424
| |
2525
| expected 2 generic arguments
2626
|

0 commit comments

Comments
 (0)