rust-lang/rust-analyzer · error

missing entry for {ty}: {default} (field {field})

Error message

missing entry for {ty}: {default} (field {field})

What it means

This panic is thrown by the config TOML-to-JSON deserialization layer in rust-analyzer when it encounters a config entry type it does not know how to map into the config tree. The fallback match arm is intentionally unreachable: every supported config value type ('ty') should have a match arm that converts the default value for the given field. Hitting it means a new config type was added to the config schema without extending this match, so the generated/converted default map would be incomplete.

Source

Thrown at crates/rust-analyzer/src/config.rs:4215

                            "path": {
                                "type": "string",
                            },
                            "type": {
                                "type": "string",
                                "enum": ["always", "methods", "sub_items", "variants"],
                                "enumDescriptions": [
                                    "Do not show this item or its methods (if it is a trait) in auto-import completions.",
                                    "Do not show this trait's methods in auto-import completions.",
                                    "Do not show this module's all items in it in auto-import completions.",
                                    "Do not show this enum's variants in auto-import completions."
                                ],
                            },
                        }
                    }
                ]
             }
        },
        _ => panic!("missing entry for {ty}: {default} (field {field})"),
    }

    map.into()
}

fn validate_toml_table(
    known_ptrs: &[&[&'static str]],
    toml: &toml::Table,
    ptr: &mut String,
    error_sink: &mut Vec<(String, toml::de::Error)>,
) {
    let verify = |ptr: &String| known_ptrs.iter().any(|ptrs| ptrs.contains(&ptr.as_str()));

    let l = ptr.len();
    for (k, v) in toml {
        if !ptr.is_empty() {
            ptr.push('_');
        }

View on GitHub (pinned to e8f7e90aa3)

Solutions

  1. Add a match arm for the reported type/default combination in the conversion match in crates/rust-analyzer/src/config.rs
  2. Regenerate or update any codegen-derived config schema so all types are covered (`cargo xtask codegen` if applicable)
  3. Run `cargo test -p rust-analyzer` config tests to confirm the exhaustive match compiles and defaults map correctly

Example fix

// before
        _ => panic!("missing entry for {ty}: {default} (field {field})"),
// after
        (ty @ Flavor::MyNewType, ConfigValue::Bool(default)) => map.insert(field, ty_to_json(ty, *default)),
        _ => panic!("missing entry for {ty}: {default} (field {field})"),
Defensive patterns

Strategy: validation

Validate before calling

// Before relying on converted defaults, assert all config types are covered:
fn validate_config_coverage(entries: &[(Ty, Default)]) {
    for (ty, default, field) in entries {
        assert!(SUPPORTED_TYPES.contains(ty), "unmapped config type {ty:?} for field {field}");
    }
}

Prevention

When it happens

Trigger: Calling the config conversion function with a config field whose declared type (ty) has no arm in the match, e.g. after adding a new variant to the ConfigFlavor/type enum in config.rs but not updating the mapping code, or a mismatch between the declared type and the default value produced by the `set_roots`/default-generation path.

Common situations: Contributors adding a new rust-analyzer config option or a new config value type and forgetting to update the exhaustive match in the TOML table conversion; running `rust-analyzer --print-config` or workspace config loading right after such a change; codegen or manual edits drifting out of sync with the config schema.

Related errors


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