Skip to content

rustc --pretty=expanded outputs invalid syntax for #[derive(RustcDecodable)] #42213

Closed
@eqrion

Description

@eqrion

Run

  1. cargo rustc -- -Z unstable-options --pretty=expanded > lib-expanded.rs
  2. rustc -Z parse-only lib-expanded.rs

With

// src/lib.rs
extern crate rustc_serialize;

#[derive(RustcDecodable, RustcEncodable)]
struct Foo;
$ rustc --version
rustc 1.19.0-nightly (5b13bff52 2017-05-23)

Results

error: expected `{`, found `::`
  --> src/lib-expanded.rs:16:39
   |
16 |                             |_d| -> _ ::std::result::Result::Ok(Foo))
   |                                       ^^

error: expected one of `.`, `;`, `?`, `}`, or an operator, found `::`
  --> src/lib-expanded.rs:16:39
   |
16 |                             |_d| -> _ ::std::result::Result::Ok(Foo))
   |                                      -^^ unexpected token
   |                                      |
   |                                      expected one of `.`, `;`, `?`, `}`, or an operator here

error: aborting due to 2 previous errors

lib-expanded.rs:

#![feature(prelude_import)]
#![no_std]
#[prelude_import]
use std::prelude::v1::*;
#[macro_use]
extern crate std as std;
extern crate rustc_serialize;

struct Foo;
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Decodable for Foo {
    fn decode<__D: ::rustc_serialize::Decoder>(__arg_0: &mut __D)
     -> ::std::result::Result<Foo, __D::Error> {
        __arg_0.read_struct("Foo", 0usize,
                            |_d| -> _ ::std::result::Result::Ok(Foo))
    }
}
#[automatically_derived]
#[allow(unused_qualifications)]
impl ::rustc_serialize::Encodable for Foo {
    fn encode<__S: ::rustc_serialize::Encoder>(&self, __arg_0: &mut __S)
     -> ::std::result::Result<(), __S::Error> {
        match *self {
            Foo =>
            __arg_0.emit_struct("Foo", 0usize,
                                |_e| -> _
                                    { return ::std::result::Result::Ok(()) }),
        }
    }
}

Expected

rustc lib-expanded.rs to succeed. Pretty printing should output valid rust syntax.

Not sure if this is specific to rustc_serialize, I haven't tried to create a simpler testcase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-prettyArea: Pretty printing (including `-Z unpretty`)C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions