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

Adding functions through crate level syntax extensions crashes compiler #45458

Closed
Rantanen opened this issue Oct 22, 2017 · 3 comments
Closed
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@Rantanen
Copy link
Contributor

Rantanen commented Oct 22, 2017

Having a MultiDecorator push function items on an attribute defined on the crate level (#![...) will result in the compiler crashing if these functions are called from the code.

#![decorator]  // Changing this to #[decorator] prevents the crash.

fn main() {
    decorated_method();  // Commenting out this line prevents the crash.
}

Full reproduction case is at https://github.com/Rantanen/com-export-rs/tree/issue
intercom-issue.zip

Use cargo run --example example

Meta

rustc --version --verbose:
rustc 1.22.0-nightly (f6d7514 2017-10-17)
binary: rustc
commit-hash: f6d7514
commit-date: 2017-10-17
host: x86_64-pc-windows-msvc
release: 1.22.0-nightly
LLVM version: 4.0

Backtrace:

thread 'rustc' panicked at 'Box<Any>', src\librustc_errors\lib.rs:492:8
stack backtrace:
   0: _rdl_shrink_in_place
   1: std::panicking::Location::column
   2: std::panicking::Location::column
   3: std::panicking::rust_panic_with_hook
   4: <unknown>
   5: rustc_errors::Handler::bug
   6: rustc::session::bug_fmt
   7: rustc::session::bug_fmt
   8: rustc::session::bug_fmt
   9: rustc::hir::map::Map::read
  10: rustc::hir::map::Map::span
  11: rustc::ty::maps::<impl rustc::ty::maps::queries::def_span<'tcx>>::ensure
  12: rustc::ty::maps::<impl rustc::ty::maps::queries::def_span<'tcx>>::try_get
  13: rustc::ty::maps::TyCtxtAt::def_span
  14: rustc::ty::maps::<impl rustc::ty::maps::queries::lookup_deprecation_entry<'tcx>>::try_get
  15: rustc::ty::maps::TyCtxtAt::lookup_deprecation_entry
  16: rustc::middle::stability::<impl rustc::ty::context::TyCtxt<'a, 'gcx, 'tcx>>::check_stability
  17: <rustc::middle::stability::Checker<'a, 'tcx> as rustc::hir::intravisit::Visitor<'tcx>>::visit_path

Edit: I removed the branch repro branch from the repository. It was causing problems with Codecov, which figured it was the default branch. Zip file of the repro case attached instead.

@TimNN
Copy link
Contributor

TimNN commented Oct 24, 2017

I'm not sure this is a bug or not -- I don't think plugins were intended to be used like this. But maybe the compiler should report a better error in that case.

@TimNN TimNN added C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ labels Oct 24, 2017
@Rantanen
Copy link
Contributor Author

Yeah, the "emit crate-level code" use case can be handled by macros so getting this to work isn't on that high priority I guess.

But it would be nice if rustc didn't panic on it. :)

@Rantanen
Copy link
Contributor Author

Rantanen commented Feb 8, 2018

Closing in favor of proc macros over syntax extensions. There are still ICEs with proc macros in the crate-level case, but those are described in #41430 in more detail.

@Rantanen Rantanen closed this as completed Feb 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

2 participants