rust-lang/rust-analyzer · error

attempted to serialize value that set `PERSIST` to false

Error message

attempted to serialize value that set `PERSIST` to false

What it means

A deliberate `unimplemented!()` sentinel in the salsa `Configuration::serialize` impl for `SyntaxContext`: the struct sets `PERSIST = false`, so salsa never persists it to the database and serialization is never expected to be called. Seeing this panic means some code path asked salsa to serialize a `SyntaxContext` even though the configuration declared it non-persistent.

Source

Thrown at crates/span/src/hygiene.rs:122

        }
    }

    // SAFETY: `Self::Fields`, i.e. `SyntaxContextData`, doesn't contain any lifetimes.
    unsafe impl zalsa_struct_::Configuration for SyntaxContext {
        const LOCATION: salsa::plumbing::Location =
            salsa::plumbing::Location { file: file!(), line: line!() };
        const DEBUG_NAME: &'static str = "SyntaxContextData";
        const REVISIONS: std::num::NonZeroUsize = std::num::NonZeroUsize::MAX;
        const PERSIST: bool = false;

        type Fields<'a> = SyntaxContextData;
        type Struct<'a> = SyntaxContext;

        fn serialize<S>(_: &Self::Fields<'_>, _: S) -> Result<S::Ok, S::Error>
        where
            S: zalsa_::serde::Serializer,
        {
            unimplemented!("attempted to serialize value that set `PERSIST` to false")
        }

        fn deserialize<'de, D>(_: D) -> Result<Self::Fields<'static>, D::Error>
        where
            D: zalsa_::serde::Deserializer<'de>,
        {
            unimplemented!("attempted to deserialize value that cannot set `PERSIST` to false");
        }
    }

    impl SyntaxContext {
        pub fn ingredient(zalsa: &zalsa_::Zalsa) -> &zalsa_struct_::IngredientImpl<Self> {
            static CACHE: zalsa_::IngredientCache<zalsa_struct_::IngredientImpl<SyntaxContext>> =
                zalsa_::IngredientCache::new();

            // SAFETY: The ingredient at offset 0 in `JarImpl<SyntaxContext>` has type
            // `IngredientImpl<SyntaxContext>`.
            unsafe { CACHE.get_or_create::<zalsa_struct_::JarImpl<SyntaxContext>, 0>(zalsa) }

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Audit how the serialization request reached a PERSIST=false struct; the caller is misconfigured (e.g. marking a dependent struct as persistent without opting fields out)
  2. If serialization of this type genuinely becomes required, implement a real serializer instead of the `unimplemented!()` stub
  3. Keep PERSIST=false types out of any query inputs/outputs that get serialized by construction
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/span/src/hygiene.rs:122 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03). Data as JSON: /api/errors/62148f569780b6c1. Report an issue: GitHub.