Skip to content

String literals in asm!() and ABIs are not escaped #60493

Closed
@petrochenkov

Description

@petrochenkov

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:

  • Alternative 1: Treat them as usual non-raw literals and escape properly.
    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.
  • Alternative 2: Treat them as implicitly raw during parsing (share the same code path with raw literals), but not during lexing (cannot do that without an explicit lexical marker).
    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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)A-grammarArea: The grammar of RustA-inline-assemblyArea: Inline assembly (`asm!(…)`)C-bugCategory: This is a bug.P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamrequires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions