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: derive(Clone) on trait item or impl item #46655

Closed
Armavica opened this issue Dec 11, 2017 · 1 comment · Fixed by #47013
Closed

ICE: derive(Clone) on trait item or impl item #46655

Armavica opened this issue Dec 11, 2017 · 1 comment · Fixed by #47013
Labels
A-syntaxext Area: Syntax extensions 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.

Comments

@Armavica
Copy link
Contributor

Armavica commented Dec 11, 2017

The following code:

trait Foo {
    #[derive(Clone)]
    type Bar;
}

produces the following compilation output:

$ RUST_BACKTRACE=1 cargo build
   Compiling bug v0.1.0 (file:///home/virgile/bug)
error: internal compiler error: #[derive(Clone)] on trait item or impl item
 --> src/main.rs:2:14
  |
2 |     #[derive(Clone)]
  |              ^^^^^

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

note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.22.1 (05e2e1c41 2017-11-22) running on x86_64-unknown-linux-gnu

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc_errors/lib.rs:439:8
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace
             at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49
   1: std::sys_common::backtrace::_print
             at /checkout/src/libstd/sys_common/backtrace.rs:69
   2: std::panicking::default_hook::{{closure}}
             at /checkout/src/libstd/sys_common/backtrace.rs:58
             at /checkout/src/libstd/panicking.rs:381
   3: std::panicking::default_hook
             at /checkout/src/libstd/panicking.rs:391
   4: std::panicking::rust_panic_with_hook
             at /checkout/src/libstd/panicking.rs:577
   5: std::panicking::begin_panic
   6: rustc_errors::Handler::span_bug
   7: syntax::ext::base::ExtCtxt::span_bug
   8: syntax_ext::deriving::clone::expand_deriving_clone
   9: syntax::ext::expand::MacroExpander::expand_invoc
  10: syntax::ext::expand::MacroExpander::expand
  11: syntax::ext::expand::MacroExpander::expand_crate
  12: rustc_driver::driver::phase_2_configure_and_expand::{{closure}}
  13: rustc_driver::driver::phase_2_configure_and_expand
  14: rustc_driver::driver::compile_input
  15: rustc_driver::run_compiler

error: Could not compile `bug`.

To learn more, run the command again with --verbose.

Rust version:

$ rustc --version --verbose
rustc 1.22.1 (05e2e1c41 2017-11-22)
binary: rustc
commit-hash: 05e2e1c41414e8fc73d0f267ea8dab1a3eeeaa99
commit-date: 2017-11-22
host: x86_64-unknown-linux-gnu
release: 1.22.1
LLVM version: 4.0
@kennytm kennytm added A-syntaxext Area: Syntax extensions I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ C-bug Category: This is a bug. labels Dec 11, 2017
@kennytm
Copy link
Member

kennytm commented Dec 11, 2017

(The ICE is introduced in 1.20. There is no ICE in 1.19.)

@arielb1 arielb1 added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Dec 11, 2017
bors added a commit that referenced this issue Dec 27, 2017
Do not expand a derive invocation when derive is not allowed

Closes #46655.

The first commit is what actually closes #46655. The second one is just a refactoring I have done while waiting on a test.
bors added a commit that referenced this issue Dec 28, 2017
Do not expand a derive invocation when derive is not allowed

Closes #46655.

The first commit is what actually closes #46655. The second one is just a refactoring I have done while waiting on a test.
kennytm added a commit to kennytm/rust that referenced this issue Jan 31, 2018
…source-line, r=estebank

Avoid underflow in render_source_line

While testing rust-lang#47655 I was able to make the compiler panic when it's compiled with debug assertions:

```shell
> rustc /dev/null --crate-type proc-macro

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/blob/master/CONTRIBUTING.md#bug-reports

note: rustc 1.25.0-dev running on x86_64-apple-darwin

note: run with `RUST_BACKTRACE=1` for a backtrace

thread 'rustc' panicked at 'attempt to subtract with overflow', librustc_errors/emitter.rs:287:49
```

Without debug assertions the following warning is emitted:

```shell
> rustc /dev/null --crate-type proc-macro

warning: unused variable: `registrar`
 --> /dev/null:0:1
  |
  |
  = note: #[warn(unused_variables)] on by default
  = note: to avoid this warning, consider using `_registrar` instead
```

The panic is due to the unused variable warning being spanned to `/dev/null:0:1`. When `render_source_line` subtracts 1 from the line number to look up the source line it panics due to underflow. Without debug assertions this would wrap and cause us to return a blank string instead.

Fix by explicitly testing for 0 and exiting early. I'm unsure how to automatically test this now that rust-lang#46655 has been approved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-syntaxext Area: Syntax extensions 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants