{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/30861","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/30861/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/30861/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/30861/events","html_url":"https://github.com/rust-lang/rust/issues/30861","id":126287597,"number":30861,"title":"rustc panics when adding #[derive(Deserialize)] to pub type declaration","user":{"login":"dikaiosune","id":6812281,"avatar_url":"https://avatars.githubusercontent.com/u/6812281?v=3","gravatar_id":"","url":"https://api.github.com/users/dikaiosune","html_url":"https://github.com/dikaiosune","followers_url":"https://api.github.com/users/dikaiosune/followers","following_url":"https://api.github.com/users/dikaiosune/following{/other_user}","gists_url":"https://api.github.com/users/dikaiosune/gists{/gist_id}","starred_url":"https://api.github.com/users/dikaiosune/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dikaiosune/subscriptions","organizations_url":"https://api.github.com/users/dikaiosune/orgs","repos_url":"https://api.github.com/users/dikaiosune/repos","events_url":"https://api.github.com/users/dikaiosune/events{/privacy}","received_events_url":"https://api.github.com/users/dikaiosune/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2016-01-12T22:01:36Z","updated_at":"2016-01-13T16:57:37Z","closed_at":null,"body":"## Summary\r\n\r\nI accidentally added a `#[derive(Deserialize)]` (from serde_macros) to a `pub type _ = _;` declaration instead a struct, which then caused the compiler to panic. I reproduced it with this toy example on the 2016-01-04 nightly (the 01-11 nightly isn't compiling a dependency of `serde_macros` right now):\r\n\r\n## Repro\r\n\r\n```bash\r\nadam@ARD155-01 ~/rust-projects $ cargo new demo --bin\r\nadam@ARD155-01 ~/rust-projects/demo $ multirust override nightly-2016-01-04\r\nmultirust: using existing install for 'nightly-2016-01-04'\r\nmultirust: override toolchain for '/home/adam/rust-projects/demo' set to 'nightly-2016-01-04'\r\n```\r\n\r\nCargo.toml:\r\n```toml\r\n[package]\r\nname = \"demo\"\r\nversion = \"0.1.0\"\r\nauthors = [\"Adam Perry <adam.n.perry@gmail.com>\"]\r\n\r\n[dependencies]\r\nserde_macros = \"0.6\"\r\n```\r\n\r\nmain.rs:\r\n```rust\r\n#![feature(custom_derive, plugin)]\r\n#![plugin(serde_macros)]\r\n\r\n#[derive(Deserialize)]\r\npub type NewType = Vec<u8>;\r\n\r\nfn main() {\r\n    println!(\"Hello, world!\");\r\n}\r\n```\r\n\r\nI expected to see this happen:\r\n\r\n`Don't do that stupid, here's a compiler (plugin) error.`\r\n\r\nInstead, this happened:\r\n\r\n```bash\r\nerror: internal compiler error: expected ItemStruct or ItemEnum in #[derive(Deserialize)]\r\nnote: the compiler unexpectedly panicked. this is a bug.\r\nnote: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports\r\nthread 'rustc' panicked at 'Box<Any>', ../src/libsyntax/errors/mod.rs:469\r\n```\r\n\r\n## Meta\r\n\r\n```bash\r\nadam@ARD155-01 ~/rust-projects/demo $ rustc --version --verbose\r\nrustc 1.7.0-nightly (8f11a9ef4 2016-01-03)\r\nbinary: rustc\r\ncommit-hash: 8f11a9ef4e23db189676c57c91c2675e97a74fea\r\ncommit-date: 2016-01-03\r\nhost: x86_64-unknown-linux-gnu\r\nrelease: 1.7.0-nightly\r\n```\r\n\r\n```bash\r\nadam@ARD155-01 ~/rust-projects/demo $ RUST_BACKTRACE=1 cargo build --verbose\r\n       Fresh quasi v0.3.12\r\n       Fresh aster v0.9.3\r\n       Fresh quasi_codegen v0.3.12\r\n       Fresh quasi_macros v0.3.12\r\n       Fresh serde_codegen v0.6.8\r\n       Fresh serde_macros v0.6.5\r\n   Compiling demo v0.1.0 (file:///home/adam/rust-projects/demo)\r\n     Running `rustc src/main.rs --crate-name demo --crate-type bin -g --out-dir /home/adam/rust-projects/demo/target/debug --emit=dep-info,link -L dependency=/home/adam/rust-projects/demo/target/debug -L dependency=/home/adam/rust-projects/demo/target/debug/deps --extern serde_macros=/home/adam/rust-projects/demo/target/debug/deps/libserde_macros-cc8fd08d94a4bbe6.so`\r\nerror: internal compiler error: expected ItemStruct or ItemEnum in #[derive(Deserialize)]\r\nnote: the compiler unexpectedly panicked. this is a bug.\r\nnote: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports\r\nthread 'rustc' panicked at 'Box<Any>', ../src/libsyntax/errors/mod.rs:469\r\nstack backtrace:\r\n   1:     0x7f8ded2b9ae0 - sys::backtrace::tracing::imp::write::h83c931a57293be64Afu\r\n   2:     0x7f8ded2c0925 - panicking::default_handler::_<closure>::closure.42389\r\n   3:     0x7f8ded2c038e - panicking::default_handler::hf06b6e142d791340Eqy\r\n   4:     0x7f8ded2896a6 - sys_common::unwind::begin_unwind_inner::h1f0575245cf3d0d097s\r\n   5:     0x7f8de94a3c57 - sys_common::unwind::begin_unwind::h12034783770677981522\r\n   6:     0x7f8de94a4094 - errors::Handler::bug::hdf0210fa875065449ed\r\n   7:     0x7f8de9700a98 - ext::base::ExtCtxt<'a>::bug::h7e5b95135edda145nY7\r\n   8:     0x7f8de1cd578e - de::expand_derive_deserialize::hd8e126252fab8683hra\r\n                        at /home/adam/.multirust/toolchains/nightly-2016-01-04/cargo/registry/src/github.com-88ac128001ac3a9a/serde_codegen-0.6.8/src/de.rs:42\r\n   9:     0x7f8de1cd7a71 - fn(&mut syntax..ext..base..ExtCtxt, syntax..codemap..Span, &syntax..codemap..Spanned<syntax..ast..MetaItem_>, &syntax..ext..base..Annotatable, &mut core..ops..FnMut(syntax..ext..base..Annotatable)) $u7b$de..expand_derive_deserialize$u7d$::fn_pointer_shim.11656::h4bad183350a0218a\r\n  10:     0x7f8de1cd7a3d - ext::base::F.MultiItemDecorator::expand::h17106332544396698413\r\n                        at ../src/libsyntax/ext/base.rs:119\r\n  11:     0x7f8de97414cb - ext::expand::expand_annotatable::h8c7d426b1e137197Zua\r\n  12:     0x7f8de973f4a8 - ext::expand::expand_item::h39bd2724f5135651IX9\r\n  13:     0x7f8de974b325 - fold::noop_fold_mod::h5906434227193000799\r\n  14:     0x7f8de9744ec9 - ext::expand::expand_item_underscore::h21fd83f940aaf048jY9\r\n  15:     0x7f8de977a2be - fold::noop_fold_item_simple::h14303000504543087339\r\n  16:     0x7f8de9779e20 - fold::noop_fold_item::h6885099739504352802\r\n  17:     0x7f8de9743559 - ext::expand::expand_annotatable::h8c7d426b1e137197Zua\r\n  18:     0x7f8de973f4a8 - ext::expand::expand_item::h39bd2724f5135651IX9\r\n  19:     0x7f8de9783abb - ext::expand::expand_crate::h11ede8e6c601d3973Sa\r\n  20:     0x7f8ded8138d2 - driver::phase_2_configure_and_expand::_<closure>::closure.31650\r\n  21:     0x7f8ded7a5b55 - driver::phase_2_configure_and_expand::hb11cfa87638fbd7ekya\r\n  22:     0x7f8ded7852f5 - driver::compile_input::h7886c8c232de8c7bjca\r\n  23:     0x7f8ded778a1b - run_compiler::hfed1b58f3d8ec3b4Lwc\r\n  24:     0x7f8ded7757e1 - sys_common::unwind::try::try_fn::h2798711789016417359\r\n  25:     0x7f8ded2b7778 - __rust_try\r\n  26:     0x7f8ded2aef6b - sys_common::unwind::try::inner_try::hfe5be09170a408dfH4s\r\n  27:     0x7f8ded775b40 - boxed::F.FnBox<A>::call_box::h4070559527455171401\r\n  28:     0x7f8ded2beb33 - sys::thread::Thread::new::thread_start::he835c8386c59daa96nx\r\n  29:     0x7f8de616e4a3 - start_thread\r\n  30:     0x7f8decf4513c - clone\r\n  31:                0x0 - <unknown>\r\n\r\nCould not compile `demo`.\r\n\r\nCaused by:\r\n  Process didn't exit successfully: `rustc src/main.rs --crate-name demo --crate-type bin -g --out-dir /home/adam/rust-projects/demo/target/debug --emit=dep-info,link -L dependency=/home/adam/rust-projects/demo/target/debug -L dependency=/home/adam/rust-projects/demo/target/debug/deps --extern serde_macros=/home/adam/rust-projects/demo/target/debug/deps/libserde_macros-cc8fd08d94a4bbe6.so` (exit code: 101)\r\n```"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/171363318","html_url":"https://github.com/rust-lang/rust/issues/30861#issuecomment-171363318","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/30861","id":171363318,"user":{"login":"est31","id":8872119,"avatar_url":"https://avatars.githubusercontent.com/u/8872119?v=3","gravatar_id":"","url":"https://api.github.com/users/est31","html_url":"https://github.com/est31","followers_url":"https://api.github.com/users/est31/followers","following_url":"https://api.github.com/users/est31/following{/other_user}","gists_url":"https://api.github.com/users/est31/gists{/gist_id}","starred_url":"https://api.github.com/users/est31/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/est31/subscriptions","organizations_url":"https://api.github.com/users/est31/orgs","repos_url":"https://api.github.com/users/est31/repos","events_url":"https://api.github.com/users/est31/events{/privacy}","received_events_url":"https://api.github.com/users/est31/received_events","type":"User","site_admin":false},"created_at":"2016-01-13T16:57:37Z","updated_at":"2016-01-13T16:57:37Z","body":"Yes, the fact that the compiler asks you to open an issue at this place and not at the place of the compiler plugin is unfortunate.\r\n\r\nThe plugin used an internal rustc API function that causes the panic and prints the \"internal error\" message you see above, it seems to be more intended for internal compiler usage than a compiler plugin. The way the plugin used the function is clearly wrong, it only complains about wrong by code writers.\r\n\r\nThe compiler exposes this API to plugins, this is wrong IMO, but I don't know whether there is a way to hide single functions from compiler plugins. Perhaps it could also check whether a plugin's code is in the stacktrace when printing the backtrace near the \"the compiler unexpectedly panicked\" code.\r\n\r\nSo agreed, rustc could do better here, but the major cause for this panic is the plugin."}}