`slow const evaluation` when iterating over [&str] slices

⚓ Rust    📅 2025-09-07    👤 surdeus    👁️ 3      

surdeus

Was trying to find a way to get to the index of an element in a slice at compile time. First attempt:

pointer arithmetic (click for more details)

Building this on both my own machine and in the cloud hangs for a ridiculously long time:

   Compiling playground v0.0.1 (/playground)
error: constant evaluation is taking a long time

Researching a bit further brought me to the message by @H2CO3 as well as the recently stabilized str::eq_ignore_ascii_case in the rustc 1.89. By combining the two:

pattern matching (click for more details)

The compilation returns back to instant. Yet I can't wrap my head around as to why it is so slow, in the first place. How is the pattern matching version so much faster than plain old pointer arithmetic?


Digging some more lead me to const_str as well. Good to know, for future reference.

3 posts - 2 participants

Read full topic

🏷️ Rust_feed