actix/actix-web · error · syn::Error
missing arguments for scope macro, expected…
Error message
missing arguments for scope macro, expected: #[scope("/prefix")] What it means
This compile-time error fires when the `#[scope("...")]` macro is used without any arguments at all (i.e., `#[scope]` with empty parentheses or no parentheses). The macro checks `args.is_empty()` at line 18 and requires a string literal prefix argument.
Solutions
- Provide a string literal path prefix: `#[scope("/api")]`
- If you don't need a path prefix, consider whether the scope macro is needed at all
- Ensure the argument is inside the parentheses: `#[scope("/api")]` not `#[scope] "/api"`
Example fix
// before
#[scope]
mod api { ... }
// after
#[scope("/api")]
mod api { ... } Defensive patterns
Strategy: type-guard
Type guard
// Compile-time error. Always provide a string literal argument:
// #[scope("/api")] — correct
// #[scope] — incorrect (missing argument)
// #[scope()] — incorrect (empty argument) Prevention
- Always include a string literal path prefix in #[scope("/prefix")]
- Follow the actix-web scope macro examples from the documentation
- Run cargo check after adding #[scope] to catch missing arguments
When it happens
Trigger: Writing `#[scope]` or `#[scope()]` on a module. The macro expects the form `#[scope("/prefix")]` with a non-empty string literal argument.
Common situations: Developers who add `#[scope]` without reading the docs, or who delete the path argument during editing and forget to restore it.
Related errors
- argument to scope macro is not a string literal, expected…
- #[scope] macro must be attached to a module
- scopes should not have trailing slashes; see…
- invalid service definition, expected #
- Multiple paths specified! There should be only one.
AI-assisted analysis of actix/actix-web@4d435abc28 (2026-08-09).
Data as JSON: /api/errors/27b2520309689958.
Report an issue: GitHub.
Appendix: source
Thrown at actix-web-codegen/src/scope.rs:19
use proc_macro::TokenStream;
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::{quote, ToTokens as _};
use crate::{
input_and_compile_error,
route::{MethodType, RouteArgs},
};
pub fn with_scope(args: TokenStream, input: TokenStream) -> TokenStream {
match with_scope_inner(args, input.clone()) {
Ok(stream) => stream,
Err(err) => input_and_compile_error(input, err),
}
}
fn with_scope_inner(args: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {
if args.is_empty() {
return Err(syn::Error::new(
Span::call_site(),
"missing arguments for scope macro, expected: #[scope(\"/prefix\")]",
));
}
let scope_prefix = syn::parse::<syn::LitStr>(args.clone()).map_err(|err| {
syn::Error::new(
err.span(),
"argument to scope macro is not a string literal, expected: #[scope(\"/prefix\")]",
)
})?;
let scope_prefix_value = scope_prefix.value();
if scope_prefix_value.ends_with('/') {
// trailing slashes cause non-obvious problems
// it's better to point them out to developers rather than
View on GitHub (pinned to 4d435abc28)