Skip to content

Compiler panics unexpectedly in 1.31 when constructing struct with wrong syntax #56611

Closed
@chridou

Description

@chridou

The compiler crashes when constructing a struct syntactically wrong.

Simply paste the code below into the playground.

I tried this code:

struct Foo {
    t: u32,
}

impl Foo {
    fn new(t: u32) -> Self {
        Self(t) // wrong. Should be Self{t}
    }
}

fn main() {
    println!("Hello, world!");
}

This is the compiler output:

Compiling playground v0.0.1 (/playground)
error[E0658]: `Self` struct constructors are unstable (see issue #51994)
 --> src/main.rs:7:9
  |
7 |         Self(t) // wrong. Should be Self{t}
  |         ^^^^

error: internal compiler error: librustc/hir/def.rs:265: attempted .def_id() on invalid def: SelfCtor(DefId(0/0:4 ~ playground[8d9a]::{{impl}}[0]))

thread 'main' panicked at 'Box<Any>', librustc_errors/lib.rs:600:9
note: Run with `RUST_BACKTRACE=1` for a backtrace.
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0658`.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.31.0 (abe02cefd 2018-12-04) running on x86_64-unknown-linux-gnu

note: compiler flags: -C codegen-units=1 -C debuginfo=2 --crate-type bin

note: some of the compiler flags provided by cargo are hidden

error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Labels

A-type-systemArea: Type systemI-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️P-highHigh priorityT-compilerRelevant to the compiler 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