rust-lang/cargo · error
invalid character `+` in package name: `+{toolchain}` Us
Error message
invalid character `+` in package name: `+{toolchain}`
Use `cargo +{toolchain} update` if you meant to use the `{toolchain}` toolchain. What it means
In `cargo update` (update.rs:74-81), each package name is checked for a leading `+`. A leading `+` is how Cargo selects a toolchain (e.g. `cargo +nightly`), so a package name starting with `+` almost always means the user misplaced the toolchain selector after `update` instead of before `cargo`.
Source
Thrown at src/bin/cargo/commands/update.rs:76
))
}
pub fn exec(gctx: &mut GlobalContext, args: &ArgMatches) -> CliResult {
let mut ws = args.workspace(gctx)?;
if args.is_present_with_zero_values("package") {
print_available_packages(&ws)?;
}
let to_update = if args.contains_id("package") {
"package"
} else {
"package2"
};
let to_update = values(args, to_update);
for crate_name in to_update.iter() {
if let Some(toolchain) = crate_name.strip_prefix("+") {
return Err(anyhow!(
"invalid character `+` in package name: `+{toolchain}`
Use `cargo +{toolchain} update` if you meant to use the `{toolchain}` toolchain."
)
.into());
}
}
let update_opts = UpdateOptions {
recursive: args.flag("recursive"),
precise: args.get_one::<String>("precise").map(String::as_str),
to_update,
dry_run: args.dry_run(),
workspace: args.flag("workspace"),
gctx,
};
if args.flag("breaking") {
gctx.cli_unstable()View on GitHub (pinned to 0e07a15537)
Solutions
- Move the toolchain selector before the subcommand: `cargo +nightly update`.
- If you really have a package whose name starts with `+`, that is not a valid crate name — rename it.
- Remove the `+toolchain` token if you did not intend to override the toolchain.
Example fix
// before $ cargo update +nightly error: invalid character `+` in package name: `+nightly` // after $ cargo +nightly update
Defensive patterns
Strategy: validation
Validate before calling
for name in &packages {
if let Some(rest) = name.strip_prefix('+') {
eprintln!("did you mean `cargo +{rest} update`? moving toolchain before subcommand");
return;
}
} Type guard
fn is_toolchain_misplacement(arg: &str) -> bool {
arg.starts_with('+') && arg[1..].chars().all(|c| c.is_alphanumeric() || c == '-')
}
Prevention
- Remember rustup toolchain order: `cargo +<toolchain> <subcommand>`.
- Validate package args don't start with '+' before passing to cargo.
When it happens
Trigger: Running `cargo update +nightly` (toolchain after the subcommand) instead of `cargo +nightly update`. The `+nightly` is interpreted as a package name and fails this check.
Common situations: Confusing toolchain-selector argument order; scripts that append `+toolchain` to the wrong position; copying rustup examples incorrectly.
Related errors
- invalid character `+` in dependency name: `+{toolchain}`
- invalid character `+` in package name: `+{toolchain}` Us
- argument for --color must be auto, always, or never, but fou
- subcommand is required, add a subcommand to the command alia
- alias {} has unresolvable recursive definition: {} -> {}
AI-assisted analysis of rust-lang/cargo@0e07a15537 (2026-08-06).
Data as JSON: /data/errors/32deb7e5dfcf6a20.json.
Report an issue: GitHub.