Skip to content

Commit 446fc6a

Browse files
committed
Progress checkin
1 parent 0c7dc80 commit 446fc6a

File tree

5 files changed

+80
-16
lines changed

5 files changed

+80
-16
lines changed

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,19 +2239,43 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
22392239
.skip(if is_method { 1 } else { 0 })
22402240
.collect();
22412241

2242-
if params.len() == param_generics.len() {
2242+
let check_for_matched_generics_fn = || {
2243+
if params.len() == param_generics.len()
2244+
&& matched_inputs.iter().any(|x| x.is_some())
2245+
&& param_generics.iter().any(|x| x.is_some())
2246+
{
2247+
for (idx, generic) in param_generics.iter().enumerate() {
2248+
if matched_inputs[idx.into()].is_none() {
2249+
continue;
2250+
}
2251+
2252+
let Some(generic) = generic else {
2253+
continue;
2254+
};
2255+
2256+
for unmatching_idx in idx + 1..params.len() {
2257+
if matched_inputs[unmatching_idx.into()].is_none()
2258+
&& let Some(unmatched_idx_param_generic) =
2259+
param_generics[unmatching_idx]
2260+
&& unmatched_idx_param_generic.name.ident() == generic.name.ident()
2261+
{
2262+
return true;
2263+
}
2264+
}
2265+
}
2266+
}
2267+
false
2268+
};
2269+
2270+
if check_for_matched_generics_fn() {
22432271
let mut generics_map: Vec<(usize, &hir::GenericParam<'_>)> = Vec::new();
22442272
// This is a map from the index of the generic to the index of the parameter and the
22452273
// parameter
22462274
let mut matched_params_map: Vec<(usize, usize, &hir::Param<'_>)> = Vec::new();
22472275
let mut unmatched_params_map: Vec<(usize, &hir::Param<'_>)> = Vec::new();
22482276

22492277
for (idx, (param, generic)) in
2250-
params.iter().zip_eq(param_generics.iter()).enumerate().filter(
2251-
|(idx, (_, _))| {
2252-
expected_idx.map_or(true, |expected_idx| expected_idx == *idx)
2253-
},
2254-
)
2278+
params.iter().zip_eq(param_generics.iter()).enumerate()
22552279
{
22562280
if matched_inputs[idx.into()].is_none() {
22572281
spans.push_span_label(param.span, "");

tests/ui/async-await/coroutine-desc.stderr

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ note: function defined here
1414
--> $DIR/coroutine-desc.rs:8:4
1515
|
1616
LL | fn fun<F: Future<Output = ()>>(f1: F, f2: F) {}
17-
| ^^^ -----
17+
| ^^^ - ----- -----
18+
| | | |
19+
| | | this parameter needs to match the `async` block type of `f1`
20+
| | `f2` needs to match the type of this parameter
21+
| `f1` and `f2` all reference this parameter F
1822

1923
error[E0308]: mismatched types
2024
--> $DIR/coroutine-desc.rs:12:16
@@ -31,7 +35,11 @@ note: function defined here
3135
--> $DIR/coroutine-desc.rs:8:4
3236
|
3337
LL | fn fun<F: Future<Output = ()>>(f1: F, f2: F) {}
34-
| ^^^ -----
38+
| ^^^ - ----- -----
39+
| | | |
40+
| | | this parameter needs to match the future type of `f1`
41+
| | `f2` needs to match the type of this parameter
42+
| `f1` and `f2` all reference this parameter F
3543

3644
error[E0308]: mismatched types
3745
--> $DIR/coroutine-desc.rs:14:26
@@ -49,7 +57,11 @@ note: function defined here
4957
--> $DIR/coroutine-desc.rs:8:4
5058
|
5159
LL | fn fun<F: Future<Output = ()>>(f1: F, f2: F) {}
52-
| ^^^ -----
60+
| ^^^ - ----- -----
61+
| | | |
62+
| | | this parameter needs to match the `async` closure body type of `f1`
63+
| | `f2` needs to match the type of this parameter
64+
| `f1` and `f2` all reference this parameter F
5365

5466
error: aborting due to 3 previous errors
5567

tests/ui/coercion/coerce-reborrow-multi-arg-fail.stderr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ note: function defined here
1313
--> $DIR/coerce-reborrow-multi-arg-fail.rs:1:4
1414
|
1515
LL | fn test<T>(_a: T, _b: T) {}
16-
| ^^^^ -----
16+
| ^^^^ - ----- -----
17+
| | | |
18+
| | | this parameter needs to match the `&mut {integer}` type of `_a`
19+
| | `_b` needs to match the type of this parameter
20+
| `_a` and `_b` all reference this parameter T
1721

1822
error: aborting due to 1 previous error
1923

tests/ui/fn/fn-item-type.stderr

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@ note: function defined here
1414
--> $DIR/fn-item-type.rs:11:4
1515
|
1616
LL | fn eq<T>(x: T, y: T) {}
17-
| ^^ ----
17+
| ^^ - ---- ----
18+
| | | |
19+
| | | this parameter needs to match the fn item type of `x`
20+
| | `y` needs to match the type of this parameter
21+
| `x` and `y` all reference this parameter T
1822
= help: consider casting both fn items to fn pointers using `as fn(isize) -> isize`
1923

2024
error[E0308]: mismatched types
@@ -33,7 +37,11 @@ note: function defined here
3337
--> $DIR/fn-item-type.rs:11:4
3438
|
3539
LL | fn eq<T>(x: T, y: T) {}
36-
| ^^ ----
40+
| ^^ - ---- ----
41+
| | | |
42+
| | | this parameter needs to match the fn item type of `x`
43+
| | `y` needs to match the type of this parameter
44+
| `x` and `y` all reference this parameter T
3745
= help: consider casting both fn items to fn pointers using `as fn(isize) -> isize`
3846

3947
error[E0308]: mismatched types
@@ -52,7 +60,11 @@ note: function defined here
5260
--> $DIR/fn-item-type.rs:11:4
5361
|
5462
LL | fn eq<T>(x: T, y: T) {}
55-
| ^^ ----
63+
| ^^ - ---- ----
64+
| | | |
65+
| | | this parameter needs to match the fn item type of `x`
66+
| | `y` needs to match the type of this parameter
67+
| `x` and `y` all reference this parameter T
5668
= help: consider casting both fn items to fn pointers using `as fn(isize) -> isize`
5769

5870
error[E0308]: mismatched types
@@ -71,7 +83,11 @@ note: function defined here
7183
--> $DIR/fn-item-type.rs:11:4
7284
|
7385
LL | fn eq<T>(x: T, y: T) {}
74-
| ^^ ----
86+
| ^^ - ---- ----
87+
| | | |
88+
| | | this parameter needs to match the fn item type of `x`
89+
| | `y` needs to match the type of this parameter
90+
| `x` and `y` all reference this parameter T
7591
= help: consider casting both fn items to fn pointers using `as fn()`
7692

7793
error[E0308]: mismatched types
@@ -90,7 +106,11 @@ note: function defined here
90106
--> $DIR/fn-item-type.rs:11:4
91107
|
92108
LL | fn eq<T>(x: T, y: T) {}
93-
| ^^ ----
109+
| ^^ - ---- ----
110+
| | | |
111+
| | | this parameter needs to match the fn item type of `x`
112+
| | `y` needs to match the type of this parameter
113+
| `x` and `y` all reference this parameter T
94114

95115
error: aborting due to 5 previous errors
96116

tests/ui/mismatched_types/generic-mismatch-reporting-issue-116615.stderr

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ note: function defined here
1111
--> $DIR/generic-mismatch-reporting-issue-116615.rs:1:4
1212
|
1313
LL | fn foo<T>(a: T, b: T) {}
14-
| ^^^ ----
14+
| ^^^ - ---- ----
15+
| | | |
16+
| | | this parameter needs to match the integer type of `a`
17+
| | `b` needs to match the type of this parameter
18+
| `a` and `b` all reference this parameter T
1519

1620
error[E0308]: arguments to this function are incorrect
1721
--> $DIR/generic-mismatch-reporting-issue-116615.rs:8:5

0 commit comments

Comments
 (0)