{"action":"created","issue":{"url":"https://api.github.com/repos/rust-lang/rust/issues/49592","repository_url":"https://api.github.com/repos/rust-lang/rust","labels_url":"https://api.github.com/repos/rust-lang/rust/issues/49592/labels{/name}","comments_url":"https://api.github.com/repos/rust-lang/rust/issues/49592/comments","events_url":"https://api.github.com/repos/rust-lang/rust/issues/49592/events","html_url":"https://github.com/rust-lang/rust/issues/49592","id":310529509,"number":49592,"title":"ICE: in proc_macro when creating static generator tokens (Broken MIR: generator contains type [...] in MIR, but typeck only knows about for)","user":{"login":"PaulGrandperrin","id":1748936,"avatar_url":"https://avatars2.githubusercontent.com/u/1748936?v=4","gravatar_id":"","url":"https://api.github.com/users/PaulGrandperrin","html_url":"https://github.com/PaulGrandperrin","followers_url":"https://api.github.com/users/PaulGrandperrin/followers","following_url":"https://api.github.com/users/PaulGrandperrin/following{/other_user}","gists_url":"https://api.github.com/users/PaulGrandperrin/gists{/gist_id}","starred_url":"https://api.github.com/users/PaulGrandperrin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PaulGrandperrin/subscriptions","organizations_url":"https://api.github.com/users/PaulGrandperrin/orgs","repos_url":"https://api.github.com/users/PaulGrandperrin/repos","events_url":"https://api.github.com/users/PaulGrandperrin/events{/privacy}","received_events_url":"https://api.github.com/users/PaulGrandperrin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-04-02T16:18:37Z","updated_at":"2018-04-02T16:32:58Z","closed_at":null,"author_association":"NONE","body":"Hi,\r\nI was trying to do a \"quick and dirty\" port of future-await 0.1 to use `immovable generators` everywhere, using the new API from the recent nightlies (https://github.com/rust-lang/rust/pull/49194).\r\n\r\nIt's really simple, you just have to enclose calls to `resume()` with unsafe blocks and add the `static` keyword to all generator declarations.\r\nIt worked well for the places where the macro code was in declarative style but when trying to add the `static` keyword to generator declared in procedure style macros, I get an ICE. \r\n\r\nYou can find the offending code in question here: https://github.com/PaulGrandperrin/futures-await/commit/227bcc35ecdbe1c16e70079fd2f69f77607902ac#diff-aae145273a44b5b7d67eba92bc61af08R343\r\n\r\n```rust\r\n#[proc_macro]\r\npub fn async_block(input: TokenStream) -> TokenStream {\r\n    let input = TokenStream::from(TokenTree {\r\n        kind: TokenNode::Group(Delimiter::Brace, input),\r\n        span: proc_macro::Span::def_site(),\r\n    });\r\n    let expr = syn::parse(input)\r\n        .expect(\"failed to parse tokens as an expression\");\r\n    let expr = ExpandAsyncFor.fold_expr(expr);\r\n\r\n    let mut tokens = quote_cs! {\r\n        ::futures::__rt::gen\r\n    };\r\n\r\n    let span = Span::call_site();\r\n    syn::token::Paren(span).surround(&mut tokens, |tokens| {\r\n        syn::token::Unsafe(span).to_tokens(tokens);\r\n        syn::token::Brace(span).surround(tokens, |tokens| {\r\n            syn::token::Static(span).to_tokens(tokens); // if you comment this line => No ICE\r\n            syn::token::Move(span).to_tokens(tokens);\r\n            syn::token::OrOr([span, span]).to_tokens(tokens);\r\n            syn::token::Brace(span).surround(tokens, |tokens| {\r\n                (quote_cs! {\r\n                    if false { yield ::futures::Async::NotReady }\r\n                }).to_tokens(tokens);\r\n                expr.to_tokens(tokens);\r\n            });\r\n        });\r\n\r\n\r\n    });\r\n\r\n    tokens.into()\r\n}\r\n```\r\nTo reproduce, clone the branch `rustc-bug` of https://github.com/PaulGrandperrin/futures-await.git\r\nand use it in a project using `async_block!`.\r\n\r\nHere is the crash\r\n```\r\n   Compiling reactfs v0.1.0 (file:///home/paulg/Projects/reactfs)\r\n     Running `rustc --crate-name reactfs src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature=\"default\"' --cfg 'feature=\"instrumentation\"' -C metadata=882e506be794ab99 -C extra-filename=-882e506be794ab99 --out-dir /home/paulg/Projects/reactfs/target/debug/deps -C incremental=/home/paulg/Projects/reactfs/target/debug/incremental -L dependency=/home/paulg/Projects/reactfs/target/debug/deps --extern byteorder=/home/paulg/Projects/reactfs/target/debug/deps/libbyteorder-f8246f5b53339753.rlib --extern itertools=/home/paulg/Projects/reactfs/target/debug/deps/libitertools-eb98fbccb4da1591.rlib --extern honggfuzz=/home/paulg/Projects/reactfs/target/debug/deps/libhonggfuzz-9f774f97be9121c6.rlib --extern bytes=/home/paulg/Projects/reactfs/target/debug/deps/libbytes-3be8cb5d0748d1dc.rlib --extern num_traits=/home/paulg/Projects/reactfs/target/debug/deps/libnum_traits-30c3c0056211cac7.rlib --extern futures_await=/home/paulg/Projects/reactfs/target/debug/deps/libfutures_await-637cade218d0db17.rlib --extern futures=/home/paulg/Projects/reactfs/target/debug/deps/libfutures-75d075e86bb0e45b.rlib --extern slab=/home/paulg/Projects/reactfs/target/debug/deps/libslab-158bd0e99f5d7cbe.rlib --extern failure=/home/paulg/Projects/reactfs/target/debug/deps/libfailure-6808a5ea78d81bc4.rlib --extern enum_primitive_derive=/home/paulg/Projects/reactfs/target/debug/deps/libenum_primitive_derive-7e3658016f2f1a8c.so --extern fuzztest=/home/paulg/Projects/reactfs/target/debug/deps/libfuzztest-c5ecfc509dc6c5c0.rlib -C target-cpu=native -L native=/home/paulg/Projects/reactfs/target/debug/build/backtrace-sys-f867eb04e6714ca4/out/.libs`\r\nerror: internal compiler error: librustc_mir/transform/generator.rs:495: Broken MIR: generator contains type (core::ObjectPointer, u64, std::option::Option<u64>) in MIR, but typeck only knows about for<'r, 's, 't0> {futures::Async<futures::__rt::Mu>, (), fn(std::result::Result<(), failure::Error>) -> std::result::Result<<std::result::Result<(), failure::Error> as std::ops::Try>::Ok, <std::result::Result<(), failure::Error> as std::ops::Try>::Error> {<std::result::Result<(), failure::Error> as std::ops::Try>::into_result}, impl futures::__rt::MyFuture<std::result::Result<(), failure::Error>>, fn(std::result::Result<core::Uberblock, failure::Error>) -> std::result::Result<<std::result::Result<core::Uberblock, failure::Error> as std::ops::Try>::Ok, <std::result::Result<core::Uberblock, failure::Error> as std::ops::Try>::Error> {<std::result::Result<core::Uberblock, failure::Error> as std::ops::Try>::into_result}, impl futures::__rt::MyFuture<std::result::Result<core::Uberblock, failure::Error>>, core::Uberblock, core::ObjectPointer, u64, fn(std::ops::Range<usize>) -> <std::ops::Range<usize> as std::iter::IntoIterator>::IntoIter {<std::ops::Range<usize> as std::iter::IntoIterator>::into_iter}, usize, &'r std::vec::Vec<(u64, u64)>, std::ops::Range<usize>, fn(std::result::Result<(core::ObjectPointer, u64, std::option::Option<u64>), failure::Error>) -> std::result::Result<<std::result::Result<(core::ObjectPointer, u64, std::option::Option<u64>), failure::Error> as std::ops::Try>::Ok, <std::result::Result<(core::ObjectPointer, u64, std::option::Option<u64>), failure::Error> as std::ops::Try>::Error> {<std::result::Result<(core::ObjectPointer, u64, std::option::Option<u64>), failure::Error> as std::ops::Try>::into_result}, std::boxed::Box<futures::Future<Error=failure::Error, Item=(core::ObjectPointer, u64, std::option::Option<u64>)> + 's>, std::boxed::Box<futures::Future<Error=failure::Error, Item=std::vec::Vec<core::NodeEntry<u64, u64>>> + 't0>}\r\n   --> src/core/instrumentation.rs:113:5\r\n    |\r\n113 | /     async_block!{\r\n114 | |         await!(format(handle.clone()))?;\r\n115 | |         let uberblock = await!(find_latest_uberblock(handle.clone()))?;\r\n116 | |         let (mut op, mut free_space_offset) = (uberblock.tree_root_pointer, uberblock.free_space_offset);\r\n...   |\r\n134 | |         await!(read_btree(handle.clone(), op.clone()))\r\n135 | |     }\r\n    | |_____^\r\n\r\nthread 'rustc' panicked at 'Box<Any>', librustc_errors/lib.rs:488:9\r\nnote: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.\r\nstack backtrace:\r\n   0: std::sys::unix::backtrace::tracing::imp::unwind_backtrace\r\n             at libstd/sys/unix/backtrace/tracing/gcc_s.rs:49\r\n   1: std::sys_common::backtrace::print\r\n             at libstd/sys_common/backtrace.rs:71\r\n             at libstd/sys_common/backtrace.rs:59\r\n   2: std::panicking::default_hook::{{closure}}\r\n             at libstd/panicking.rs:207\r\n   3: std::panicking::default_hook\r\n             at libstd/panicking.rs:223\r\n   4: core::ops::function::Fn::call\r\n   5: std::panicking::rust_panic_with_hook\r\n             at libstd/panicking.rs:403\r\n   6: std::panicking::begin_panic\r\n   7: rustc_errors::Handler::span_bug\r\n   8: rustc::session::opt_span_bug_fmt::{{closure}}\r\n   9: rustc::ty::context::tls::with_opt::{{closure}}\r\n  10: <std::thread::local::LocalKey<T>>::try_with\r\n  11: <std::thread::local::LocalKey<T>>::with\r\n  12: rustc::ty::context::tls::with\r\n  13: rustc::ty::context::tls::with_opt\r\n  14: rustc::session::opt_span_bug_fmt\r\n  15: rustc::session::span_bug_fmt\r\n  16: <rustc_mir::transform::generator::StateTransform as rustc_mir::transform::MirPass>::run_pass\r\n  17: rustc_mir::transform::optimized_mir::{{closure}}\r\n  18: rustc_mir::transform::optimized_mir\r\n  19: rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::compute_result\r\n  20: rustc::dep_graph::graph::DepGraph::with_task_impl\r\n  21: rustc_errors::Handler::track_diagnostics\r\n  22: rustc::ty::maps::plumbing::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::cycle_check\r\n  23: rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::force\r\n  24: rustc::ty::maps::<impl rustc::ty::maps::queries::optimized_mir<'tcx>>::try_get\r\n  25: rustc::ty::maps::TyCtxtAt::optimized_mir\r\n  26: rustc::ty::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::generator_layout\r\n  27: rustc_metadata::encoder::<impl rustc_metadata::isolated_encoder::IsolatedEncoder<'a, 'b, 'tcx>>::encode_info_for_closure\r\n  28: rustc::dep_graph::graph::DepGraph::with_ignore\r\n  29: rustc_metadata::encoder::<impl rustc_metadata::index_builder::IndexBuilder<'a, 'b, 'tcx>>::encode_info_for_expr\r\n  30: rustc::hir::intravisit::walk_expr\r\n  31: rustc::hir::intravisit::walk_expr\r\n  32: rustc::hir::intravisit::Visitor::visit_nested_body\r\n  33: <rustc_metadata::encoder::EncodeVisitor<'a, 'b, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_item\r\n  34: rustc::hir::Crate::visit_all_item_likes\r\n  35: rustc_metadata::encoder::encode_metadata\r\n  36: rustc_metadata::cstore_impl::<impl rustc::middle::cstore::CrateStore for rustc_metadata::cstore::CStore>::encode_metadata\r\n  37: rustc::ty::context::TyCtxt::encode_metadata\r\n  38: rustc_trans::base::write_metadata\r\n  39: rustc::util::common::time\r\n  40: rustc_trans::base::trans_crate\r\n  41: <rustc_trans::LlvmTransCrate as rustc_trans_utils::trans_crate::TransCrate>::trans_crate\r\n  42: rustc::util::common::time\r\n  43: rustc_driver::driver::phase_4_translate_to_llvm\r\n  44: rustc_driver::driver::compile_input::{{closure}}\r\n  45: <std::thread::local::LocalKey<T>>::with\r\n  46: <std::thread::local::LocalKey<T>>::with\r\n  47: rustc::ty::context::TyCtxt::create_and_enter\r\n  48: rustc_driver::driver::compile_input\r\n  49: rustc_driver::run_compiler_impl\r\n  50: syntax::with_globals\r\nerror: aborting due to previous error\r\n\r\n\r\nnote: the compiler unexpectedly panicked. this is a bug.\r\n\r\nnote: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports\r\n\r\nnote: rustc 1.26.0-nightly (ae544ee1c 2018-03-29) running on x86_64-unknown-linux-gnu\r\n\r\nnote: compiler flags: -C debuginfo=2 -C incremental -C target-cpu=native --crate-type lib\r\n\r\nnote: some of the compiler flags provided by cargo are hidden\r\n\r\nerror: Could not compile `reactfs`.\r\n\r\nCaused by:\r\n  process didn't exit successfully: `rustc --crate-name reactfs src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg feature=\"default\" --cfg feature=\"instrumentation\" -C metadata=882e506be794ab99 -C extra-filename=-882e506be794ab99 --out-dir /home/paulg/Projects/reactfs/target/debug/deps -C incremental=/home/paulg/Projects/reactfs/target/debug/incremental -L dependency=/home/paulg/Projects/reactfs/target/debug/deps --extern byteorder=/home/paulg/Projects/reactfs/target/debug/deps/libbyteorder-f8246f5b53339753.rlib --extern itertools=/home/paulg/Projects/reactfs/target/debug/deps/libitertools-eb98fbccb4da1591.rlib --extern honggfuzz=/home/paulg/Projects/reactfs/target/debug/deps/libhonggfuzz-9f774f97be9121c6.rlib --extern bytes=/home/paulg/Projects/reactfs/target/debug/deps/libbytes-3be8cb5d0748d1dc.rlib --extern num_traits=/home/paulg/Projects/reactfs/target/debug/deps/libnum_traits-30c3c0056211cac7.rlib --extern futures_await=/home/paulg/Projects/reactfs/target/debug/deps/libfutures_await-637cade218d0db17.rlib --extern futures=/home/paulg/Projects/reactfs/target/debug/deps/libfutures-75d075e86bb0e45b.rlib --extern slab=/home/paulg/Projects/reactfs/target/debug/deps/libslab-158bd0e99f5d7cbe.rlib --extern failure=/home/paulg/Projects/reactfs/target/debug/deps/libfailure-6808a5ea78d81bc4.rlib --extern enum_primitive_derive=/home/paulg/Projects/reactfs/target/debug/deps/libenum_primitive_derive-7e3658016f2f1a8c.so --extern fuzztest=/home/paulg/Projects/reactfs/target/debug/deps/libfuzztest-c5ecfc509dc6c5c0.rlib -C target-cpu=native -L native=/home/paulg/Projects/reactfs/target/debug/build/backtrace-sys-f867eb04e6714ca4/out/.libs` (exit code: 101)\r\n```"},"comment":{"url":"https://api.github.com/repos/rust-lang/rust/issues/comments/377971328","html_url":"https://github.com/rust-lang/rust/issues/49592#issuecomment-377971328","issue_url":"https://api.github.com/repos/rust-lang/rust/issues/49592","id":377971328,"user":{"login":"PaulGrandperrin","id":1748936,"avatar_url":"https://avatars2.githubusercontent.com/u/1748936?v=4","gravatar_id":"","url":"https://api.github.com/users/PaulGrandperrin","html_url":"https://github.com/PaulGrandperrin","followers_url":"https://api.github.com/users/PaulGrandperrin/followers","following_url":"https://api.github.com/users/PaulGrandperrin/following{/other_user}","gists_url":"https://api.github.com/users/PaulGrandperrin/gists{/gist_id}","starred_url":"https://api.github.com/users/PaulGrandperrin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PaulGrandperrin/subscriptions","organizations_url":"https://api.github.com/users/PaulGrandperrin/orgs","repos_url":"https://api.github.com/users/PaulGrandperrin/repos","events_url":"https://api.github.com/users/PaulGrandperrin/events{/privacy}","received_events_url":"https://api.github.com/users/PaulGrandperrin/received_events","type":"User","site_admin":false},"created_at":"2018-04-02T16:32:58Z","updated_at":"2018-04-02T16:32:58Z","author_association":"NONE","body":"I guess @Zoxc "}}
{"actor":{"display_login":"PaulGrandperrin"}}