Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
erickt opened this issue Nov 18, 2014 · 3 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)

Comments

@erickt
Copy link
Contributor

erickt commented Nov 18, 2014

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.

@klutzy
Copy link
Contributor

klutzy commented Nov 19, 2014

Afaik paths are space-sensitive if it contains keywords. For example, use self :: a; causes "expected identifier, found keyword self".

@steveklabnik steveklabnik added O-macos Operating system: macOS A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) and removed O-macos Operating system: macOS labels Jan 29, 2015
@ghost
Copy link

ghost commented Nov 10, 2015

@steveklabnik duplicate of #14109

@steveklabnik
Copy link
Member

Yes, this seems to be true. thanks @Toby-s !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)
Projects
None yet
Development

No branches or pull requests

3 participants