Closed
Description
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 `(`
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.