rwf2/Rocket · error · rocket_codegen::param::Error
BadIdent
BadIdent
Error message
invalid identifier
What it means
Compile-time error from Rocket's codegen: the name inside a dynamic route parameter <name> is not a valid Rust identifier (is_valid_ident failed), so Rocket cannot generate a binding for it. The name must be a valid identifier because it is used to match against a function argument in the generated code. The error span covers just the offending name inside the brackets.
Source
Thrown at core/codegen/src/attribute/param/parse.rs:63
segment: &str,
source_span: Span,
) -> Result<Self, Error<'_>> {
let mut trailing = false;
// Check if this is a dynamic param. If so, check its well-formedness.
let lint = Lint::SegmentChars;
if segment.starts_with('<') && segment.ends_with('>') {
let mut name = &segment[1..(segment.len() - 1)];
if name.ends_with("..") {
trailing = true;
name = &name[..(name.len() - 2)];
}
let span = subspan(name, segment, source_span);
if name.is_empty() {
return Err(Error::new(name, source_span, ErrorKind::Empty));
} else if !is_valid_ident(name) {
return Err(Error::new(name, span, ErrorKind::BadIdent));
}
let dynamic = Dynamic { name: Name::new(name, span), trailing, index: 0 };
if dynamic.is_wild() && P::KIND != Kind::Path {
return Err(Error::new(name, span, ErrorKind::Ignored));
} else if dynamic.is_wild() {
return Ok(Parameter::Ignored(dynamic));
} else {
return Ok(Parameter::Dynamic(dynamic));
}
} else if segment.is_empty() {
return Err(Error::new(segment, source_span, ErrorKind::Empty));
} else if segment.starts_with('<') && lint.enabled(source_span) {
let candidate = candidate_from_malformed(segment);
source_span.warning("`segment` starts with `<` but does not end with `>`")
.help(format!("perhaps you meant the dynamic parameter `<{}>`?", candidate))
.note(lint.how_to_suppress())
.emit_as_item_tokens();View on GitHub (pinned to 3a54d079ae)
Solutions
- Rename the parameter to a valid snake_case Rust identifier: <user_id> instead of <user-id>
- Keep the pretty URL only if you don't need the value; otherwise map it in the handler, since the parameter name must equal the function argument name
- Check for stray characters (spaces, unicode dashes) if the name looks valid
Example fix
// before
#[get("/users/<user-id>")]
fn user(user_id: &str) { }
// after
#[get("/users/<user_id>")]
fn user(user_id: &str) { } Defensive patterns
Strategy: validation
Prevention
- Use snake_case for route parameter names; keep kebab-case only in static path text
- Parameter name must equal the handler argument name
- cargo check after renaming path segments
When it happens
Trigger: Route parameters containing hyphens, leading digits, spaces, or other non-ident characters: #[get("/<user-id>")], #[get("/<0id>")], #[get("/<user id..>")].
Common situations: Mirroring URL naming (kebab-case) into the parameter name instead of the function argument; renaming a path segment for SEO without updating the parameter; typos inserting invisible characters or spaces.
Related errors
AI-assisted analysis of rwf2/Rocket@3a54d079ae (2026-08-16).
Data as JSON: /api/errors/e5fa9c3521ccc498.
Report an issue: GitHub.