Skip to content

Commit ea116d1

Browse files
authored
Unrolled build for rust-lang#127374
Rollup merge of rust-lang#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 2ccafed + 921de9d commit ea116d1

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

Diff for: compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs

+20-14
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 {

Diff for: tests/rustdoc-ui/invalid_const_in_lifetime_position.stderr

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

Diff for: tests/rustdoc-ui/mismatched_arg_count.stderr

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

Diff for: tests/ui/argument-suggestions/issue-100154.stderr

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

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

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

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

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

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

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

Diff for: tests/ui/const-generics/generic_const_exprs/const_kind_expr/issue_114151.stderr

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

Diff for: tests/ui/const-generics/generic_const_exprs/issue-102768.stderr

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

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

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ help: consider moving this generic argument to the `TryInto` trait, which takes
88
|
99
LL | let _: u32 = TryInto::<32>::try_into(5i32).unwrap();
1010
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
11-
help: remove these generics
11+
help: remove the unnecessary generics
1212
|
1313
LL - let _: u32 = 5i32.try_into::<32>().unwrap();
1414
LL + let _: u32 = 5i32.try_into().unwrap();
@@ -27,7 +27,7 @@ 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
30+
| ^----- help: remove the unnecessary generics
3131
| |
3232
| expected 0 generic arguments
3333
|

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

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

Diff for: tests/ui/constructor-lifetime-args.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ error[E0107]: struct takes 2 lifetime arguments but 3 lifetime arguments were su
2020
--> $DIR/constructor-lifetime-args.rs:19:5
2121
|
2222
LL | S::<'static, 'static, 'static>(&0, &0);
23-
| ^ ------- help: remove this lifetime argument
23+
| ^ --------- help: remove the lifetime argument
2424
| |
2525
| expected 2 lifetime arguments
2626
|
@@ -52,7 +52,7 @@ error[E0107]: enum takes 2 lifetime arguments but 3 lifetime arguments were supp
5252
--> $DIR/constructor-lifetime-args.rs:24:8
5353
|
5454
LL | E::V::<'static, 'static, 'static>(&0);
55-
| ^ ------- help: remove this lifetime argument
55+
| ^ --------- help: remove the lifetime argument
5656
| |
5757
| expected 2 lifetime arguments
5858
|

Diff for: tests/ui/consts/effect_param.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,31 @@ error[E0107]: method takes 0 generic arguments but 1 generic argument was suppli
22
--> $DIR/effect_param.rs:11:9
33
|
44
LL | i8::checked_sub::<false>(42, 43);
5-
| ^^^^^^^^^^^--------- help: remove these generics
5+
| ^^^^^^^^^^^--------- help: remove the unnecessary generics
66
| |
77
| expected 0 generic arguments
88

99
error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied
1010
--> $DIR/effect_param.rs:13:9
1111
|
1212
LL | i8::checked_sub::<true>(42, 43);
13-
| ^^^^^^^^^^^-------- help: remove these generics
13+
| ^^^^^^^^^^^-------- help: remove the unnecessary generics
1414
| |
1515
| expected 0 generic arguments
1616

1717
error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied
1818
--> $DIR/effect_param.rs:4:9
1919
|
2020
LL | i8::checked_sub::<true>(42, 43);
21-
| ^^^^^^^^^^^-------- help: remove these generics
21+
| ^^^^^^^^^^^-------- help: remove the unnecessary generics
2222
| |
2323
| expected 0 generic arguments
2424

2525
error[E0107]: method takes 0 generic arguments but 1 generic argument was supplied
2626
--> $DIR/effect_param.rs:6:9
2727
|
2828
LL | i8::checked_sub::<false>(42, 43);
29-
| ^^^^^^^^^^^--------- help: remove these generics
29+
| ^^^^^^^^^^^--------- help: remove the unnecessary generics
3030
| |
3131
| expected 0 generic arguments
3232

Diff for: tests/ui/error-codes/E0107.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,35 @@ struct Baz<'a, 'b, 'c> {
1616

1717
bar: Bar<'a>,
1818
//~^ ERROR enum takes 0 lifetime arguments
19-
//~| HELP remove these generics
19+
//~| HELP remove the unnecessary generics
2020

2121
foo2: Foo<'a, 'b, 'c>,
2222
//~^ ERROR struct takes 1 lifetime argument
23-
//~| HELP remove these lifetime arguments
23+
//~| HELP remove the lifetime arguments
2424

2525
qux1: Qux<'a, 'b, i32>,
2626
//~^ ERROR struct takes 1 lifetime argument
27-
//~| HELP remove this lifetime argument
27+
//~| HELP remove the lifetime argument
2828

2929
qux2: Qux<'a, i32, 'b>,
3030
//~^ ERROR struct takes 1 lifetime argument
31-
//~| HELP remove this lifetime argument
31+
//~| HELP remove the lifetime argument
3232

3333
qux3: Qux<'a, 'b, 'c, i32>,
3434
//~^ ERROR struct takes 1 lifetime argument
35-
//~| HELP remove these lifetime arguments
35+
//~| HELP remove the lifetime arguments
3636

3737
qux4: Qux<'a, i32, 'b, 'c>,
3838
//~^ ERROR struct takes 1 lifetime argument
39-
//~| HELP remove these lifetime arguments
39+
//~| HELP remove the lifetime arguments
4040

4141
qux5: Qux<'a, 'b, i32, 'c>,
4242
//~^ ERROR struct takes 1 lifetime argument
43-
//~| HELP remove this lifetime argument
43+
//~| HELP remove the lifetime argument
4444

4545
quux: Quux<'a, i32, 'b>,
4646
//~^ ERROR struct takes 0 lifetime arguments
47-
//~| HELP remove this lifetime argument
47+
//~| HELP remove the lifetime argument
4848
}
4949

5050
pub trait T {

Diff for: tests/ui/error-codes/E0107.stderr

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ error[E0107]: enum takes 0 lifetime arguments but 1 lifetime argument was suppli
2020
--> $DIR/E0107.rs:17:10
2121
|
2222
LL | bar: Bar<'a>,
23-
| ^^^---- help: remove these generics
23+
| ^^^---- help: remove the unnecessary generics
2424
| |
2525
| expected 0 lifetime arguments
2626
|
@@ -34,7 +34,7 @@ error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were sup
3434
--> $DIR/E0107.rs:21:11
3535
|
3636
LL | foo2: Foo<'a, 'b, 'c>,
37-
| ^^^ ------ help: remove these lifetime arguments
37+
| ^^^ -------- help: remove the lifetime arguments
3838
| |
3939
| expected 1 lifetime argument
4040
|
@@ -48,7 +48,7 @@ error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were sup
4848
--> $DIR/E0107.rs:25:11
4949
|
5050
LL | qux1: Qux<'a, 'b, i32>,
51-
| ^^^ -- help: remove this lifetime argument
51+
| ^^^ ---- help: remove the lifetime argument
5252
| |
5353
| expected 1 lifetime argument
5454
|
@@ -62,7 +62,7 @@ error[E0107]: struct takes 1 lifetime argument but 2 lifetime arguments were sup
6262
--> $DIR/E0107.rs:29:11
6363
|
6464
LL | qux2: Qux<'a, i32, 'b>,
65-
| ^^^ -- help: remove this lifetime argument
65+
| ^^^ --------- help: remove the lifetime argument
6666
| |
6767
| expected 1 lifetime argument
6868
|
@@ -76,7 +76,7 @@ error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were sup
7676
--> $DIR/E0107.rs:33:11
7777
|
7878
LL | qux3: Qux<'a, 'b, 'c, i32>,
79-
| ^^^ ------ help: remove these lifetime arguments
79+
| ^^^ -------- help: remove the lifetime arguments
8080
| |
8181
| expected 1 lifetime argument
8282
|
@@ -90,7 +90,7 @@ error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were sup
9090
--> $DIR/E0107.rs:37:11
9191
|
9292
LL | qux4: Qux<'a, i32, 'b, 'c>,
93-
| ^^^ ------ help: remove these lifetime arguments
93+
| ^^^ ------------- help: remove the lifetime arguments
9494
| |
9595
| expected 1 lifetime argument
9696
|
@@ -104,7 +104,7 @@ error[E0107]: struct takes 1 lifetime argument but 3 lifetime arguments were sup
104104
--> $DIR/E0107.rs:41:11
105105
|
106106
LL | qux5: Qux<'a, 'b, i32, 'c>,
107-
| ^^^ -- help: remove this lifetime argument
107+
| ^^^ ---- help: remove the lifetime argument
108108
| |
109109
| expected 1 lifetime argument
110110
|
@@ -118,7 +118,7 @@ error[E0107]: struct takes 0 lifetime arguments but 2 lifetime arguments were su
118118
--> $DIR/E0107.rs:45:11
119119
|
120120
LL | quux: Quux<'a, i32, 'b>,
121-
| ^^^^ -- help: remove this lifetime argument
121+
| ^^^^ -- help: remove the lifetime argument
122122
| |
123123
| expected 0 lifetime arguments
124124
|

0 commit comments

Comments
 (0)