Skip to content

Commit 7e7dfb8

Browse files
committed
fix #101097, avoid infinite loop in fn arguments checking
1 parent 50e5d03 commit 7e7dfb8

File tree

4 files changed

+187
-6
lines changed

4 files changed

+187
-6
lines changed

compiler/rustc_typeck/src/check/fn_ctxt/arg_matrix.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ impl<'tcx> ArgMatrix<'tcx> {
236236
if matches!(c, Compatibility::Compatible) { Some(i) } else { None }
237237
})
238238
.collect();
239-
if compat.len() != 1 {
240-
// this could go into multiple slots, don't bother exploring both
239+
if compat.len() < 1 {
240+
// try to find a cycle even when this could go into multiple slots, see #101097
241241
is_cycle = false;
242242
break;
243243
}

src/test/ui/argument-suggestions/issue-100478.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ LL | fn three_diff(_a: T1, _b: T2, _c: T3) {}
1515
help: provide the arguments
1616
|
1717
LL | three_diff(/* T1 */, T2::new(0), /* T3 */);
18-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1919

2020
error[E0308]: arguments to this function are incorrect
2121
--> $DIR/issue-100478.rs:35:5
@@ -35,7 +35,7 @@ LL | fn four_shuffle(_a: T1, _b: T2, _c: T3, _d: T4) {}
3535
help: did you mean
3636
|
3737
LL | four_shuffle(T1::default(), T2::default(), T3::default(), T4::default());
38-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
38+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3939

4040
error[E0308]: arguments to this function are incorrect
4141
--> $DIR/issue-100478.rs:36:5
@@ -54,7 +54,7 @@ LL | fn four_shuffle(_a: T1, _b: T2, _c: T3, _d: T4) {}
5454
help: swap these arguments
5555
|
5656
LL | four_shuffle(T1::default(), T2::default(), T3::default(), /* T4 */);
57-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5858

5959
error[E0061]: this function takes 8 arguments but 7 arguments were supplied
6060
--> $DIR/issue-100478.rs:47:5
@@ -73,7 +73,7 @@ LL | fn foo(p1: T1, p2: Arc<T2>, p3: T3, p4: Arc<T4>, p5: T5, p6: T6, p7: T7, p8
7373
help: provide the argument
7474
|
7575
LL | foo(p1, /* Arc<T2> */, p3, p4, p5, p6, p7, p8);
76-
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7777

7878
error: aborting due to 4 previous errors
7979

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
struct A;
2+
struct B;
3+
struct C;
4+
struct D;
5+
6+
fn f(
7+
a1: A,
8+
a2: A,
9+
b1: B,
10+
b2: B,
11+
c1: C,
12+
c2: C,
13+
) {}
14+
15+
fn main() {
16+
f(C, A, A, A, B, B, C); //~ ERROR this function takes 6 arguments but 7 arguments were supplied [E0061]
17+
f(C, C, A, A, B, B); //~ ERROR arguments to this function are incorrect [E0308]
18+
f(A, A, D, D, B, B); //~ arguments to this function are incorrect [E0308]
19+
f(C, C, B, B, A, A); //~ arguments to this function are incorrect [E0308]
20+
f(C, C, A, B, A, A); //~ arguments to this function are incorrect [E0308]
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
error[E0061]: this function takes 6 arguments but 7 arguments were supplied
2+
--> $DIR/issue-101097.rs:16:5
3+
|
4+
LL | f(C, A, A, A, B, B, C);
5+
| ^ - - - - expected `C`, found `B`
6+
| | | |
7+
| | | argument of type `A` unexpected
8+
| | expected `B`, found `A`
9+
| expected `A`, found `C`
10+
|
11+
note: function defined here
12+
--> $DIR/issue-101097.rs:6:4
13+
|
14+
LL | fn f(
15+
| ^
16+
LL | a1: A,
17+
| -----
18+
LL | a2: A,
19+
| -----
20+
LL | b1: B,
21+
| -----
22+
LL | b2: B,
23+
| -----
24+
LL | c1: C,
25+
| -----
26+
LL | c2: C,
27+
| -----
28+
help: did you mean
29+
|
30+
LL | f(A, A, B, B, C, C);
31+
| ~~~~~~~~~~~~~~~~~~
32+
33+
error[E0308]: arguments to this function are incorrect
34+
--> $DIR/issue-101097.rs:17:5
35+
|
36+
LL | f(C, C, A, A, B, B);
37+
| ^
38+
|
39+
note: function defined here
40+
--> $DIR/issue-101097.rs:6:4
41+
|
42+
LL | fn f(
43+
| ^
44+
LL | a1: A,
45+
| -----
46+
LL | a2: A,
47+
| -----
48+
LL | b1: B,
49+
| -----
50+
LL | b2: B,
51+
| -----
52+
LL | c1: C,
53+
| -----
54+
LL | c2: C,
55+
| -----
56+
help: did you mean
57+
|
58+
LL | f(A, A, B, B, C, C);
59+
| ~~~~~~~~~~~~~~~~~~
60+
61+
error[E0308]: arguments to this function are incorrect
62+
--> $DIR/issue-101097.rs:18:5
63+
|
64+
LL | f(A, A, D, D, B, B);
65+
| ^ - - ---- two arguments of type `C` and `C` are missing
66+
| | |
67+
| | argument of type `D` unexpected
68+
| argument of type `D` unexpected
69+
|
70+
note: function defined here
71+
--> $DIR/issue-101097.rs:6:4
72+
|
73+
LL | fn f(
74+
| ^
75+
LL | a1: A,
76+
| -----
77+
LL | a2: A,
78+
| -----
79+
LL | b1: B,
80+
| -----
81+
LL | b2: B,
82+
| -----
83+
LL | c1: C,
84+
| -----
85+
LL | c2: C,
86+
| -----
87+
help: did you mean
88+
|
89+
LL | f(A, A, B, B, /* C */, /* C */);
90+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91+
92+
error[E0308]: arguments to this function are incorrect
93+
--> $DIR/issue-101097.rs:19:5
94+
|
95+
LL | f(C, C, B, B, A, A);
96+
| ^ - - - - expected `C`, found `A`
97+
| | | |
98+
| | | expected `C`, found `A`
99+
| | expected `A`, found `C`
100+
| expected `A`, found `C`
101+
|
102+
note: function defined here
103+
--> $DIR/issue-101097.rs:6:4
104+
|
105+
LL | fn f(
106+
| ^
107+
LL | a1: A,
108+
| -----
109+
LL | a2: A,
110+
| -----
111+
LL | b1: B,
112+
| -----
113+
LL | b2: B,
114+
| -----
115+
LL | c1: C,
116+
| -----
117+
LL | c2: C,
118+
| -----
119+
help: did you mean
120+
|
121+
LL | f(A, A, B, B, C, C);
122+
| ~~~~~~~~~~~~~~~~~~
123+
124+
error[E0308]: arguments to this function are incorrect
125+
--> $DIR/issue-101097.rs:20:5
126+
|
127+
LL | f(C, C, A, B, A, A);
128+
| ^ - - - - - expected `C`, found `A`
129+
| | | | |
130+
| | | | expected `C`, found `A`
131+
| | | expected struct `B`, found struct `A`
132+
| | expected `A`, found `C`
133+
| expected `A`, found `C`
134+
|
135+
note: function defined here
136+
--> $DIR/issue-101097.rs:6:4
137+
|
138+
LL | fn f(
139+
| ^
140+
LL | a1: A,
141+
| -----
142+
LL | a2: A,
143+
| -----
144+
LL | b1: B,
145+
| -----
146+
LL | b2: B,
147+
| -----
148+
LL | c1: C,
149+
| -----
150+
LL | c2: C,
151+
| -----
152+
help: did you mean
153+
|
154+
LL | f(A, A, /* B */, B, C, C);
155+
| ~~~~~~~~~~~~~~~~~~~~~~~~
156+
157+
error: aborting due to 5 previous errors
158+
159+
Some errors have detailed explanations: E0061, E0308.
160+
For more information about an error, try `rustc --explain E0061`.

0 commit comments

Comments
 (0)