{
  "$type": "site.standard.document",
  "bskyPostRef": {
    "cid": "bafyreibhmna7zhulhf4zpsyehcjvo6z3ualahnhz3acs5f4fcrezmpol7q",
    "uri": "at://did:plc:ivbknywyskln22er3nkssdhl/app.bsky.feed.post/3mgs42ituds72"
  },
  "path": "/t/optional-features-are-part-of-the-crate-the-project-should-say-so/24069#post_1",
  "publishedAt": "2026-03-11T12:55:21.000Z",
  "site": "https://internals.rust-lang.org",
  "textContent": "When a crate defines an optional feature like `mock`, and there's a module behind `#[cfg(feature = \"mock\")]`, that code is part of the crate. It compiles. It’s tested. It’s documented. It’s not an afterthought — it’s intentional.\n\nBut when someone opens the project, that code is often grayed out. The file shows up as “not included in any crates.” Go-to-def doesn’t work. It’s as if it’s not there.\n\nThis isn’t because the code is optional. It’s because the project hasn’t said: _“This feature is meant to be used.”_\n\nWe already have a place for project-local intent: `.cargo/config.toml`. It’s where we set `RUSTFLAGS`, define targets, and configure environment variables. It’s version-controlled, shared, and respected by Cargo, build scripts, and tools.\n\nAnd rust-analyzer already reads from it — whenever it sees `[env]`.\n\nSo it’s natural for it to also express: _“When analyzing this crate, these features are active.”_\n\n\n    # .cargo/config.toml\n    [unstable]\n    rust-analyzer.cargo.features = \"all\"\n\n\nor\n\n\n    [unstable]\n    rust-analyzer.cargo.features = [\"mock\"]\n\n\nThis doesn’t change how `cargo build` works. It doesn’t affect compilation. It just aligns analysis with the project’s intent — the same way `[env]` already does.\n\nNo setup. No terminal tricks. No editor-specific files.\n\nIf a feature exists and is meant to be used, the project should be able to say so — once, clearly, in the same place we already use for project configuration.\n\nWe already have the mechanism. This is just using it.",
  "title": "Optional features are part of the crate — the project should say so"
}