Skip to content

'as', '<' and '*' can cause a parsing error #32852

Description

@keeperofdakeys

The following code snippet is causing an error that might be avoidable (I suspect a parsing error, but I don't know how the grammar is actually defined, so this is just a guess). The error is "bare raw pointers are no longer allowed".

fn main() { let a = &4u64; println!("{}", 43 as u64 < *a);

I suspect that the *a is being interpreted as the start of a type generic, when it's actually dereferencing a value. Adding brances '( ... )' fixes the issue, as well as reordering the statement into a '>'. The problem occurs on both stable and nightly.

Activity

  1. keeperofdakeys commented on Apr 9, 2016

    @keeperofdakeys
    ContributorAuthor

    Thinking about this a bit further, the 'bare raw pointers' error must be occurring very early in the parsing (lexer?) in order to trigger that early. The less-than doesn't even have a matching angle-bracket.

  2. petrochenkov commented on Apr 9, 2016

    @petrochenkov
    Contributor

    The parser expects a type after as, so it starts parsing u64 < *a as a type.
    If we rename the identifiers and remove whitespaces things become more evident - we have Type<*T and < is interpreted as a start of type parameters and * is interpreted as a start of a pointer type which should be followed by const or mut, but is followed by T, therefore the error.

    The specialized error message about bare raw pointers should probably be removed - it's a pre-1.0 feature and only gray-bearded elders remember about them.

  3. birkenfeld commented on May 9, 2016

    @birkenfeld
    Contributor

    Compiler now says

    x.rs:1:55: 1:56 error: expected mut or const in raw pointer type (use`_mut T`or`_const T` as appropriate)
    x.rs:1 fn main() { let a = &4u64; println!("{}", 43 as u64 < *a);
    
    

    Otherwise, this is a duplicate of #22644 and #11962.

  4. Mark-Simulacrum commented on May 4, 2017

    @Mark-Simulacrum
    Member

    Closing in favor of #22644.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions