Skip to content

macros can observe raw identifier state [discuss] #49520

Open
@nikomatsakis

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.

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.WG-epochWorking group: Epoch (2018) management

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions