rust-lang/rust-analyzer · error · 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
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.
Source
Thrown at 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 e8f7e90aa3)
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.
Example fix
// before cargo build // after cargo build --features dhat --profile dev-rel
Defensive patterns
Strategy: fallback
Validate before calling
// detect a profiling-capable build before calling the request
fn supports_memory_usage(build_features: &[&str]) -> bool {
build_features.contains(&"dhat")
} Try / catch
match request_memory_usage() {
Err(e) if e.to_string().contains("Memory profiling is not enabled") => {
eprintln!("falling back to OS profiler; rebuild with --features dhat for dhat profiles");
spawn_external_profiler() // heaptrack / massif
}
other => other,
} Prevention
- 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.
When it happens
Trigger: Invoking `rust-analyzer/memoryUsage` (e.g. via `Editor: RA Memory Usage` command in VS Code) against a rust-analyzer binary compiled without `--features dhat`.
Common situations: 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.
Related errors
- Please set `rust-analyzer.profiling.memoryProfile` to the pa
- invalid profile longer_than
- invalid profile depth
- profiler already started
- profiler failed to start
AI-assisted analysis of rust-lang/rust-analyzer@e8f7e90aa3 (2026-09-03).
Data as JSON: /api/errors/96894a2e93c73a28.
Report an issue: GitHub.