Skip to content

Commit 3ad6fed

Browse files
authored
Rollup merge of #74991 - JulianKnodt:74199, r=lcnr
Fix Const-Generic Cycle ICE #74199 This PR intends to fix the bug in Issue #74199 by following the suggestion provided of ignoring the error that causes the ICE. This does not fix the underlying cycle detection issue, but fixes the ICE. Also adds a test to check that it doesn't causes an ICE but returns a valid error for now. r? @lcnr Edit: Also it's funny how this PR number is an anagram of the issue number
2 parents ff5ccc8 + 96b5dee commit 3ad6fed

File tree

3 files changed

+178
-0
lines changed

3 files changed

+178
-0
lines changed

src/librustc_typeck/variance/constraints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
161161
self.add_constraints_from_sig(current_item, tcx.fn_sig(def_id), self.covariant);
162162
}
163163

164+
ty::Error(_) => {}
164165
_ => {
165166
span_bug!(
166167
tcx.def_span(def_id),
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(const_generics)]
2+
#![allow(incomplete_features)]
3+
4+
struct Foo<const N: [u8; {
5+
//~^ ERROR cycle detected
6+
//~| ERROR cycle detected
7+
struct Foo<const N: usize>;
8+
9+
impl<const N: usize> Foo<N> {
10+
fn value() -> usize {
11+
N
12+
}
13+
}
14+
15+
Foo::<17>::value()
16+
}]>;
17+
18+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
error[E0391]: cycle detected when computing type of `Foo`
2+
--> $DIR/nested-type.rs:4:1
3+
|
4+
LL | struct Foo<const N: [u8; {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: ...which requires computing type of `Foo::N`...
8+
--> $DIR/nested-type.rs:4:18
9+
|
10+
LL | struct Foo<const N: [u8; {
11+
| ^
12+
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
13+
--> $DIR/nested-type.rs:4:26
14+
|
15+
LL | struct Foo<const N: [u8; {
16+
| __________________________^
17+
LL | |
18+
LL | |
19+
LL | | struct Foo<const N: usize>;
20+
... |
21+
LL | | Foo::<17>::value()
22+
LL | | }]>;
23+
| |_^
24+
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
25+
--> $DIR/nested-type.rs:4:26
26+
|
27+
LL | struct Foo<const N: [u8; {
28+
| __________________________^
29+
LL | |
30+
LL | |
31+
LL | | struct Foo<const N: usize>;
32+
... |
33+
LL | | Foo::<17>::value()
34+
LL | | }]>;
35+
| |_^
36+
note: ...which requires const-evaluating `Foo::{{constant}}#0`...
37+
--> $DIR/nested-type.rs:4:26
38+
|
39+
LL | struct Foo<const N: [u8; {
40+
| __________________________^
41+
LL | |
42+
LL | |
43+
LL | | struct Foo<const N: usize>;
44+
... |
45+
LL | | Foo::<17>::value()
46+
LL | | }]>;
47+
| |_^
48+
note: ...which requires type-checking `Foo::{{constant}}#0`...
49+
--> $DIR/nested-type.rs:4:26
50+
|
51+
LL | struct Foo<const N: [u8; {
52+
| __________________________^
53+
LL | |
54+
LL | |
55+
LL | | struct Foo<const N: usize>;
56+
... |
57+
LL | | Foo::<17>::value()
58+
LL | | }]>;
59+
| |_^
60+
note: ...which requires computing the variances of `Foo::{{constant}}#0::Foo`...
61+
--> $DIR/nested-type.rs:7:5
62+
|
63+
LL | struct Foo<const N: usize>;
64+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
65+
= note: ...which requires computing the variances for items in this crate...
66+
= note: ...which again requires computing type of `Foo`, completing the cycle
67+
note: cycle used when collecting item types in top-level module
68+
--> $DIR/nested-type.rs:1:1
69+
|
70+
LL | / #![feature(const_generics)]
71+
LL | | #![allow(incomplete_features)]
72+
LL | |
73+
LL | | struct Foo<const N: [u8; {
74+
... |
75+
LL | |
76+
LL | | fn main() {}
77+
| |____________^
78+
79+
error[E0391]: cycle detected when computing type of `Foo`
80+
--> $DIR/nested-type.rs:4:1
81+
|
82+
LL | struct Foo<const N: [u8; {
83+
| ^^^^^^^^^^^^^^^^^^^^^^^^
84+
|
85+
note: ...which requires computing type of `Foo::N`...
86+
--> $DIR/nested-type.rs:4:18
87+
|
88+
LL | struct Foo<const N: [u8; {
89+
| ^
90+
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
91+
--> $DIR/nested-type.rs:4:26
92+
|
93+
LL | struct Foo<const N: [u8; {
94+
| __________________________^
95+
LL | |
96+
LL | |
97+
LL | | struct Foo<const N: usize>;
98+
... |
99+
LL | | Foo::<17>::value()
100+
LL | | }]>;
101+
| |_^
102+
note: ...which requires const-evaluating + checking `Foo::{{constant}}#0`...
103+
--> $DIR/nested-type.rs:4:26
104+
|
105+
LL | struct Foo<const N: [u8; {
106+
| __________________________^
107+
LL | |
108+
LL | |
109+
LL | | struct Foo<const N: usize>;
110+
... |
111+
LL | | Foo::<17>::value()
112+
LL | | }]>;
113+
| |_^
114+
note: ...which requires const-evaluating `Foo::{{constant}}#0`...
115+
--> $DIR/nested-type.rs:4:26
116+
|
117+
LL | struct Foo<const N: [u8; {
118+
| __________________________^
119+
LL | |
120+
LL | |
121+
LL | | struct Foo<const N: usize>;
122+
... |
123+
LL | | Foo::<17>::value()
124+
LL | | }]>;
125+
| |_^
126+
note: ...which requires type-checking `Foo::{{constant}}#0`...
127+
--> $DIR/nested-type.rs:4:26
128+
|
129+
LL | struct Foo<const N: [u8; {
130+
| __________________________^
131+
LL | |
132+
LL | |
133+
LL | | struct Foo<const N: usize>;
134+
... |
135+
LL | | Foo::<17>::value()
136+
LL | | }]>;
137+
| |_^
138+
note: ...which requires computing the variances of `Foo::{{constant}}#0::Foo`...
139+
--> $DIR/nested-type.rs:7:5
140+
|
141+
LL | struct Foo<const N: usize>;
142+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
143+
= note: ...which requires computing the variances for items in this crate...
144+
= note: ...which again requires computing type of `Foo`, completing the cycle
145+
note: cycle used when collecting item types in top-level module
146+
--> $DIR/nested-type.rs:1:1
147+
|
148+
LL | / #![feature(const_generics)]
149+
LL | | #![allow(incomplete_features)]
150+
LL | |
151+
LL | | struct Foo<const N: [u8; {
152+
... |
153+
LL | |
154+
LL | | fn main() {}
155+
| |____________^
156+
157+
error: aborting due to 2 previous errors
158+
159+
For more information about this error, try `rustc --explain E0391`.

0 commit comments

Comments
 (0)