File: 101557.rs

package info (click to toggle)
rustc 1.85.0%2Bdfsg3-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental, sid, trixie
  • size: 893,396 kB
  • sloc: xml: 158,127; python: 35,830; javascript: 19,497; cpp: 19,002; sh: 17,245; ansic: 13,127; asm: 4,376; makefile: 1,051; perl: 29; lisp: 29; ruby: 19; sql: 11
file content (42 lines) | stat: -rw-r--r-- 731 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
//@ known-bug: #101557
//@ compile-flags: -Copt-level=0
#![feature(generic_const_exprs)]
use std::marker::PhantomData;

trait Trait {
    const CONST: usize;
}

struct A<T: Trait> {
    _marker: PhantomData<T>,
}

impl<const N: usize> Trait for [i8; N] {
    const CONST: usize = N;
}

impl<const N: usize> From<usize> for A<[i8; N]> {
    fn from(_: usize) -> Self {
        todo!()
    }
}

impl<T: Trait> From<A<[i8; T::CONST]>> for A<T> {
    fn from(_: A<[i8; T::CONST]>) -> Self {
        todo!()
    }
}

fn f<T: Trait>() -> A<T>
where
    [(); T::CONST]:,
{
    // Usage of `0` is arbitrary
    let a = A::<[i8; T::CONST]>::from(0);
    A::<T>::from(a)
}

fn main() {
    // Usage of `1` is arbitrary
    f::<[i8; 1]>();
}