Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Derive RustcDecodable not working when rustc-serialize crate is imported inside a module #61

Closed
@mhristache

Description

@mhristache

When importing rustc-serialize inside a module, [derive(RustcDecodable, RustcEncodable)] fails.

The code inside the module file:

extern crate "rustc-serialize" as rustc_serialize;
use self::rustc_serialize::json::{self, ToJson, Json, DecoderError};

#[derive(RustcDecodable, RustcEncodable)]
struct Test {
    test: String
    }

fn test(s: String) -> Test {
    Test {test: s}
    }

When compiling I get the following errors:

$ cargo build
   Compiling serialize_issue v0.0.1 (file://rust-playground/serialize_issue)
src/mod1/mod.rs:4:26: 4:41 error: failed to resolve. Did you mean     `self::rustc_serialize`?
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
                                           ^~~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
src/mod1/mod.rs:4:26: 4:40 error: attempt to implement a nonexistent trait    `rustc_serialize::Encodable`
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
                                           ^~~~~~~~~~~~~~
 note: in expansion of #[derive]
 src/mod1/mod.rs:4:1: 4:42 note: expansion site
 src/mod1/mod.rs:4:26: 4:41 error: failed to resolve. Did you mean     `self::rustc_serialize`?
 src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
                                           ^~~~~~~~~~~~~~~
 note: in expansion of #[derive]
 src/mod1/mod.rs:4:1: 4:42 note: expansion site
 src/mod1/mod.rs:4:26: 4:40 error: attempt to bound type parameter with a nonexistent    trait `rustc_serialize::Encoder`
 src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
                                           ^~~~~~~~~~~~~~
 note: in expansion of #[derive]
 src/mod1/mod.rs:4:1: 4:42 note: expansion site
 src/mod1/mod.rs:4:10: 4:25 error: failed to resolve. Did you mean     `self::rustc_serialize`?
 src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
                           ^~~~~~~~~~~~~~~
 note: in expansion of #[derive]
 src/mod1/mod.rs:4:1: 4:42 note: expansion site
 src/mod1/mod.rs:4:10: 4:24 error: attempt to implement a nonexistent trait    `rustc_serialize::Decodable`
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
                           ^~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
src/mod1/mod.rs:4:10: 4:25 error: failed to resolve. Did you mean     `self::rustc_serialize`?
src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
                           ^~~~~~~~~~~~~~~
note: in expansion of #[derive]
src/mod1/mod.rs:4:1: 4:42 note: expansion site
src/mod1/mod.rs:4:10: 4:24 error: attempt to bound type parameter with a nonexistent    trait `rustc_serialize::Decoder`
 src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
                           ^~~~~~~~~~~~~~
 note: in expansion of #[derive]
 src/mod1/mod.rs:4:1: 4:42 note: expansion site
 src/mod1/mod.rs:4:10: 4:25 error: failed to resolve. Did you mean     `self::rustc_serialize::Decodable`?
 src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
                           ^~~~~~~~~~~~~~~
 note: in expansion of #[derive]
 src/mod1/mod.rs:4:1: 4:42 note: expansion site
 src/mod1/mod.rs:4:10: 4:24 error: unresolved name `rustc_serialize::Decodable::decode`
 src/mod1/mod.rs:4 #[derive(RustcDecodable, RustcEncodable)]
                           ^~~~~~~~~~~~~~
 note: in expansion of #[derive]
 src/mod1/mod.rs:4:1: 4:42 note: expansion site
 error: aborting due to 10 previous errors
 Could not compile `serialize_issue`. 

The issue can be workaround by moving the imports to the lib.rs file.

$ cat src/mod1/mod.rs 
use super::rustc_serialize::json::{self, ToJson, Json, DecoderError};

#[derive(RustcDecodable, RustcEncodable)]
struct Test {
    test: String
    }

fn test(s: String) -> Test {
    Test {test: s}
    }

$ cat src/lib.rs 
extern crate "rustc-serialize" as rustc_serialize;
mod mod1;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions