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

  1. Provide a string literal path prefix: `#[scope("/api")]`
  2. If you don't need a path prefix, consider whether the scope macro is needed at all
  3. 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

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


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)