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

accessing private struct member in a macro triggers compiler panic #25386

Closed
zmike opened this issue May 13, 2015 · 4 comments
Closed

accessing private struct member in a macro triggers compiler panic #25386

zmike opened this issue May 13, 2015 · 4 comments
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@zmike
Copy link

zmike commented May 13, 2015

Using this macro:

macro_rules! check_ptr_exist {
    ($var:expr, $member:ident) => (
        (*$var.c_object).$member.is_some()
    );
}
window.rs:225:29: 10:24 error: field `c_object` of struct `interfaces::cef_client::CefClient` is private
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: run with `RUST_BACKTRACE=1` for a backtrace
thread 'rustc' panicked at 'capacity overflow', /home/larsberg/rust/src/libcore/option.rs:330

stack backtrace:
   1:     0x7f389b244019 - sys::backtrace::write::h6dd465a29c00292cqYr
   2:     0x7f389b24bd89 - panicking::on_panic::hce7ca60568ec6ad9low
   3:     0x7f389b20da62 - rt::unwind::begin_unwind_inner::h2ea6b65af87d2482v3v
   4:     0x7f389b20e827 - rt::unwind::begin_unwind_fmt::hecd98e7f8a3b6e1cB2v
   5:     0x7f389b24b966 - rust_begin_unwind
   6:     0x7f389b297284 - panicking::panic_fmt::hd9d434c1534722c4NKy
   7:     0x7f389858a9ff - codemap::CodeMap::span_to_lines::hd5bcc89a8db6c068VtA
   8:     0x7f38985d1c07 - diagnostic::emit::h30031222ffc58de3U7B
   9:     0x7f38985cf824 - diagnostic::EmitterWriter.Emitter::emit::h8650f6f90b911a76C4B
  10:     0x7f3898581591 - diagnostic::SpanHandler::span_err::hb240726d7d932f7aIAB
  11:     0x7f38991e8c0d - session::Session::span_err::h3dc9cf7be0f3e980wrq
  12:     0x7f3899d60aa4 - PrivacyVisitor<'a, 'tcx>::check_field::h42b479c9ea66632514a
  13:     0x7f3899d62c4d - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_expr::hfc9c6e63d9e29d5fkob
  14:     0x7f3899d63779 - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_expr::hfc9c6e63d9e29d5fkob
  15:     0x7f3899d63779 - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_expr::hfc9c6e63d9e29d5fkob
  16:     0x7f3899d63779 - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_expr::hfc9c6e63d9e29d5fkob
  17:     0x7f3899d6309a - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_expr::hfc9c6e63d9e29d5fkob
  18:     0x7f3899d63126 - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_expr::hfc9c6e63d9e29d5fkob
  19:     0x7f3899d6316e - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_expr::hfc9c6e63d9e29d5fkob
  20:     0x7f3899d63c42 - visit::Visitor::visit_fn::h13779281697168954307
  21:     0x7f3899d64676 - visit::walk_impl_item::h9531018899457863059
  22:     0x7f3899d61fdf - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_item::h66a2e730a6f7b526akb
  23:     0x7f3899d61def - PrivacyVisitor<'a, 'tcx>.Visitor<'v>::visit_item::h66a2e730a6f7b526akb
  24:     0x7f3899d6898b - check_crate::h2621f8f2bc7b0c62v2b
  25:     0x7f389b7859f3 - driver::phase_3_run_analysis_passes::hc6c9df64aa0dd2d3tGa
  26:     0x7f389b766dbc - driver::compile_input::hf267a3a644c56a8cQba
  27:     0x7f389b81ffd1 - run_compiler::hd83bb72e6a98a17365b
  28:     0x7f389b81d822 - boxed::F.FnBox<A>::call_box::h6617975357532431123
  29:     0x7f389b81cdc9 - rt::unwind::try::try_fn::h15749177775482334247
  30:     0x7f389b2be918 - rust_try_inner
  31:     0x7f389b2be905 - rust_try
  32:     0x7f389b81d070 - boxed::F.FnBox<A>::call_box::h14003238196261600415
  33:     0x7f389b24ab21 - sys::thread::Thread::new::thread_start::hfc58bae990d0713aR9u
  34:     0x7f3895b16554 - start_thread
  35:     0x7f389ae9cf3c - __clone
  36:                0x0 - <unknown>
@steveklabnik steveklabnik added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label May 18, 2015
@JustAPerson
Copy link
Contributor

This still causes an ICE

A complete test case:

mod stuff {
    pub struct Item {
        c_object: Box<CObj>,
    }
    pub struct CObj {
        name: Option<String>,
    }
    impl Item {
        pub fn new() -> Item {
            Item {
                c_object: Box::new(CObj { name: None }),
            }
        }
    }
}

macro_rules! check_ptr_exist {
    ($var:expr, $member:ident) => (
        (*$var.c_object).$member.is_some()
    );
}

fn main() {
    let item = stuff::Item::new();
    println!("{}", check_ptr_exist!(item, name));
}

@pmarcelll
Copy link
Contributor

I can't reproduce it with rustc 1.2.0-nightly (2f5683913 2015-06-18).
EDIT: I still can, but the error message is just one line.

@pmarcelll
Copy link
Contributor

Here's the compiler output:

test.rs:19:9: 19:33 error: field `name` of struct `stuff::CObj` is private
test.rs:19         (*$var.c_object).$member.is_some()
                   ^~~~~~~~~~~~~~~~~~~~~~~~
test.rs:17:1: 21:2 note: in expansion of check_ptr_exist!
test.rs:25:20: 25:48 note: expansion site
note: in expansion of format_args!
<std macros>:2:25: 2:56 note: expansion site
<std macros>:1:1: 2:62 note: in expansion of print!
<std macros>:3:1: 3:54 note: expansion site
<std macros>:1:1: 3:58 note: in expansion of println!
test.rs:25:5: 25:50 note: expansion site
test.rs:25:37: 19:24 error: field `c_object` of struct `stuff::Item` is private
(internal compiler error: unprintable span)
test.rs:17:1: 21:2 note: in expansion of check_ptr_exist!
test.rs:25:20: 25:48 note: expansion site
note: in expansion of format_args!
<std macros>:2:25: 2:56 note: expansion site
<std macros>:1:1: 2:62 note: in expansion of print!
<std macros>:3:1: 3:54 note: expansion site
<std macros>:1:1: 3:58 note: in expansion of println!
test.rs:25:5: 25:50 note: expansion site
error: aborting due to 2 previous errors

@frewsxcv
Copy link
Member

Triage: this still causes an ICE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️
Projects
None yet
Development

No branches or pull requests

5 participants