rust-lang/rust · warning · anyhow::Error
Memory profiling is not enabled for this build of rust-analy
Error message
Memory profiling is not enabled for this build of rust-analyzer.
To 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`. What it means
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.
Source
Thrown at src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs:134
.status(file_id)
.unwrap_or_else(|_| "Analysis retrieval was cancelled".to_owned()),
);
buf.push_str("\nVersion: \n");
format_to!(buf, "{}", crate::version());
buf.push_str("\nConfiguration: \n");
format_to!(buf, "{:#?}", snap.config);
Ok(buf)
}
pub(crate) fn handle_memory_usage(_state: &mut GlobalState, _: ()) -> anyhow::Result<String> {
let _p = tracing::info_span!("handle_memory_usage").entered();
#[cfg(not(feature = "dhat"))]
{
Err(anyhow::anyhow!(
"Memory profiling is not enabled for this build of rust-analyzer.\n\n\
To 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`."
))
}
#[cfg(feature = "dhat")]
{
if let Some(dhat_output_file) = _state.config.dhat_output_file() {
let mut profiler = crate::DHAT_PROFILER.lock().unwrap();
let old_profiler = profiler.take();
// Need to drop the old profiler before creating a new one.
drop(old_profiler);
*profiler = Some(dhat::Profiler::builder().file_name(&dhat_output_file).build());
Ok(format!(
"Memory profile was saved successfully to {dhat_output_file}.\n\n\
See https://docs.rs/dhat/latest/dhat/#viewing for how to inspect the profile."
))
} else {View on GitHub (pinned to 7088e4b63a)
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.
Example fix
// before: cfg-gated unconditional error in the non-dhat arm
#[cfg(not(feature = "dhat"))]
{ Err(anyhow::anyhow!("Memory profiling is not enabled ...")) }
// after: still error, but include how to verify the feature is active once rebuilt
#[cfg(not(feature = "dhat"))]
{
Err(anyhow::anyhow!(
"Memory profiling is not enabled for this build of rust-analyzer.\
\n\nRebuild with `--features dhat --profile dev-rel`, \
then confirm with `rust-analyzer --version` showing the profiling build."
))
} Defensive patterns
Strategy: validation
Validate before calling
// Confirm the running binary was built with dhat before offering the profile UI:
fn profiling_enabled() -> bool {
// The dhat feature allocates the global DHAT_PROFILER at startup; alternatively
// gate the UI on a known version string produced only by the profiling build.
cfg!(feature = "dhat") // for the server side; clients should check version metadata
} Type guard
null
Try / catch
// Client-side: only expose the memory-profile command when the server advertises it:
if !server_capabilities.experimental.as_ref().is_some_and(|v| v.get("memoryProfile").is_some()) {
return Ok(()); // hide/disable the command
}
// then call the request and handle the error by prompting the rebuild steps. Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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`.
Related errors
- Please set `rust-analyzer.profiling.memoryProfile` to the pa
- rust-analyzer analysis-stats produced no pgo files. This is
- rust-analyzer Language Server is not available. Please, ensu
- Failed to execute ${path} --version.
- bootstrap error. See the logs in "OUTPUT > Rust Analyzer Cli
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/9e06c619f8895a9d.
Report an issue: GitHub.