rust-lang/rust · warning · anyhow::Error
Please set `rust-analyzer.profiling.memoryProfile` to the pa
Error message
Please set `rust-analyzer.profiling.memoryProfile` to the path where you want to save the profile.
What it means
Returned by handle_memory_usage in the dhat-enabled arm when the server has no output path configured (config.dhat_output_file() returns None). Even on a profiling build the user must tell rust-analyzer where to write the profile, via the rust-analyzer.profiling.memoryProfile setting.
Source
Thrown at src/tools/rust-analyzer/crates/rust-analyzer/src/handlers/request.rs:153
"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 {
Err(anyhow::anyhow!(
"Please set `rust-analyzer.profiling.memoryProfile` to the path where you want to save the profile."
))
}
}
}
pub(crate) fn handle_view_syntax_tree(
snap: GlobalStateSnapshot,
params: lsp_ext::ViewSyntaxTreeParams,
) -> anyhow::Result<String> {
let _p = tracing::info_span!("handle_view_syntax_tree").entered();
let id = try_default!(from_proto::file_id(&snap, ¶ms.text_document.uri)?);
let res = snap.analysis.view_syntax_tree(id)?;
Ok(res)
}
pub(crate) fn handle_view_hir(
snap: GlobalStateSnapshot,View on GitHub (pinned to 7088e4b63a)
Solutions
- Set rust-analyzer.profiling.memoryProfile to an absolute writable file path in the client/extension settings.
- Ensure the directory portion of that path exists and is writable by the server process.
- Re-trigger the profiling request after saving the setting.
Example fix
// settings.json (VS Code) — before: no setting
{}
// after
{
"rust-analyzer.profiling.memoryProfile": "/home/me/ra-dhat.json"
} Defensive patterns
Strategy: validation
Validate before calling
// Validate the memoryProfile setting is a writable path before sending the request:
fn profile_path_ok(p: &str) -> bool {
let path = std::path::Path::new(p);
path.is_absolute() && path.parent().map(|d| d.exists() && std::fs::metadata(d).map(|m| !m.permissions().readonly()).unwrap_or(false)).unwrap_or(false)
} Type guard
null
Try / catch
match ra.handle_memory_usage() {
Ok(msg) => Ok(msg),
Err(e) if e.to_string().contains("memoryProfile") => {
eprintln!("set rust-analyzer.profiling.memoryProfile to a writable file path, then retry");
Err(e)
}
Err(e) => Err(e),
} Prevention
- Always configure rust-analyzer.profiling.memoryProfile before triggering profiling.
- Use an absolute path in a directory the server can write.
- Re-verify the setting after extension updates in case it was renamed.
When it happens
Trigger: Invoking the memory profiling request on a correctly-built (dhat) rust-analyzer while the client has not set rust-analyzer.profiling.memoryProfile to a writable path.
Common situations: Enabling the profiling command for the first time without configuring the output path; the setting being cleared/renamed after an extension update; pointing at an unwritable directory (handled separately at write time).
Related errors
- Memory profiling is not enabled for this build of rust-analy
- rust-analyzer Language Server is not available. Please, ensu
- Failed to execute ${path} --version.
- rust-analyzer analysis-stats produced no pgo files. This is
- proc-macro-srv-cli needs to be compiled with the `in-rust-tr
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/e109de1369801591.
Report an issue: GitHub.