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

using pub macro_rules outside of the crate ICEs with Missing span for DefIndex(3) #83641

Closed
jjl opened this issue Mar 29, 2021 · 12 comments
Closed
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-pub_macro_rules `#![feature(pub_macro_rules)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jjl
Copy link

jjl commented Mar 29, 2021

using pub_macro_rules on the latest nightly, i get this compiler panic.

index varies according to the code that's running as you might expect

Code

in a project called 'repro'

main.rs:

fn main() {
    repro::fail!(recv);
}

lib.rs:

#![feature(pub_macro_rules)]
pub macro_rules! fail {
    ($x:expr) => { $x }
}

Meta

> cargo version --verbose
cargo 1.52.0-nightly (90691f2bf 2021-03-16)
release: 1.52.0
commit-hash: 90691f2bfe9a50291a98983b1ed2feab51d5ca55
commit-date: 2021-03-16

Error output

> RUST_BACKTRACE=1 cargo test
   Compiling repro v0.5.0 (/home/james/code/irrustible/repro)
thread 'rustc' panicked at 'Missing span for DefIndex(3)', compiler/rustc_metadata/src/rmeta/decoder.rs:715:32
stack backtrace:
   0: rust_begin_unwind
             at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/panicking.rs:493:5
   1: std::panicking::begin_panic_fmt
             at /rustc/07e0e2ec268c140e607e1ac7f49f145612d0f597/library/std/src/panicking.rs:435:5
   2: rustc_metadata::rmeta::decoder::<impl rustc_metadata::creader::CrateMetadataRef>::get_span::{{closure}}
   3: rustc_metadata::rmeta::decoder::cstore_impl::<impl rustc_metadata::creader::CStore>::load_macro_untracked
   4: rustc_resolve::build_reduced_graph::<impl rustc_resolve::Resolver>::get_macro_by_def_id
   5: rustc_resolve::macros::<impl rustc_resolve::Resolver>::resolve_macro_path
   6: rustc_resolve::macros::<impl rustc_expand::base::ResolverExpand for rustc_resolve::Resolver>::resolve_macro_invocation
   7: rustc_expand::expand::MacroExpander::fully_expand_fragment
   8: rustc_expand::expand::MacroExpander::expand_crate
   9: rustc_session::utils::<impl rustc_session::session::Session>::time
  10: rustc_interface::passes::configure_and_expand_inner
  11: rustc_interface::passes::configure_and_expand::{{closure}}
  12: rustc_data_structures::box_region::PinnedGenerator<I,A,R>::new
  13: rustc_interface::passes::configure_and_expand
  14: rustc_interface::queries::Queries::expansion
  15: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  16: rustc_span::with_source_map
  17: rustc_interface::interface::create_compiler_and_run
  18: scoped_tls::ScopedKey<T>::set
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.53.0-nightly (07e0e2ec2 2021-03-24) running on x86_64-unknown-linux-musl

note: compiler flags: -C embed-bitcode=no -C debuginfo=2 -C incremental -C target-feature=-crt-static

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
end of query stack
error: could not compile `repro`

To learn more, run the command again with --verbose.
@jjl jjl 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 Mar 29, 2021
@jonas-schievink jonas-schievink changed the title using pub macro_rules outside of the crate segfaults with Missing span for DefIndex(3) using pub macro_rules outside of the crate ICEs with Missing span for DefIndex(3) Mar 29, 2021
@jonas-schievink jonas-schievink added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) requires-nightly This issue requires a nightly compiler in some way. labels Mar 29, 2021
@jjl
Copy link
Author

jjl commented Mar 29, 2021

Note that I was not able to reproduce this without using a main.rs or test file, which is why i think it's about being used outside of the crate.

@jonas-schievink jonas-schievink added the F-pub_macro_rules `#![feature(pub_macro_rules)]` label Mar 29, 2021
@jjl
Copy link
Author

jjl commented Mar 29, 2021

It appears to be because it's trying to give me a helpful error for the variable i never defined that i'm passing as an argument to the macro

@petrochenkov
Copy link
Contributor

Unfortunately, the feature was merged in half-implemented state.
@spastorino @nikomatsakis I mentioned in #78166 that cross-crate cases need to be tested/fixed, but #82296 was merged as is instead.

@spastorino
Copy link
Member

@petrochenkov yeah, I understood that and I was going to work on this problem. At some point these changes that were supposed to be included in edition 2021, are now (if I'm not wrong) not going to be included so I ended de-priorizing this work.

Please @nikomatsakis correct me if I'm wrong. We may want or to have this open and assigned to me or @petrochenkov you can feel free to fix this too or we can also revert the included PR too.

@nikomatsakis
Copy link
Contributor

I think at this point we should just revert the PR. My sense was that we never quite got the design resolved to the point where we were confident we were going to go forward with it. Another option would be to add the "half-baked" flag that gives warnings when you use it, of course.

@jjl
Copy link
Author

jjl commented Mar 31, 2021

I think the 'half-baked' flag is still worth having, but it would be helpful if it noted that out of crate use is unlikely to work.

@nikomatsakis
Copy link
Contributor

My personal take is that if nobody is actively pursuing this design (and I think nobody is) we should just revert the PR.

@spastorino
Copy link
Member

spastorino commented Mar 31, 2021

Have opened a PR #83713 to revert this. As I've commented there, I guess if someone has time to make it work cross crates we could add the feature again with cross crate support.

fanninpm added a commit to fanninpm/glacier that referenced this issue Apr 2, 2021
@rust-lang-glacier-bot rust-lang-glacier-bot added the glacier ICE tracked in rust-lang/glacier. label Apr 2, 2021
bors added a commit to rust-lang-ci/rust that referenced this issue Apr 28, 2021
…nikomatsakis

Revert "Rollup merge of rust-lang#82296 - spastorino:pubrules, r=nikomatsakis"

This reverts commit e2561c5, reversing
changes made to 2982ba5.

As discussed in rust-lang#83641 this feature is not complete and in particular doesn't work cross macros and given that this is not going to be included in edition 2021 nobody seems to be trying to fix the underlying problem. When can add this again I guess, whenever somebody has the time to make it work cross crates.

r? `@nikomatsakis`
@JohnTitor
Copy link
Member

Triage: ICE has gone by #83713, I'm going to mark this as E-needs-test since it seems that PR doesn't have a regression test for the issue.

@JohnTitor JohnTitor added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Apr 29, 2021
@nikomatsakis
Copy link
Contributor

Hmm, I'm not sure if we need a regression test for this -- it's a regression test for a feature that no longer exists and may well never be added again -- but I guess it doesn't hurt.

@JohnTitor
Copy link
Member

Ah, good call, I'm not familiar with the context. @nikomatsakis feel free to just close if you like :)

@spastorino
Copy link
Member

Yes, this can be closed now.

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, ..) C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. F-pub_macro_rules `#![feature(pub_macro_rules)]` glacier ICE tracked in rust-lang/glacier. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ requires-nightly This issue requires a nightly compiler in some way. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants