{"record":{"id":"9e06c619f8895a9d","repo":"rust-lang/rust","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`\n            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`\n            when building from source, or pass `--enable-profiling` to `cargo xtask`\\.","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"warning","filePath":"src/tools/rust-analyzer/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/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs#L116-L152","documentation":"Returned by handle_memory_usage when the running rust-analyzer binary was compiled WITHOUT the `dhat` feature (the #[cfg(not(feature = \"dhat\"))] arm). The memory-profile LSP request can only succeed on a profiling-enabled build; the message tells the user how to rebuild.","triggerScenarios":"A client invokes the rust-analyzer memory profiling/usage request on a stock (non-profiling) build. The cfg-gated arm unconditionally errors with rebuild instructions.","commonSituations":"Using a released rust-analyzer (no dhat feature) and triggering the profiling command from the IDE; building via plain `cargo build` instead of `cargo xtask --enable-profiling`.","solutions":["Rebuild rust-analyzer with profiling: `cargo build -p rust-analyzer --features dhat --profile dev-rel`.","Or use the xtask entry: `cargo xtask --enable-profiling install` (or the documented xtask invocation).","Restart the IDE/extension to point at the rebuilt server binary."],"exampleFix":"// before: cfg-gated unconditional error in the non-dhat arm\n#[cfg(not(feature = \"dhat\"))]\n{ Err(anyhow::anyhow!(\"Memory profiling is not enabled ...\")) }\n\n// after: still error, but include how to verify the feature is active once rebuilt\n#[cfg(not(feature = \"dhat\"))]\n{\n    Err(anyhow::anyhow!(\n        \"Memory profiling is not enabled for this build of rust-analyzer.\\\n         \\n\\nRebuild with `--features dhat --profile dev-rel`, \\\n         then confirm with `rust-analyzer --version` showing the profiling build.\"\n    ))\n}","handlingStrategy":"validation","validationCode":"// Confirm the running binary was built with dhat before offering the profile UI:\nfn profiling_enabled() -> bool {\n    // The dhat feature allocates the global DHAT_PROFILER at startup; alternatively\n    // gate the UI on a known version string produced only by the profiling build.\n    cfg!(feature = \"dhat\") // for the server side; clients should check version metadata\n}","typeGuard":"null","tryCatchPattern":"// Client-side: only expose the memory-profile command when the server advertises it:\nif !server_capabilities.experimental.as_ref().is_some_and(|v| v.get(\"memoryProfile\").is_some()) {\n    return Ok(()); // hide/disable the command\n}\n// then call the request and handle the error by prompting the rebuild steps.","preventionTips":["Build rust-analyzer with --features dhat --profile dev-rel (or via xtask --enable-profiling) when you need profiling.","Have the client hide the profiling command unless the server advertises support.","Document that released builds do not include profiling."],"tags":["rust-analyzer","profiling","build-features","dhat"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}