{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/29908","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/29908/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/29908/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/29908/events","html_url":"https://github.com/rust-lang/rust/issues/29908","id":117588259,"number":29908,"title":"cannot use RustcEncodable when rustc_serialize is aliased","user":{"login":"debris","id":2613714,"avatar_url":"https://avatars.githubusercontent.com/u/2613714?v=3","gravatar_id":"","url":"https://api.github.com/users/debris","html_url":"https://github.com/debris","followers_url":"https://api.github.com/users/debris/followers","following_url":"https://api.github.com/users/debris/following{/other_user}","gists_url":"https://api.github.com/users/debris/gists{/gist_id}","starred_url":"https://api.github.com/users/debris/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/debris/subscriptions","organizations_url":"https://api.github.com/users/debris/orgs","repos_url":"https://api.github.com/users/debris/repos","events_url":"https://api.github.com/users/debris/events{/privacy}","received_events_url":"https://api.github.com/users/debris/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/rust-lang/rust/labels/A-syntaxext","name":"A-syntaxext","color":"d7e102"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-11-18T13:36:23Z","updated_at":"2016-03-07T18:18:05Z","closed_at":null,"body":"I tried this code:\r\n\r\n```rust\r\nextern crate rustc_serialize as serialize;\r\n\r\n#[derive(RustcEncodable)]\r\npub struct Hello {\r\n    a: u64\r\n}\r\n\r\n```\r\n\r\nI expected the code to compile, instead I saw these errors\r\n\r\n```\r\nsrc/lib.rs:3:10: 3:25 error: failed to resolve. Maybe a missing `extern crate rustc_serialize`? [E0433]\r\nsrc/lib.rs:3 #[derive(RustcEncodable)]\r\n                      ^~~~~~~~~~~~~~~\r\nsrc/lib.rs:3:10: 3:24 note: in this expansion of #[derive_RustcEncodable] (defined in src/lib.rs)\r\nsrc/lib.rs:3:10: 3:25 help: run `rustc --explain E0433` to see a detailed explanation\r\nsrc/lib.rs:3:10: 3:24 error: use of undeclared trait name `rustc_serialize::Encodable` [E0405]\r\nsrc/lib.rs:3 #[derive(RustcEncodable)]\r\n                      ^~~~~~~~~~~~~~\r\nsrc/lib.rs:3:10: 3:24 note: in this expansion of #[derive_RustcEncodable] (defined in src/lib.rs)\r\nsrc/lib.rs:3:10: 3:24 help: run `rustc --explain E0405` to see a detailed explanation\r\nsrc/lib.rs:3:10: 3:25 error: failed to resolve. Maybe a missing `extern crate rustc_serialize`? [E0433]\r\nsrc/lib.rs:3 #[derive(RustcEncodable)]\r\n                      ^~~~~~~~~~~~~~~\r\nsrc/lib.rs:3:10: 3:24 note: in this expansion of #[derive_RustcEncodable] (defined in src/lib.rs)\r\nsrc/lib.rs:3:10: 3:25 help: run `rustc --explain E0433` to see a detailed explanation\r\nsrc/lib.rs:3:10: 3:24 error: use of undeclared trait name `rustc_serialize::Encoder` [E0405]\r\nsrc/lib.rs:3 #[derive(RustcEncodable)]\r\n                      ^~~~~~~~~~~~~~\r\nsrc/lib.rs:3:10: 3:24 note: in this expansion of #[derive_RustcEncodable] (defined in src/lib.rs)\r\nsrc/lib.rs:3:10: 3:24 help: run `rustc --explain E0405` to see a detailed explanation\r\nerror: aborting due to 4 previous errors\r\n```\r\n\r\nWhen I removed alias for `rustc_serialize` everything compiled fine.\r\n\r\n```rust\r\nextern crate rustc_serialize;\r\n\r\n#[derive(RustcEncodable)]\r\npub struct Hello {\r\n    a: u64\r\n}\r\n```\r\n\r\nI assume, that this is caused by hardcoded path to `rustc_serialize`.\r\n\r\nhttps://github.com/rust-lang/rust/blob/97ba52ec379e17cc0984224b756282b68bc3a53b/src/libsyntax/ext/deriving/mod.rs#L166-L168\r\n```rust\r\n    \"RustcEncodable\" => encodable::expand_deriving_rustc_encodable,\r\n```\r\n\r\nhttps://github.com/rust-lang/rust/blob/219eca11b044de3644b3e9101124513c1a842b09/src/libsyntax/ext/deriving/encodable.rs#L100-L107\r\n```rust\r\npub fn expand_deriving_rustc_encodable(cx: &mut ExtCtxt,\r\n                                       span: Span,\r\n                                       mitem: &MetaItem,\r\n                                       item: &Annotatable,\r\n                                       push: &mut FnMut(Annotatable))\r\n{\r\n    expand_deriving_encodable_imp(cx, span, mitem, item, push, \"rustc_serialize\")\r\n}\r\n```\r\n\r\nhttps://github.com/rust-lang/rust/blob/219eca11b044de3644b3e9101124513c1a842b09/src/libsyntax/ext/deriving/encodable.rs#L134-L136\r\n```rust\r\nfn expand_deriving_encodable_imp(cx: &mut ExtCtxt,\r\n                                 span: Span,\r\n                                 mitem: &MetaItem,\r\n                                 item: &Annotatable,\r\n                                 push: &mut FnMut(Annotatable),\r\n                                 krate: &'static str)\r\n{\r\n    if cx.crate_root != Some(\"std\") {\r\n        // FIXME(#21880): lift this requirement.\r\n        cx.span_err(span, \"this trait cannot be derived with #![no_std] \\\r\n                           or #![no_core]\");\r\n        return;\r\n    }\r\n\r\n    let trait_def = TraitDef {\r\n        span: span,\r\n        attributes: Vec::new(),\r\n        path: Path::new_(vec!(krate, \"Encodable\"), None, vec!(), true),\r\n        additional_bounds: Vec::new(),\r\n```\r\n\r\n## Meta\r\n\r\n`rustc --version --verbose`:\r\n\r\n```\r\nrustc 1.4.0\r\nbinary: rustc\r\ncommit-hash: unknown\r\ncommit-date: unknown\r\nhost: x86_64-apple-darwin\r\nrelease: 1.4.0\r\n```"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/193378244","html_url":"https://github.com/rust-lang/rust/issues/29908#issuecomment-193378244","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/29908","id":193378244,"user":{"login":"durka","id":47007,"avatar_url":"https://avatars.githubusercontent.com/u/47007?v=3","gravatar_id":"","url":"https://api.github.com/users/durka","html_url":"https://github.com/durka","followers_url":"https://api.github.com/users/durka/followers","following_url":"https://api.github.com/users/durka/following{/other_user}","gists_url":"https://api.github.com/users/durka/gists{/gist_id}","starred_url":"https://api.github.com/users/durka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/durka/subscriptions","organizations_url":"https://api.github.com/users/durka/orgs","repos_url":"https://api.github.com/users/durka/repos","events_url":"https://api.github.com/users/durka/events{/privacy}","received_events_url":"https://api.github.com/users/durka/received_events","type":"User","site_admin":false},"created_at":"2016-03-07T18:18:05Z","updated_at":"2016-03-07T18:18:05Z","body":"It would be nice to fix this but I don't see how. A syntax extension can't browse the list of crate imports or anything like that. Should we just document that this is a requirement for `#[derive(RustcEncodable)]`? Or we could add an argument like `#[derive(RustcEncodable(crate=serialize))]` or something."}}