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

Unary operator applied to range fails to parse #134899

Open
dtolnay opened this issue Dec 29, 2024 · 0 comments · May be fixed by #134900
Open

Unary operator applied to range fails to parse #134899

dtolnay opened this issue Dec 29, 2024 · 0 comments · May be fixed by #134900
Labels
A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@dtolnay
Copy link
Member

dtolnay commented Dec 29, 2024

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
@dtolnay dtolnay added A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 29, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 29, 2024
@dtolnay dtolnay linked a pull request Dec 29, 2024 that will close this issue
@jieyouxu jieyouxu added T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants