rust-lang/cargo · error · anyhow::Error
unexpected {btype} bracket `{literal}` in build.build-dir pa
Error message
unexpected {btype} bracket `{literal}` in build.build-dir path `{raw_template}` What it means
Raised in the same `resolve_templated_path` call (src/workspace/workspace.rs:384) when the lockfile-path contains an unmatched/unbalanced brace — `ResolveTemplateError::UnexpectedBracket` with `BracketType::Opening` (`{`) or `Closing` (`}`). The message reports whether the stray character is an opening or closing bracket and shows the raw template. Note the message string hard-codes 'build.build-dir path' even though it fires for `resolver.lockfile-path`.
Source
Thrown at src/workspace/workspace.rs:390
let replacements: [(&str, &str); 0] = [];
let path = lockfile_path
.resolve_templated_path(self.gctx(), replacements)
.map_err(|e| match e {
context::ResolveTemplateError::UnexpectedVariable {
variable,
raw_template,
} => {
anyhow!(
"unexpected variable `{variable}` in resolver.lockfile-path `{raw_template}`"
)
}
context::ResolveTemplateError::UnexpectedBracket { bracket_type, raw_template } => {
let (btype, literal) = match bracket_type {
context::BracketType::Opening => ("opening", "{"),
context::BracketType::Closing => ("closing", "}"),
};
anyhow!(
"unexpected {btype} bracket `{literal}` in build.build-dir path `{raw_template}`"
)
}
})?;
if !path.ends_with(LOCKFILE_NAME) {
bail!("the `resolver.lockfile-path` must be a path to a {LOCKFILE_NAME} file");
}
if path.is_dir() {
bail!(
"`resolver.lockfile-path` `{}` is a directory but expected a file",
path.display()
);
}
self.requested_lockfile_path = Some(path);
}
Ok(())
}View on GitHub (pinned to 0e07a15537)
Solutions
- Balance or remove the stray `{` / `}` in the `resolver.lockfile-path` value.
- If the brace was meant literally (rare), choose a path without brace characters.
- Re-read the raw value from the config file the error references and fix it there.
Example fix
# before
[resolver]
lockfile-path = "${HOME}/Cargo.lock"
# after — use a real path, no shell/brace syntax
[resolver]
lockfile-path = "/home/user/Cargo.lock" Defensive patterns
Strategy: validation
Validate before calling
fn balanced_braces(s: &str) -> bool {
let mut depth = 0i32;
for c in s.chars() { match c { '{' => depth += 1, '}' => { depth -= 1; if depth < 0 { return false; } } _ => {} } }
depth == 0
}
// assert balanced_braces(&lockfile_path) and no stray braces Prevention
- Avoid brace characters in resolver.lockfile-path entirely.
- Do not put shell `${VAR}` syntax into cargo config.
When it happens
Trigger: A `resolver.lockfile-path` value containing a lone `{` or `}` (e.g. `"{Cargo.lock"`, `"dir/}x"`, or a literal brace intended as a filename).
Common situations: Hand-editing config and leaving an unclosed brace; pasting a Windows path with brace characters; an editor auto-inserting a closing brace in the wrong place; shell variable leftovers like `${HOME}/Cargo.lock`.
Related errors
- unexpected variable `{variable}` in resolver.lockfile-path `
- unexpected {btype} bracket `{literal}` in build.build-dir pa
- subcommand is required, add a subcommand to the command alia
- alias {} has unresolvable recursive definition: {} -> {}
- subcommand is required, but `{alias_name}` is empty
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/dcf04f996d6ef87f.json.
Report an issue: GitHub.