{"record":{"id":"6b963d3448fd9c75","repo":"actix/actix-web","slug":"argument-to-scope-macro-is-not-a-string-literal-e","errorCode":null,"errorMessage":"argument to scope macro is not a string literal, expected: #[scope(\"/prefix\")]","messagePattern":"argument to scope macro is not a string literal, expected: #\\[scope\\(\"/prefix\"\\)\\]","errorType":"validation","errorClass":"syn::Error","httpStatus":null,"severity":"error","filePath":"actix-web-codegen/src/scope.rs","lineNumber":26,"sourceCode":"};\n\npub fn with_scope(args: TokenStream, input: TokenStream) -> TokenStream {\n    match with_scope_inner(args, input.clone()) {\n        Ok(stream) => stream,\n        Err(err) => input_and_compile_error(input, err),\n    }\n}\n\nfn with_scope_inner(args: TokenStream, input: TokenStream) -> syn::Result<TokenStream> {\n    if args.is_empty() {\n        return Err(syn::Error::new(\n            Span::call_site(),\n            \"missing arguments for scope macro, expected: #[scope(\\\"/prefix\\\")]\",\n        ));\n    }\n\n    let scope_prefix = syn::parse::<syn::LitStr>(args.clone()).map_err(|err| {\n        syn::Error::new(\n            err.span(),\n            \"argument to scope macro is not a string literal, expected: #[scope(\\\"/prefix\\\")]\",\n        )\n    })?;\n\n    let scope_prefix_value = scope_prefix.value();\n\n    if scope_prefix_value.ends_with('/') {\n        // trailing slashes cause non-obvious problems\n        // it's better to point them out to developers rather than\n\n        return Err(syn::Error::new(\n            scope_prefix.span(),\n            \"scopes should not have trailing slashes; see https://docs.rs/actix-web/4/actix_web/struct.Scope.html#avoid-trailing-slashes\",\n        ));\n    }\n\n    let mut module = syn::parse::<syn::ItemMod>(input).map_err(|err| {","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/actix/actix-web/blob/4d435abc281842f3cbee165b6cde739e001d3a25/actix-web-codegen/src/scope.rs#L8-L44","documentation":"This compile-time error fires when the argument to `#[scope(...)]` cannot be parsed as a Rust string literal (`syn::LitStr`). The macro attempts `syn::parse::<syn::LitStr>(args)` at line 25 and if it fails (e.g., the argument is a number, identifier, or expression), this error is returned.","triggerScenarios":"Writing `#[scope(/api)]` (bare path without quotes), `#[scope(42)]` (number), or `#[scope(api)]` (identifier). The argument must be a double-quoted string literal.","commonSituations":"Forgetting to quote the prefix string, or trying to use a constant or expression as the scope prefix.","solutions":["Wrap the prefix in double quotes: `#[scope(\"/api\")]`","Do not use variables, constants, or macros as the argument; it must be a literal string","Check for accidental removal of quotes during refactoring"],"exampleFix":"// before\n#[scope(/api)]\nmod api { ... }\n\n// after\n#[scope(\"/api\")]\nmod api { ... }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Compile-time error. The argument must be a string literal:\n// #[scope(\"/api\")] — correct\n// #[scope(/api)] — incorrect (bare path)\n// #[scope(api)] — incorrect (identifier)\n// #[scope(42)] — incorrect (number)","tryCatchPattern":null,"preventionTips":["Always wrap the scope prefix in double quotes","Do not use variables or constants as scope prefix arguments","Use rust-analyzer or an IDE for real-time syntax feedback"],"tags":["rust","actix-web","codegen","routing","compile-time","macro","scope"],"backgroundTag":null,"analyzedSha":"4d435abc281842f3cbee165b6cde739e001d3a25","analyzedAt":"2026-08-09T01:01:40.926Z","contentChangedAt":"2026-08-09T01:01:40.926Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}