Skip to content

format!, println!, and panic! macros cannot handle "super :: ..." and "self :: ..." paths #19075

Closed
@erickt

Description

@erickt

The format macros seem to be having some trouble parsing an argument that contains super :: and self :: paths, where the white space is significant. Here's an example:

fn bar() -> int { 5 }

mod foo {
    pub fn foo1() { let _ = format!("{}", super :: bar()); }
    pub fn foo2() { println!("{}", super :: bar()); }
    pub fn foo3() { panic!("{}", super :: bar()); }
    pub fn foo4() { 5 }
    pub fn foo5() { panic!("{}", self :: foo4()); }
}

fn main() {
    foo::foo1();
    foo::foo2();
    foo::foo3();
    println!("{}", foo :: foo4())
}

Errors with:

test.rs:4:43: 4:48 error: expected identifier, found keyword `super`
test.rs:4     pub fn foo1() { let _ = format!("{}", super :: bar()); }
                                                    ^~~~~
test.rs:5:36: 5:41 error: expected identifier, found keyword `super`
test.rs:5     pub fn foo2() { println!("{}", super :: bar()); }
                                             ^~~~~
test.rs:6:34: 6:39 error: expected identifier, found keyword `super`
test.rs:6     pub fn foo3() { panic!("{}", super :: bar()); }
                                           ^~~~~
test.rs:8:21: 8:50 error: expected token: `,`
test.rs:8     pub fn foo5() { panic!("{}", self :: foo4()); }
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Notice that a regular module paths work, but the special super and self tokens do not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions