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

ch as u32 < 0x80 syntax misinterpreted as a type parameter #20078

Closed
SimonSapin opened this issue Dec 20, 2014 · 2 comments
Closed

ch as u32 < 0x80 syntax misinterpreted as a type parameter #20078

SimonSapin opened this issue Dec 20, 2014 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST

Comments

@SimonSapin
Copy link
Contributor

Code like this:

    pub fn push(&mut self, ch: char) {
        if ch as u32 < 0x80 {
            // ...

Gives a parse error:

error: expected type, found `0x80`
        if ch as u32 < 0x80 {
                       ^~~~

Adding parentheses to disambiguate works around the issue:

    pub fn push(&mut self, ch: char) {
        if (ch as u32) < 0x80 {
            // ...

I understand that u32 is being parsed as a type and so < is assumed to be the start of type parameters. But maybe when that fails, the parser should backtrack and try to parse < as an operator?

@kmcallister kmcallister added A-parser Area: The parsing of Rust source code to an AST A-diagnostics Area: Messages for errors, warnings, and lints labels Jan 16, 2015
@bombless
Copy link
Contributor

I think this is a little similar as #22644 .
I imagine if we change the parser's front-end to parse this ideally, of course it is potentially a breaking-change, but I doubt if it would actually break a single line of existing code.

@huonw
Copy link
Member

huonw commented Jan 8, 2016

There's been more discussion on #22644, so I'm closing this as a dupe of that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST
Projects
None yet
Development

No branches or pull requests

4 participants