Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ICE when forwarding $item with inner attr through a proc-macro layer #78675

Closed
danielhenrymantilla opened this issue Nov 2, 2020 · 2 comments · Fixed by #78677 or #74967
Closed

ICE when forwarding $item with inner attr through a proc-macro layer #78675

danielhenrymantilla opened this issue Nov 2, 2020 · 2 comments · Fixed by #78677 or #74967
Assignees
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@danielhenrymantilla
Copy link
Contributor

danielhenrymantilla commented Nov 2, 2020

Code

macro_rules! foo {(
    #[fake_attr]
    $item:item
) => (
    $item
)}

macro_rules! outer {($item:item) => (
    ::paste::paste! { // Identity proc-macro
        foo! {
            #[fake_attr]
            $item
        }
    }
)}
outer! {
    mod bar {
        //! Foo
    }
}

Meta

rustc --version --verbose:

rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24) running on x86_64-apple-darwin

Error output

thread 'rustc' panicked at 'assertion failed: `(left == right)`
  left: `Inner`,
 right: `Outer`: inner attributes should prevent cached tokens from existing', compiler/rustc_parse/src/lib.rs:613:9
Backtrace

stack backtrace:
   0: _rust_begin_unwind
   1: std::panicking::begin_panic_fmt
   2: rustc_parse::prepend_attrs
   3: rustc_parse::nt_to_tokenstream
   4: <proc_macro::bridge::TokenTree<rustc_expand::proc_macro_server::Group,rustc_expand::proc_macro_server::Punct,rustc_expand::proc_macro_server::Ident,rustc_expand::proc_macro_server::Literal> as rustc_expand::proc_macro_server::FromInternal<((rustc_ast::tokenstream::TokenTree,rustc_ast::tokenstream::Spacing),&rustc_session::parse::ParseSess,&mut alloc::vec::Vec<proc_macro::bridge::TokenTree<rustc_expand::proc_macro_server::Group,rustc_expand::proc_macro_server::Punct,rustc_expand::proc_macro_server::Ident,rustc_expand::proc_macro_server::Literal>>)>>::from_internal
   5: <rustc_expand::proc_macro_server::Rustc as proc_macro::bridge::server::TokenStreamIter>::next
   6: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
   7: std::panicking::try
   8: <proc_macro::bridge::server::Dispatcher<proc_macro::bridge::server::MarkedTypes<S>> as proc_macro::bridge::server::DispatcherTrait>::dispatch
   9: <proc_macro::bridge::closure::Closure<A,R> as core::convert::From<&mut F>>::from::call
  10: proc_macro::bridge::closure::Closure<A,R>::call
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/proc_macro/src/bridge/closure.rs:27:18
  11: proc_macro::bridge::client::TokenStreamIter::next::{{closure}}
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/proc_macro/src/bridge/client.rs:244:25
  12: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::with::{{closure}}
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/proc_macro/src/bridge/client.rs:336:47
  13: proc_macro::bridge::client::BridgeState::with::{{closure}}::{{closure}}
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/proc_macro/src/bridge/client.rs:293:17
  14: proc_macro::bridge::scoped_cell::ScopedCell<T>::replace
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/proc_macro/src/bridge/scoped_cell.rs:75:9
  15: proc_macro::bridge::client::BridgeState::with::{{closure}}
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/proc_macro/src/bridge/client.rs:291:13
  16: std::thread::local::LocalKey<T>::try_with
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/thread/local.rs:272:16
  17: std::thread::local::LocalKey<T>::with
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/std/src/thread/local.rs:248:9
  18: proc_macro::bridge::client::BridgeState::with
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/proc_macro/src/bridge/client.rs:290:9
  19: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::with
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/proc_macro/src/bridge/client.rs:329:9
  20: proc_macro::bridge::client::TokenStreamIter::next
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/proc_macro/src/bridge/client.rs:237:17
  21: <proc_macro::token_stream::IntoIter as core::iter::traits::iterator::Iterator>::next
             at /rustc/ffa2e7ae8fbf9badc035740db949b9dae271c29f/library/proc_macro/src/lib.rs:239:13
  22: <proc_macro2::imp::TokenTreeIter as core::iter::traits::iterator::Iterator>::next
             at /Users/dhm/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.24/src/wrapper.rs:304:46
  23: <proc_macro2::token_stream::IntoIter as core::iter::traits::iterator::Iterator>::next
             at /Users/dhm/.cargo/registry/src/github.com-1ecc6299db9ec823/proc-macro2-1.0.24/src/lib.rs:1213:13
  24: syn::buffer::TokenBuffer::inner_new
             at /Users/dhm/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.48/src/buffer.rs:53:19
  25: syn::buffer::TokenBuffer::inner_new
             at /Users/dhm/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.48/src/buffer.rs:89:25
  26: syn::buffer::TokenBuffer::inner_new
             at /Users/dhm/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.48/src/buffer.rs:89:25
  27: syn::buffer::TokenBuffer::new2
             at /Users/dhm/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.48/src/buffer.rs:112:9
  28: <F as syn::parse::Parser>::parse2
             at /Users/dhm/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.48/src/parse.rs:1184:19
  29: syn::parse::Parser::parse
             at /Users/dhm/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.48/src/parse.rs:1138:9
  30: syn::parse_macro_input::parse
             at /Users/dhm/.cargo/registry/src/github.com-1ecc6299db9ec823/syn-1.0.48/src/parse_macro_input.rs:138:5
  31: with_builtin_macros_proc_macros::with_builtin
             at /Users/dhm/git/dhm/with_builtin_macros.rs/src/lib.rs:54:9
  32: core::ops::function::FnOnce::call_once
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
  33: proc_macro::bridge::client::Client<fn(proc_macro::TokenStream) .> proc_macro::TokenStream>::expand1::run::{{closure}}
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:410:40
  34: proc_macro::bridge::client::run_client::{{closure}}::{{closure}}
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:377:26
  35: proc_macro::bridge::scoped_cell::ScopedCell<T>::set::{{closure}}
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/proc_macro/src/bridge/scoped_cell.rs:80:33
  36: proc_macro::bridge::scoped_cell::ScopedCell<T>::replace
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/proc_macro/src/bridge/scoped_cell.rs:75:9
  37: proc_macro::bridge::scoped_cell::ScopedCell<T>::set
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/proc_macro/src/bridge/scoped_cell.rs:80:9
  38: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter::{{closure}}
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:325:35
  39: std::thread::local::LocalKey<T>::try_with
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:272:16
  40: std::thread::local::LocalKey<T>::with
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/thread/local.rs:248:9
  41: proc_macro::bridge::client::<impl proc_macro::bridge::Bridge>::enter
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:325:9
  42: proc_macro::bridge::client::run_client::{{closure}}
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:370:9
  43: <std::panic::AssertUnwindSafe<F> as core::ops::function::FnOnce<()>>::call_once
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:308:9
  44: std::panicking::try::do_call
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:381:40
  45: ___rust_try
  46: std::panicking::try
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panicking.rs:345:19
  47: std::panic::catch_unwind
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/std/src/panic.rs:382:14
  48: proc_macro::bridge::client::run_client
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:369:5
  49: proc_macro::bridge::client::Client<fn(proc_macro::TokenStream) .> proc_macro::TokenStream>::expand1::run
             at /Users/dhm/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/proc_macro/src/bridge/client.rs:410:13
  50: proc_macro::bridge::server::run_server
  51: <rustc_expand::proc_macro::BangProcMacro as rustc_expand::base::ProcMacro>::expand
  52: rustc_expand::expand::MacroExpander::fully_expand_fragment
  53: rustc_expand::expand::MacroExpander::expand_crate
  54: rustc_interface::passes::configure_and_expand_inner
  55: rustc_interface::passes::configure_and_expand::{{closure}}
  56: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::new
  57: rustc_interface::passes::configure_and_expand
  58: rustc_interface::queries::Queries::expansion
  59: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  60: rustc_span::with_source_map
  61: rustc_interface::interface::create_compiler_and_run
  62: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

cc @Aaron1011

@danielhenrymantilla danielhenrymantilla added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Nov 2, 2020
@rustbot rustbot added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros labels Nov 2, 2020
@danielhenrymantilla
Copy link
Contributor Author

danielhenrymantilla commented Nov 2, 2020

Also note that on 1.45.0 there is no ICE, so this is a regression (EDIT: it ICEs starting from 1.46.0)

@rustbot modify labels: +regression-from-stable-to-stable

@rustbot rustbot added regression-untriaged Untriaged performance or correctness regression. I-prioritize Issue: Indicates that prioritization has been requested for this issue. regression-from-stable-to-stable Performance or correctness regression from one stable version to another. and removed regression-untriaged Untriaged performance or correctness regression. labels Nov 2, 2020
@Aaron1011 Aaron1011 self-assigned this Nov 2, 2020
@camelid
Copy link
Member

camelid commented Nov 2, 2020

searched nightlies: from nightly-2020-03-01 to nightly-2020-11-02
regressed nightly: nightly-2020-06-25
searched commits: from ff5b446 to 67100f6
regressed commit: 3c90ae8

bisected with cargo-bisect-rustc v0.6.0

Host triple: x86_64-apple-darwin
Reproduce with:

cargo bisect-rustc --regress=ice --start=2020-03-01 --preserve 

@rustbot rustbot removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Nov 2, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Nov 3, 2020
…r=petrochenkov

Use reparsed `TokenStream` if we captured any inner attributes

Fixes rust-lang#78675

We now bail out of `prepend_attrs` if we ended up capturing any inner
attributes (which can happen in several places, due to token capturing
for `macro_rules!` arguments.
bors added a commit to rust-lang-ci/rust that referenced this issue Nov 4, 2020
…petrochenkov

Use reparsed `TokenStream` if we captured any inner attributes

Fixes rust-lang#78675

We now bail out of `prepend_attrs` if we ended up capturing any inner
attributes (which can happen in several places, due to token capturing
for `macro_rules!` arguments.
@bors bors closed this as completed in 22383b3 Nov 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-proc-macros Area: Procedural macros C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
4 participants