{"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":"exception","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/937960ca67f20e14ffe2a075bf6d4593502be12c/actix-web-codegen/src/scope.rs#L8-L44","documentation":"The scope prefix must be a string literal. At actix-web-codegen/src/scope.rs:25-30 the args are parsed as `syn::LitStr`; if parsing fails the macro reports that the argument is not a string literal and shows the expected form.","triggerScenarios":"`#[scope(api)]` (ident), `#[scope(PREFIX)]` (const), or `#[scope(\"/api\".to_string())]` (expression) instead of a quoted string.","commonSituations":"Trying to use a constant or computed prefix, or forgetting quotes.","solutions":["Use a quoted string literal: `#[scope(\"/api\")]`.","Inline any constant value as a literal since proc-macro args must be literals."],"exampleFix":"// before\nconst PREFIX: &str = \"/api\";\n#[scope(PREFIX)]\nmod api { ... }\n\n// after\n#[scope(\"/api\")]\nmod api { ... }","handlingStrategy":"validation","validationCode":"// Compile-time only. The scope argument must be a string literal \"...\".\n// Constants/idents are not allowed; inline the literal.","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Quote the prefix string.","Do not reference const/&str variables in macro argument position."],"tags":["rust","actix","actix-web","macro","compile-time","routing"],"analyzedSha":"937960ca67f20e14ffe2a075bf6d4593502be12c","analyzedAt":"2026-08-06T01:15:46.978Z","schemaVersion":2}