denoland/deno · error · syn::Error
The flags for this attribute were not sorted alphabetically.
Error message
The flags for this attribute were not sorted alphabetically.
What it means
The op2 macro parses its attribute flags and then checks `passed_flags.is_sorted()` in libs/ops/op2/config.rs. This is a style-enforcement error: all flags inside one `#[op2(...)]` (fast, nofast, getter, setter, lazy/async, reentrant, stack_trace, required, rename, symbol, promise_id, validate(...), etc.) must be written in alphabetical order so attributes stay consistent and searchable across the codebase.
Source
Thrown at libs/ops/op2/config.rs:146
Flags::Required(req) => config.required = Some(*req),
Flags::Rename(rename) => config.rename = Some(rename.clone()),
Flags::Symbol(symbol) => {
config.rename = Some(symbol.clone());
config.symbol = true;
}
Flags::PromiseId => config.promise_id = true,
Flags::Validate(path) => {
config.validate = Some(path.0.clone());
}
}
passed_flags.push(flag);
}
// Ensure that the flags are sorted in alphabetical order for consistency and searchability
if !passed_flags.is_sorted() {
return Err(
syn::Error::new(
span,
"The flags for this attribute were not sorted alphabetically.",
)
.into(),
);
}
// Test for invalid attribute combinations
if config.fast && config.nofast {
return Err(Op2Error::with_span(
span,
Op2ErrorKind::InvalidAttributeCombination("fast", "nofast"),
));
}
if config.fast && config.fast_alternative.is_some() {
return Err(Op2Error::with_span(
span,
Op2ErrorKind::InvalidAttributeCombination("fast", "fast(...)"),View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Alphabetically sort the flags inside the `#[op2(...)]` parentheses; compare flag names as written (e.g. `fast` < `getter` < `nofast`).
- Remember the check runs over every flag in one attribute, including argument-taking ones like `validate(path)` and `rename("x")` — sort by the flag's identifier.
- Run `cargo check` after touching op attributes; this is compile-time only and costs nothing at runtime.
Example fix
// before
#[op2(nofast, fast)]
fn op_do_thing() -> OpId { /* ... */ }
// after
#[op2(fast, nofast)]
fn op_do_thing() -> OpId { /* ... */ } Defensive patterns
Strategy: validation
Validate before calling
// CI/editor guard: op2 flag lists must be sorted. Example shell check: // grep -rnoE '#\[op2\([^)]*\)\]' src/ | ... verify comma-separated flags are ascending. // Cheapest reliable validation is `cargo check` in CI — the macro enforces it deterministically.
Prevention
- When adding a flag to an `#[op2(...)]` attribute, insert it in alphabetical position rather than appending.
- Sort flags by their literal spelling (e.g. `fast` before `getter` before `nofast`).
When it happens
Trigger: Writing an op2 attribute whose flag list is out of alphabetical order, e.g. `#[op2(nofast, fast)]` or `#[op2(getter, fast)]`; also triggered inside impl blocks on methods (`#[op2(stack_trace, getter)]`). The error is reported on the whole attribute span, not the specific flag.
Common situations: Appending a new flag to the end of an existing attribute without re-sorting (e.g. adding `fast` after `nofast`); code reviews that reorder flags and silently break the sort invariant.
Related errors
- Only ASCII keys are supported
- expected attribute arguments in parentheses: `{}(...)`
- Expected a function or impl block for #[op2]
- duplicate `default` argument
- duplicate `options` argument
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/b438f172feca1dbd.
Report an issue: GitHub.