{"record":{"id":"96894a2e93c73a28","repo":"rust-lang/rust-analyzer","slug":"memory-profiling-is-not-enabled-for-this-build-of","errorCode":null,"errorMessage":"Memory profiling is not enabled for this build of rust-analyzer.\n\nTo build rust-analyzer with profiling support, pass `--features dhat --profile dev-rel` to `cargo build` when building from source, or pass `--enable-profiling` to `cargo xtask`.","messagePattern":"Memory profiling is not enabled for this build of rust-analyzer\\.\n\nTo build rust-analyzer with profiling support, pass `--features dhat --profile dev-rel` to `cargo build` when building from source, or pass `--enable-profiling` to `cargo xtask`\\.","errorType":"error_code","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/rust-analyzer/src/handlers/request.rs","lineNumber":134,"sourceCode":"            .status(file_id)\n            .unwrap_or_else(|_| \"Analysis retrieval was cancelled\".to_owned()),\n    );\n\n    buf.push_str(\"\\nVersion: \\n\");\n    format_to!(buf, \"{}\", crate::version());\n\n    buf.push_str(\"\\nConfiguration: \\n\");\n    format_to!(buf, \"{:#?}\", snap.config);\n\n    Ok(buf)\n}\n\npub(crate) fn handle_memory_usage(_state: &mut GlobalState, _: ()) -> anyhow::Result<String> {\n    let _p = tracing::info_span!(\"handle_memory_usage\").entered();\n\n    #[cfg(not(feature = \"dhat\"))]\n    {\n        Err(anyhow::anyhow!(\n            \"Memory profiling is not enabled for this build of rust-analyzer.\\n\\n\\\n            To build rust-analyzer with profiling support, pass `--features dhat --profile dev-rel` to `cargo build`\n            when building from source, or pass `--enable-profiling` to `cargo xtask`.\"\n        ))\n    }\n    #[cfg(feature = \"dhat\")]\n    {\n        if let Some(dhat_output_file) = _state.config.dhat_output_file() {\n            let mut profiler = crate::DHAT_PROFILER.lock().unwrap();\n            let old_profiler = profiler.take();\n            // Need to drop the old profiler before creating a new one.\n            drop(old_profiler);\n            *profiler = Some(dhat::Profiler::builder().file_name(&dhat_output_file).build());\n            Ok(format!(\n                \"Memory profile was saved successfully to {dhat_output_file}.\\n\\n\\\n                See https://docs.rs/dhat/latest/dhat/#viewing for how to inspect the profile.\"\n            ))\n        } else {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/rust-lang/rust-analyzer/blob/e8f7e90aa3e7b26aa9a000200f606c1078da99ec/crates/rust-analyzer/src/handlers/request.rs#L116-L152","documentation":"The `rust-analyzer/memoryUsage` LSP request (`handle_memory_usage`) requires the `dhat` cargo feature. When the running binary was built without it, the handler returns this error explaining exactly how to rebuild with profiling support. It is a deliberate, documented build-configuration guard, not a bug.","triggerScenarios":"Invoking `rust-analyzer/memoryUsage` (e.g. via `Editor: RA Memory Usage` command in VS Code) against a rust-analyzer binary compiled without `--features dhat`.","commonSituations":"Developers profiling rust-analyzer's heap usage from a distro- or marketplace-supplied binary that was not built with profiling; CI binaries and default builds also lack the feature.","solutions":["Rebuild from source with `cargo build --features dhat --profile dev-rel` (inside rust-analyzer's repo).","Or build via `cargo xtask --enable-profiling install`.","Point the editor at the newly built binary and retry the memoryUsage request.","If profiling isn't actually needed, use an OS-level tool (heaptrack, valgrind/massif) instead of this request."],"exampleFix":"// before\ncargo build\n\n// after\ncargo build --features dhat --profile dev-rel","handlingStrategy":"fallback","validationCode":"// detect a profiling-capable build before calling the request\nfn supports_memory_usage(build_features: &[&str]) -> bool {\n    build_features.contains(&\"dhat\")\n}","typeGuard":null,"tryCatchPattern":"match request_memory_usage() {\n    Err(e) if e.to_string().contains(\"Memory profiling is not enabled\") => {\n        eprintln!(\"falling back to OS profiler; rebuild with --features dhat for dhat profiles\");\n        spawn_external_profiler() // heaptrack / massif\n    }\n    other => other,\n}","preventionTips":["For profiling sessions, build rust-analyzer with `cargo xtask --enable-profiling install`.","Check the server's feature set (or docs) before exposing profiling UI commands.","Keep an OS-level heap profiler available as a fallback."],"tags":["rust-analyzer","feature-flag","profiling","build-config"],"backgroundTag":"feature-not-enabled","analyzedSha":"e8f7e90aa3e7b26aa9a000200f606c1078da99ec","analyzedAt":"2026-09-03T21:08:06.959Z","contentChangedAt":"2026-09-03T21:08:06.959Z","schemaVersion":2},"datasetVersion":"2026-09-11T07:07:21.782Z"}