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

Closure with a typed function argument and top level struct constructor break in nightly #107461

Closed
nicopap opened this issue Jan 30, 2023 · 2 comments · Fixed by #107478
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST C-bug Category: This is a bug. P-critical Critical priority regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nicopap
Copy link

nicopap commented Jan 30, 2023

Code

I tried this code: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=7f3bdb07bcc3a0a30d2ef80cf0adfd22

let closure = |f: fn(&f32) -> f32| MyStruct { x: f(&y) };

This code should compile.

Instead of compiling, the compiler generates the following error:

error: anonymous enums are not supported
 --> src/main.rs:8:38
  |
8 |     let closure = |f: fn(&f32) -> f32| MyStruct { x: f(&y) };
  |                                   ---^ --------
  |
  = help: create a named `enum` and use it here instead:
          enum Name {
              Variant1(f32),
              Variant2(MyStruct),
          }

error: expected one of `!`, `(`, `,`, `::`, `<`, or `|`, found `{`
 --> src/main.rs:8:49
  |
8 |     let closure = |f: fn(&f32) -> f32| MyStruct { x: f(&y) };
  |                                                 ^ expected one of `!`, `(`, `,`, `::`, `<`, or `|`

error: could not compile `playground` due to 2 previous errors

Version it worked on

It most recently worked on: (1.67)

Version with regression

Breaks in latest nightly 1.69.0-nightly (2023-01-29 e972bc8)

Related:

@nicopap nicopap added C-bug Category: This is a bug. regression-untriaged Untriaged performance or correctness regression. labels Jan 30, 2023
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 30, 2023
@Noratrieb
Copy link
Member

Oh no, that's pretty bad.. @estebank @cjgillot
As a workaround, creating a type alias for the function pointer type should work.

@Noratrieb Noratrieb added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 30, 2023
@WaffleLapkin WaffleLapkin added the A-parser Area: The parsing of Rust source code to an AST label Jan 30, 2023
nicopap added a commit to devildahu/bevy_mod_component_mirror that referenced this issue Jan 30, 2023
rust-lang/rust#107461

Due to this, docs.rs can't generate the docs,
so we implement the workaround.
@compiler-errors compiler-errors self-assigned this Jan 30, 2023
@apiraino
Copy link
Contributor

WG-prioritization assigning priority (Zulip discussion).

@rustbot label -I-prioritize +P-critical

@rustbot rustbot added P-critical Critical priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 31, 2023
@apiraino apiraino added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jan 31, 2023
compiler-errors added a commit to compiler-errors/rust that referenced this issue Feb 2, 2023
…ambiguous, r=estebank

Revert "Teach parser to understand fake anonymous enum syntax" and related commits

anonymous enum types are currently ambiguous in positions like:

* `|` operator: `a as fn() -> B | C`
* closure args: `|_: as fn() -> A | B`

I first tried to thread around `RecoverAnonEnum` into all these positions, but the resulting complexity in the compiler is IMO not worth it, or at least worth a bit more thinking time. In the mean time, let's revert this syntax for now, so we can go back to the drawing board.

Fixes rust-lang#107461

cc: `@estebank` `@cjgillot` rust-lang#106960

---
### Squashed revert commits:

Revert "review comment: Remove AST AnonTy"

This reverts commit 020cca8.

Revert "Ensure macros are not affected"

This reverts commit 12d18e4.

Revert "Emit fewer errors on patterns with possible type ascription"

This reverts commit c847a01.

Revert "Teach parser to understand fake anonymous enum syntax"

This reverts commit 2d82420.
@bors bors closed this as completed in 97872b7 Feb 2, 2023
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 C-bug Category: This is a bug. P-critical Critical priority regression-untriaged Untriaged performance or correctness regression. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
6 participants