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

Parse and reject "typescript-style" anonymous enums #100741

Open
estebank opened this issue Aug 19, 2022 · 4 comments
Open

Parse and reject "typescript-style" anonymous enums #100741

estebank opened this issue Aug 19, 2022 · 4 comments
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

estebank commented Aug 19, 2022

Given

fn foo() -> i32 | &str { 42 }

we currently point at the | and complain about it not being expected.

Ideally, this should parse and explicitly state that anonymous enums are not supported, and provide a structured suggestion for

enum Name<'a> {
    VariantI32(i32),
    VariantStr(&'a str),
}
fn foo() -> Name<'_> {
    Name::VariantI32(42)
}

At least, we should emit a note suggesting the above in text without a structured suggestion (which will be easier to produce).

@estebank estebank added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. D-papercut Diagnostics: An error or lint that needs small tweaks. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. labels Aug 19, 2022
@LYF1999
Copy link
Contributor

LYF1999 commented Aug 19, 2022

@rustbot claim

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 23, 2023
Teach parser to understand fake anonymous enum syntax

Parse `Ty | OtherTy` in function argument and return types.
Parse type ascription in top level patterns.

Minimally address rust-lang#100741.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 25, 2023
Teach parser to understand fake anonymous enum syntax

Parse `Ty | OtherTy` in function argument and return types.
Parse type ascription in top level patterns.

Minimally address rust-lang#100741.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 26, 2023
Teach parser to understand fake anonymous enum syntax

Parse `Ty | OtherTy` in function argument and return types.
Parse type ascription in top level patterns.

Minimally address rust-lang#100741.
@Nilstrieb
Copy link
Member

Note: this had to be reverted because of the ambiguities. A new implementation has to be careful to only recover once invalid syntax has been discovered and not recover on the happy path.

@estebank
Copy link
Contributor Author

To expand on the above: types can syntactically go in the same place closure and or binop expressions can, and macros that use | today need to continue working. Effectively, the new type parsing should be limited exclusively to type parameters, return types and maybe let binding types.

calebcartwright pushed a commit to calebcartwright/rust that referenced this issue Jun 20, 2023
Teach parser to understand fake anonymous enum syntax

Parse `Ty | OtherTy` in function argument and return types.
Parse type ascription in top level patterns.

Minimally address rust-lang#100741.
@Phosphorus-M
Copy link

Phosphorus-M commented Jun 30, 2023

I love the idea! It's related to this RFC right?

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. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. D-terse Diagnostics: An error or lint that doesn't give enough information about the problem at hand. P-low Low priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants