Skip to content

Suffixed string and char literals are accepted if they don't go through parser #60494

Closed
rust-lang/reference
#612
@petrochenkov

Description

@petrochenkov

Things like "abc"suffix are lexically valid tokens, but they are reported as errors when parsed with the Rust Language Parser.

However, macro inputs are not parsed by the Rust Language Parser, each macro has its own language that it parses by itself.

It means that suffixed string and char literals can be passed to procedural macros (a procedural macro can process them as they want and make them legal and meaningful in its language), or declarative macros (if they are ignored).

Example:

macro_rules! blackhole { ($tt:tt) => () }

fn main() {
    blackhole!("string"suffix); // OK
}

Possible solutions:

  • Alternative 1: Prohibit this during lexing, a string/character literal tokens won't be able to be suffixed, proc macros won't be able to use them in their DSLs.
  • Alternative 2: Do nothing, string/character literal tokens can be suffixed (but not in the Rust Language proper), proc macros will be able to use them in their DSLs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-frontendArea: Compiler frontend (errors, parsing and HIR)A-grammarArea: The grammar of RustA-parserArea: The lexing & parsing of Rust source code to an ASTI-needs-decisionIssue: In need of a decision.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions