serde-rs / serde

Serialization framework for Rust
https://serde.rs/
Apache License 2.0
9.15k stars 773 forks source link

generic `Self` types are currently not permitted in anonymous constants #2820

Open Dushistov opened 2 months ago

Dushistov commented 2 months ago

Code bellow cause compilation error:

error: generic `Self` types are currently not permitted in anonymous constants
  --> src/main.rs:15:27
   |
15 |     pub id: ArrayString<{ Self::FIX_ID_MAX_LEN }>,
   |                           ^^^^
   |
note: not a concrete type

Without #[derive(Deserialize)] it compiled and work just fine.

use arrayvec::ArrayString;
use serde::Deserialize;

#[derive(Deserialize)]
pub struct Foo {
    pub id: ArrayString<{ Self::FIX_ID_MAX_LEN }>,
}

impl Foo {
    pub const FIX_ID_MAX_LEN: usize = 20;
}

serde 1.0.210, rustc 1.82.0-beta.1, arrayvec 0.7.6

appetrosyan commented 1 month ago

Can confirm.

Related upstream issue in Rust

https://github.com/rust-lang/rust/issues/68436