Skip to content

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

Description

@SimonSapin

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?

Activity

  1. bombless commented on Apr 14, 2015

    @bombless
    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.

  2. huonw commented on Jan 8, 2016

    @huonw
    Contributor

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-parserArea: The lexing & parsing of Rust source code to an AST

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions