Skip to content

macros can observe raw identifier state [discuss] #49520

Description

@nikomatsakis

In #48942, @Lymia landed raw identifiers; "equality" in this implementation includes observing the "raw" state. Therefore, macros can observe if r#foo was used or not:

#![feature(raw_identifiers)]

macro_rules! foo {
    (a) => {
        1
    };
    
    (r#a) => { 2 };
}

fn main() {
    println!("{}", foo!(a));
    println!("{}", foo!(r#a));
}

This makes a certain measure of sense, but also makes me nervous, and I wanted to open an issue to discuss. For example, @Manishearth proposed making identifiers "raw" in macros when they are serialized, thus ensuring consistent interpretation as we cross editions.

I'm not entirely sure of the implications of this but it does make me nervous for users to be able to distinguish foo and r#foo.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)C-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-editionRelevant to the edition team.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions