Skip to content

Commit 046f70a

Browse files
authored
Create 2021-03-23-ct-in-where-bounds.md
1 parent 466f1ba commit 046f70a

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# cg meeting 2021-03-23 ([zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/meeting.202021-03-23))
2+
3+
## Consts in `where`-bounds
4+
5+
```rust
6+
fn foo<T: Trait>() where [u8; <T as Trait>::ASSOC]: OtherTrait {}
7+
```
8+
9+
Help, our `where`-bounds don't hold:
10+
11+
### ICE example
12+
13+
(first discussed in https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/anon.20const.20in.20where.20bounds )
14+
15+
Core example is:
16+
17+
```rust
18+
trait Foo {
19+
type Assoc;
20+
}
21+
const fn bar<T>()
22+
where
23+
T: Foo<Assoc = T>,
24+
{
25+
...
26+
}
27+
fn fun1<T>
28+
where
29+
T: Foo<Assoc = T>,
30+
[u8; bar::<T>()]: Sized,
31+
{}
32+
impl Foo for i32 {
33+
type Assoc = u32;
34+
}
35+
fn main() {
36+
fun1::<i32>();
37+
}
38+
```
39+
40+
* The problem here is that when you call `fun1::<i32>` you wind up with this unevaluated constant `bar::<T>()`.
41+
* We type-check that constant when type-checking `fun1` and determine that the source code is well-typed, under the assumption that `T: Foo<Assoc = T>`
42+
* But in the body of `main` we get two distinct things to prove:
43+
* `i32: Foo<Assoc = i32>` — unprovable
44+
* `[u8; bar::<i32>()]: Sized` — no longer well typed
45+
* The current code considers them independently and may well ICE when evaluating the second one (not probably in this particular example) because it assumed that the body of a constant is well typed when evaluating.
46+
47+
### Possible solutions
48+
49+
- don't assume substituted anon consts to be well typed
50+
- dangerous, may hide actual bugs
51+
- change typeck to not evaluate constants before proving there `where`-bounds
52+
- difficult to implement
53+
54+
:shrug:

0 commit comments

Comments
 (0)