Skip to content

Commit a8a7eed

Browse files
committed
Add regression test
1 parent d2a60ad commit a8a7eed

File tree

2 files changed

+76
-0
lines changed

2 files changed

+76
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(generic_const_exprs, type_alias_impl_trait)]
2+
#![allow(incomplete_features)]
3+
4+
type Foo = impl Sized;
5+
//~^ ERROR: cycle detected
6+
7+
fn with_bound<const N: usize>() -> Foo
8+
where
9+
[u8; (N / 2) as usize]: Sized,
10+
{
11+
let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
12+
//~^ ERROR: mismatched types
13+
todo!()
14+
}
15+
16+
fn main() {
17+
with_bound::<4>();
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
error[E0391]: cycle detected when computing type of `Foo::{opaque#0}`
2+
--> $DIR/opaque_type.rs:4:12
3+
|
4+
LL | type Foo = impl Sized;
5+
| ^^^^^^^^^^
6+
|
7+
note: ...which requires computing type of opaque `Foo::{opaque#0}`...
8+
--> $DIR/opaque_type.rs:4:12
9+
|
10+
LL | type Foo = impl Sized;
11+
| ^^^^^^^^^^
12+
note: ...which requires type-checking `with_bound`...
13+
--> $DIR/opaque_type.rs:11:35
14+
|
15+
LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
16+
| ^^^^^^^^^^^^^^^^^^^^^
17+
note: ...which requires evaluating type-level constant...
18+
--> $DIR/opaque_type.rs:11:17
19+
|
20+
LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
21+
| ^^^^^^^^^^^^^^
22+
note: ...which requires const-evaluating + checking `with_bound::{constant#1}`...
23+
--> $DIR/opaque_type.rs:11:17
24+
|
25+
LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
26+
| ^^^^^^^^^^^^^^
27+
note: ...which requires caching mir of `with_bound::{constant#1}` for CTFE...
28+
--> $DIR/opaque_type.rs:11:17
29+
|
30+
LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
31+
| ^^^^^^^^^^^^^^
32+
note: ...which requires elaborating drops for `with_bound::{constant#1}`...
33+
--> $DIR/opaque_type.rs:11:17
34+
|
35+
LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
36+
| ^^^^^^^^^^^^^^
37+
= note: ...which requires normalizing `Foo`...
38+
= note: ...which again requires computing type of `Foo::{opaque#0}`, completing the cycle
39+
note: cycle used when checking that `Foo::{opaque#0}` is well-formed
40+
--> $DIR/opaque_type.rs:4:12
41+
|
42+
LL | type Foo = impl Sized;
43+
| ^^^^^^^^^^
44+
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
45+
46+
error[E0308]: mismatched types
47+
--> $DIR/opaque_type.rs:11:35
48+
|
49+
LL | let _: [u8; (N / 2) as Foo] = [0; (N / 2) as usize];
50+
| ^^^^^^^^^^^^^^^^^^^^^ expected `(N / 2) as Foo`, found `(N / 2) as usize`
51+
|
52+
= note: expected constant `(N / 2) as Foo`
53+
found constant `(N / 2) as usize`
54+
55+
error: aborting due to 2 previous errors
56+
57+
Some errors have detailed explanations: E0308, E0391.
58+
For more information about an error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)