Skip to content

Parsable associated enum constructor #79658

Closed
@iunof

Description

@iunof

I tried this code:

fn main() {
    {
        type Enum = <Bar as A>::Assoc;
        let bar = Enum::Bar(9);
        let foo = Enum::Foo{br: 3};
    }
    {
        let bar = <Bar as A>::Assoc::Bar(9);
        let foo = <Bar as A>::Assoc::Foo{br: 3};
    }

}

trait A {
    type Assoc;
}

enum Foo {
    Foo {br: i8},
    Bar(u8),
}

struct Bar;

impl A for Bar {
    type Assoc = Foo;
}

I expected to see this happen: in second block foo = Foo::Foo {br: 3}

Instead, this happened: compilation error

error: expected one of `.`, `::`, `;`, `?`, or an operator, found `{`
 --> src/main.rs:9:41
  |
9 |         let foo = <Bar as A>::Assoc::Foo{br: 3};
  |                                         ^ expected one of `.`, `::`, `;`, `?`, or an operator

error: aborting due to previous error

Playground

Meta

Stable channel 1.48.0
Beta channel 1.49.0-beta.2 (2020-11-24 bd26e4e544992e52f208)
Nightly channel 1.50.0-nightly (2020-11-30 b7ebc6b0c1ba3c27ebb1)

Metadata

Metadata

Assignees

Labels

A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.P-mediumMedium 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.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions