rodrimati1992 / tstr_crates

Type-level strings
zlib License
9 stars 1 forks source link

tstr with `const_generics` doesn't compile #5

Open nwalfield opened 7 months ago

nwalfield commented 7 months ago

I'm trying to use StrValue. This requires enabling const_generics. Unfortunately, when I enable that feature, tstr doesn't compile any more:

$ rustc --version
rustc 1.76.0 (07dca489a 2024-02-04)
$ cargo build
   Compiling tstr v0.2.3
error: `&'static str` is forbidden as the type of a const generic parameter
  --> /home/us/.cargo/registry/src/index.crates.io-6f17d22bba15001f/tstr-0.2.3/src/./p.rs:40:33
   |
40 |         pub struct ___<const S: &'static str>;
   |                                 ^^^^^^^^^^^^
...
52 | declare_const_items! {}
   | ----------------------- in this macro invocation
   |
   = note: the only supported types are integers, `bool` and `char`
   = note: this error originates in the macro `declare_const_items` (in Nightly builds, run with -Z macro-backtrace for more info)
...

I'm using an empty project created by cargo init and just add the following to Cargo.toml:

tstr = { version = "0.2", features = ["const_generics"] }

I tried compiling with rustc version 1.46, which I think should be supported, but I got the same error (I had to also change the edition to 2018). As such, I think I'm probably holding it wrong, and my request is to improve the documentation.

Thanks!

rodrimati1992 commented 7 months ago

You'll need to enable the "nightly_const_generics" feature, because the "const_generics" feature is for whenever &'static str is made usable as a const parameter on stable. (It has separate "nightly_const_generics" and "const_generics" features so that I don't have to update the library whenever &'static str const parameter support is stabilized)

The StrValue trait currently requires a nightly compiler, because I don't believe there's any way to make the &'static str associated constant on stable (in a way that works for any string).

nwalfield commented 7 months ago

Got it, thanks!

nwalfield commented 7 months ago

I think I was confused, because there is also a nightly_const_generics feature so I assumed that the const_generics feature would work with the stable compiler.