Skip to content

#[deriving(Encodable)] crashes rustc --pretty expanded #12685

Closed
@lifthrasiir

Description

@lifthrasiir
extern crate serialize;
#[deriving(Encodable)] struct A;
#[deriving(Encodable)] struct B(int);
#[deriving(Encodable)] struct C { x: int } 
#[deriving(Encodable)] enum D {}
#[deriving(Encodable)] enum E { y } 
#[deriving(Encodable)] enum F { z(int) }

While this code compiles fine and works well against the encoder, rustc --pretty expanded gives this ICE:

use std::prelude::*;
extern crate std = "std#0.10-pre";
extern crate green = "green#0.10-pre";
extern crate rustuv = "rustuv#0.10-pre";
extern crate serialize;
#[deriving(Encodable)]
struct A;
#[doc = "Automatically derived."]
impl <__E: ::serialize::Encoder> ::serialize::Encodable<__E> for A {
    fn encode(&self, __arg_0: &mut __E) {
error: internal compiler error: unexpected failure
This message reflects a bug in the Rust compiler. 
We would appreciate a bug report: http://static.rust-lang.org/doc/master/complement-bugreport.html
note: the compiler hit an unexpected failure path. this is a bug
Ok(task 'rustc' failed at 'assertion failed: body.expr.is_some()', <rust>/src/libsyntax/print/pprust.rs:1400
)

Deriving is certainly generating an AST which is fine for trans but not fine for the pretty printer. It turns out that #[deriving(Encodable)] creates an FnBlockExpr node with a multi-statement Block (normally expected to contain a single ExprBlock node), which triggers a couple of assertions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-prettyArea: Pretty printing (including `-Z unpretty`)I-ICEIssue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions