actix/actix-web · error · syn::Error
missing arguments for scope macro, expected: #[scope("/prefi
Error message
missing arguments for scope macro, expected: #[scope("/prefix")] What it means
The `#[scope(...)]` macro requires a prefix argument. At actix-web-codegen/src/scope.rs:18-23, if the args token stream is empty the macro errors with the expected form `#[scope("/prefix")]`.
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 937960ca67)
Solutions
- Provide a prefix string literal: `#[scope("/api")]`.
- If you want no prefix, use an empty string `#[scope("")]` (but a non-empty prefix is the normal use).
Example fix
// before
#[scope]
mod api { ... }
// after
#[scope("/api")]
mod api { ... } Defensive patterns
Strategy: validation
Validate before calling
// Compile-time only. #[scope] requires a non-empty argument.
// Always write #[scope("/prefix")] with a string literal prefix. Prevention
- Never use bare #[scope]; always pass a prefix.
- Use the runtime web::scope("/prefix") builder if you prefer runtime construction.
When it happens
Trigger: Writing `#[scope]` with no parentheses, or `#[scope()]` with empty parens.
Common situations: Treating `scope` like a marker attribute that needs no args, or a typo deleting the prefix string.
Related errors
- invalid service definition, expected #[<method>("<path>")]
- Multiple paths specified! There should be only one.
- The #[route(..)] macro requires at least one `method` attrib
- The #[routes] macro requires at least one `#[<method>(..)]`
- argument to scope macro is not a string literal, expected: #
AI-assisted analysis of actix/actix-web@937960ca67 (2026-08-06).
Data as JSON: /data/errors/27b2520309689958.json.
Report an issue: GitHub.