-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
String literals in asm!() and ABIs are not escaped #60493
Copy link
Copy link
Closed
Labels
A-frontendArea: Compiler frontend (errors, parsing and HIR)Area: Compiler frontend (errors, parsing and HIR)A-grammarArea: The grammar of RustArea: The grammar of RustA-inline-assemblyArea: Inline assembly (`asm!(…)`)Area: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.Category: This is a bug.P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamrequires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Metadata
Metadata
Assignees
Labels
A-frontendArea: Compiler frontend (errors, parsing and HIR)Area: Compiler frontend (errors, parsing and HIR)A-grammarArea: The grammar of RustArea: The grammar of RustA-inline-assemblyArea: Inline assembly (`asm!(…)`)Area: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.Category: This is a bug.P-lowLow priorityLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamrequires-nightlyThis issue requires a nightly compiler in some way. When possible, use a F-* label instead.This issue requires a nightly compiler in some way. When possible, use a F-* label instead.
Type
Fields
Give feedbackNo fields configured for issues without a type.
String literals in
asm!()'s outputs, inputs, clobbers and options are lexed like usual non-raw strings (asm!("something" : "outputs" : "inputs" : "clobbers" : "options")).String literals in ABI specifications are also lexed like usual non-raw strings (
extern "C" fn f();).In particular, all escapes are checked for correctness and corresponding errors are reported.
However, during parsing strings from those literals are directly transplanted into AST.
Directly means all those sweet
\r\ns are preserved, that's even raw-er than raw string literals!That's not good.
Proposed solutions:
That would mean
extern "\x43" fn f();being legal code.This is slightly weird, but
extern r#"C"# fn f() {}is already accepted, if we are talking about weird.This is slightly weird because lexing errors about escaping make no sense if the escaping is not even used.
I tend to prefer the first alternative for simplicity/consistency -
"..."means non-raw,r"..."means raw, end of the story.