Skip to content

Type called union wreaks havoc since 1.54 #88583

Closed
@dtolnay

Description

@dtolnay

When C-compatible untagged unions were introduced by RFC 1444, it was careful not to break existing valid uses of union identifier, such as https://doc.rust-lang.org/std/collections/struct.BTreeSet.html#method.union.

However, the unions from RFC 2102 (#49804) appear to be more disruptive, at least as currently implemented. The following stable code works with every stable rustc from 1.0.0 through 1.53.0, but can no longer be parsed by rustc 1.54.0 or current nightly.

struct union;

impl union {
    pub fn new() -> Self {
        unimplemented!()
    }
}

fn main() {}
error: functions are not allowed in union definitions
 --> src/main.rs:4:5
  |
4 | /     pub fn new() -> Self {
5 | |         unimplemented!()
6 | |     }
  | |_____^
  |
  = help: unlike in C++, Java, and C#, functions are declared in `impl` blocks
  = help: see https://doc.rust-lang.org/book/ch05-03-method-syntax.html for more information

error: expected `(`, found `main`
 --> src/main.rs:9:4
  |
9 | fn main() {}
  |    ^^^^ expected `(`

@jedel1043 @joshtriplett

Labeling T-compiler for what to do about the regression and T-lang because it's not clear to me what the grammar of anonymous union is intended to be from the parser's perspective.

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.P-criticalCritical priorityT-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.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions