Skip to content

Unary operator applied to range fails to parse #134899

Closed
@dtolnay

Description

@dtolnay
struct S;
impl<T> std::ops::Add<T> for S {
    type Output = ();
    fn add(self, _: T) {}
}

fn main() {
    let _ = ..0;
    let _ = S + ..0;
    let _ = &..0;
    let _ = || ..0;
    let _ = *..0;
}

With the exception of *..0, all of the above expressions parse successfully, so .. is definitely allowed to appear at the beginning of an expression — including an expression with higher precedence such as binary + and unary &. I think it is a bug that *..0 does not parse. Same for -..0 and !..0.

error: expected expression, found `..`
  --> src/main.rs:12:14
   |
12 |     let _ = *..0;
   |              ^^ expected expression

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions