Skip to content

Commit 776ad90

Browse files
committed
get_hir_params_with_generics: Don't return useless results.
1 parent 6378fbc commit 776ad90

File tree

130 files changed

+378
-485
lines changed

Some content is hidden

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

130 files changed

+378
-485
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+16-11
Original file line numberDiff line numberDiff line change
@@ -2373,9 +2373,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
23732373
let mut generics_with_unmatched_params = Vec::new();
23742374

23752375
let check_for_matched_generics = || {
2376-
if matched_inputs.iter().any(|x| x.is_some())
2377-
&& params_with_generics.iter().any(|(x, _)| x.is_some())
2378-
{
2376+
if matched_inputs.iter().any(|x| x.is_some()) {
23792377
for (idx, (generic, _)) in params_with_generics.iter_enumerated() {
23802378
// Param has to have a generic and be matched to be relevant
23812379
if matched_inputs[idx].is_none() {
@@ -2666,8 +2664,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26662664
}
26672665

26682666
/// Returns the parameters of a function, with their generic parameters if those are the full
2669-
/// type of that parameter. Returns `None` if the function has no generics or the body is
2670-
/// unavailable (eg is an instrinsic).
2667+
/// type of that parameter.
2668+
///
2669+
/// Returns `None` if the function has no parameters taking generic type, or the function is
2670+
/// both not a trait function and has no available body (eg is an instrinsic).
26712671
fn get_hir_params_with_generics(
26722672
&self,
26732673
def_id: DefId,
@@ -2695,33 +2695,38 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
26952695
};
26962696

26972697
// Make sure to remove both the receiver and variadic argument. Both are removed
2698-
// when matching parameter types.
2698+
// when warning about mismatched parameters.
2699+
let mut found_generic = false;
26992700
let fn_inputs = sig.decl.inputs.get(is_method as usize..)?.iter().map(|param| {
27002701
if let hir::TyKind::Path(QPath::Resolved(
27012702
_,
27022703
&hir::Path { res: Res::Def(_, res_def_id), .. },
27032704
)) = param.kind
27042705
{
2705-
generics.params.iter().find(|param| param.def_id.to_def_id() == res_def_id)
2706+
let res =
2707+
generics.params.iter().find(|param| param.def_id.to_def_id() == res_def_id);
2708+
found_generic |= res.is_some();
2709+
res
27062710
} else {
27072711
None
27082712
}
27092713
});
2710-
match (body_id, param_names) {
2714+
let res = match (body_id, param_names) {
27112715
(Some(_), Some(_)) | (None, None) => unreachable!(),
27122716
(Some(body), None) => {
27132717
let params = self.tcx.hir().body(body).params;
27142718
let params =
27152719
params.get(is_method as usize..params.len() - sig.decl.c_variadic as usize)?;
27162720
debug_assert_eq!(params.len(), fn_inputs.len());
2717-
Some(fn_inputs.zip(params.iter().map(|param| FnParam::Param(param))).collect())
2721+
fn_inputs.zip(params.iter().map(|param| FnParam::Param(param))).collect()
27182722
}
27192723
(None, Some(params)) => {
27202724
let params = params.get(is_method as usize..)?;
27212725
debug_assert_eq!(params.len(), fn_inputs.len());
2722-
Some(fn_inputs.zip(params.iter().map(|param| FnParam::Name(param))).collect())
2726+
fn_inputs.zip(params.iter().map(|param| FnParam::Name(param))).collect()
27232727
}
2724-
}
2728+
};
2729+
found_generic.then_some(res)
27252730
}
27262731
}
27272732

tests/ui/alloc-error/alloc-error-handler-bad-signature-1.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ note: function defined here
1616
|
1717
LL | fn oom(
1818
| ^^^
19-
LL | info: &Layout,
20-
| -------------
2119
= note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info)
2220

2321
error[E0308]: mismatched types

tests/ui/alloc-error/alloc-error-handler-bad-signature-2.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ note: function defined here
2424
|
2525
LL | fn oom(
2626
| ^^^
27-
LL | info: Layout,
28-
| ------------
2927
= note: this error originates in the attribute macro `alloc_error_handler` (in Nightly builds, run with -Z macro-backtrace for more info)
3028

3129
error[E0308]: mismatched types

tests/ui/argument-suggestions/basic.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ note: function defined here
1010
--> $DIR/basic.rs:13:4
1111
|
1212
LL | fn invalid(_i: u32) {}
13-
| ^^^^^^^ -------
13+
| ^^^^^^^
1414

1515
error[E0061]: this function takes 0 arguments but 1 argument was supplied
1616
--> $DIR/basic.rs:21:5
@@ -39,7 +39,7 @@ note: function defined here
3939
--> $DIR/basic.rs:15:4
4040
|
4141
LL | fn missing(_i: u32) {}
42-
| ^^^^^^^ -------
42+
| ^^^^^^^
4343
help: provide the argument
4444
|
4545
LL | missing(/* u32 */);
@@ -57,7 +57,7 @@ note: function defined here
5757
--> $DIR/basic.rs:16:4
5858
|
5959
LL | fn swapped(_i: u32, _s: &str) {}
60-
| ^^^^^^^ ------- --------
60+
| ^^^^^^^
6161
help: swap these arguments
6262
|
6363
LL | swapped(1, "");
@@ -76,7 +76,7 @@ note: function defined here
7676
--> $DIR/basic.rs:17:4
7777
|
7878
LL | fn permuted(_x: X, _y: Y, _z: Z) {}
79-
| ^^^^^^^^ ----- ----- -----
79+
| ^^^^^^^^
8080
help: reorder these arguments
8181
|
8282
LL | permuted(X {}, Y {}, Z {});

tests/ui/argument-suggestions/complex.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ note: function defined here
88
--> $DIR/complex.rs:11:4
99
|
1010
LL | fn complex(_i: u32, _s: &str, _e: E, _f: F, _g: G, _x: X, _y: Y, _z: Z ) {}
11-
| ^^^^^^^ ------- -------- ----- ----- ----- ----- ----- -----
11+
| ^^^^^^^
1212
help: did you mean
1313
|
1414
LL | complex(/* u32 */, &"", /* E */, F::X2, G{}, X {}, Y {}, Z {});

tests/ui/argument-suggestions/display-is-suggestable.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ note: function defined here
88
--> $DIR/display-is-suggestable.rs:3:4
99
|
1010
LL | fn foo(x: &(dyn Display + Send)) {}
11-
| ^^^ ------------------------
11+
| ^^^
1212
help: provide the argument
1313
|
1414
LL | foo(/* &dyn std::fmt::Display + Send */);

tests/ui/argument-suggestions/extra_arguments.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ note: function defined here
9797
--> $DIR/extra_arguments.rs:3:4
9898
|
9999
LL | fn two_arg_same(_a: i32, _b: i32) {}
100-
| ^^^^^^^^^^^^ ------- -------
100+
| ^^^^^^^^^^^^
101101
help: remove the extra argument
102102
|
103103
LL - two_arg_same(1, 1, 1);
@@ -114,7 +114,7 @@ note: function defined here
114114
--> $DIR/extra_arguments.rs:3:4
115115
|
116116
LL | fn two_arg_same(_a: i32, _b: i32) {}
117-
| ^^^^^^^^^^^^ ------- -------
117+
| ^^^^^^^^^^^^
118118
help: remove the extra argument
119119
|
120120
LL - two_arg_same(1, 1, 1.0);
@@ -131,7 +131,7 @@ note: function defined here
131131
--> $DIR/extra_arguments.rs:4:4
132132
|
133133
LL | fn two_arg_diff(_a: i32, _b: &str) {}
134-
| ^^^^^^^^^^^^ ------- --------
134+
| ^^^^^^^^^^^^
135135
help: remove the extra argument
136136
|
137137
LL - two_arg_diff(1, 1, "");
@@ -148,7 +148,7 @@ note: function defined here
148148
--> $DIR/extra_arguments.rs:4:4
149149
|
150150
LL | fn two_arg_diff(_a: i32, _b: &str) {}
151-
| ^^^^^^^^^^^^ ------- --------
151+
| ^^^^^^^^^^^^
152152
help: remove the extra argument
153153
|
154154
LL - two_arg_diff(1, "", "");
@@ -167,7 +167,7 @@ note: function defined here
167167
--> $DIR/extra_arguments.rs:4:4
168168
|
169169
LL | fn two_arg_diff(_a: i32, _b: &str) {}
170-
| ^^^^^^^^^^^^ ------- --------
170+
| ^^^^^^^^^^^^
171171
help: remove the extra arguments
172172
|
173173
LL - two_arg_diff(1, 1, "", "");
@@ -186,7 +186,7 @@ note: function defined here
186186
--> $DIR/extra_arguments.rs:4:4
187187
|
188188
LL | fn two_arg_diff(_a: i32, _b: &str) {}
189-
| ^^^^^^^^^^^^ ------- --------
189+
| ^^^^^^^^^^^^
190190
help: remove the extra arguments
191191
|
192192
LL - two_arg_diff(1, "", 1, "");
@@ -203,7 +203,7 @@ note: function defined here
203203
--> $DIR/extra_arguments.rs:3:4
204204
|
205205
LL | fn two_arg_same(_a: i32, _b: i32) {}
206-
| ^^^^^^^^^^^^ ------- -------
206+
| ^^^^^^^^^^^^
207207
help: remove the extra argument
208208
|
209209
LL - two_arg_same(1, 1, "");
@@ -220,7 +220,7 @@ note: function defined here
220220
--> $DIR/extra_arguments.rs:4:4
221221
|
222222
LL | fn two_arg_diff(_a: i32, _b: &str) {}
223-
| ^^^^^^^^^^^^ ------- --------
223+
| ^^^^^^^^^^^^
224224
help: remove the extra argument
225225
|
226226
LL - two_arg_diff(1, 1, "");
@@ -240,7 +240,7 @@ note: function defined here
240240
--> $DIR/extra_arguments.rs:3:4
241241
|
242242
LL | fn two_arg_same(_a: i32, _b: i32) {}
243-
| ^^^^^^^^^^^^ ------- -------
243+
| ^^^^^^^^^^^^
244244
help: remove the extra argument
245245
|
246246
LL - 1,
@@ -261,7 +261,7 @@ note: function defined here
261261
--> $DIR/extra_arguments.rs:4:4
262262
|
263263
LL | fn two_arg_diff(_a: i32, _b: &str) {}
264-
| ^^^^^^^^^^^^ ------- --------
264+
| ^^^^^^^^^^^^
265265
help: remove the extra argument
266266
|
267267
LL - 1,

0 commit comments

Comments
 (0)