Skip to content
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

fn f(*) {} successfully compiles in method position #33413

Closed
petrochenkov opened this issue May 4, 2016 · 2 comments · Fixed by #33505
Closed

fn f(*) {} successfully compiles in method position #33413

petrochenkov opened this issue May 4, 2016 · 2 comments · Fixed by #33505

Comments

@petrochenkov
Copy link
Contributor

struct S {
    lol: u8
}

impl S {
    fn f(*) -> u8 {
        self.lol
    }
}

fn main() {
    println!("{}", S{lol:10}.f());
}

prints 10 on stable/beta/nightly.

This is the coolest syntax I've seen this year, now I'll always use * instead of self to save 3 keystrokes.

@durka
Copy link
Contributor

durka commented May 4, 2016

Lol, this is great. So the * token is parsed here and it fabricates a self ident so it doesn't have to panic. But if there is no self after the * then line 4716, which emits the actual error, never executes.

@petrochenkov
Copy link
Contributor Author

(I'm auditing parsing/resolution of self for hygiene issues, so I'll fix this as well.)

@Aatch Aatch added the A-amusing label May 5, 2016
petrochenkov added a commit to petrochenkov/rust that referenced this issue May 14, 2016
Fix spans and expected token lists, fix rust-lang#33413 + other cosmetic improvements
Add test for rust-lang#33413
Convert between `Arg` and `ExplicitSelf` precisely
Simplify pretty-printing for methods
bors added a commit that referenced this issue May 16, 2016
Remove ExplicitSelf from HIR

`self` argument is already kept in the argument list and can be retrieved from there if necessary, so there's no need for the duplication.
The same changes can be applied to AST, I'll make them in the next breaking batch.
The first commit also improves parsing of method declarations and fixes #33413.

r? @eddyb
critiqjo pushed a commit to critiqjo/rustdoc that referenced this issue Dec 16, 2016
Remove ExplicitSelf from HIR

`self` argument is already kept in the argument list and can be retrieved from there if necessary, so there's no need for the duplication.
The same changes can be applied to AST, I'll make them in the next breaking batch.
The first commit also improves parsing of method declarations and fixes rust-lang/rust#33413.

r? @eddyb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants