Skip to content

ICE: ID not mapped to struct fields #24365

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

Closed
ghost opened this issue Apr 13, 2015 · 4 comments · Fixed by #24380
Closed

ICE: ID not mapped to struct fields #24365

ghost opened this issue Apr 13, 2015 · 4 comments · Fixed by #24380
Labels
I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️

Comments

@ghost
Copy link

ghost commented Apr 13, 2015

I received an internal compiler error "ID not mapped to struct fields" while attempting to compile the code below (relevant parts excerpted for brevity). The important part is marked "BEGIN INTERNAL COMPILER ERROR CAUSING CODE;" note that this code will refuse to compile for several reasons (for loop should be using .iter(), string concatenation needs &str rather than String), so I expected to see those issues but not the ICE. Replacing that section with the commented out section directly below it marked "BEGIN CORRECT SUBSTITUTION FOR THE ABOVE CODE" causes the code to compile successfully.

EDIT: To make replication easier, you can check out the code (commit ID: 6f7f07488) from my public repo here and cargo build to reproduce the issue:
https://github.com/mquinn/RustedJVM/tree/d6f7f07488c3a8239cbf2078aed23b5ebf1ad1dc

methods.rs

use attributes::*;

pub struct Method {
    pub access_flags: u16,
    pub name_idx: u16,
    pub descriptor_idx: u16,
    pub attrs_count: u16,
    pub attributes: Vec<Attribute>,
}

impl Method {
    pub fn to_string(&self) -> String {
        let mut string_rep = format!("Method:\n\
                \t- access_flags=0x{:x}\n\
                \t- name_idx={}\n\
                \t- descriptor_idx={}\n\
                \t- attrs_count={}\n",
                self.access_flags, self.name_idx, self.descriptor_idx,
                self.attrs_count);

        /* BEGIN INTERNAL COMPILER ERROR CAUSING CODE */
        for attr in self.attributes {
            string_rep = string_rep + format!("\tAttributes:\n\
                \t\t- attr_name_idx={}\n\
                \t\t- attr_length={}\n",
                attr.attr_name_idx, attr.attr_length);
        }
        /* END INTERNAL COMPILER ERROR CAUSING CODE */

        /* BEGIN CORRECT SUBSTITUTION FOR THE ABOVE CODE */
       // for attr in self.attributes.iter() {
       //     string_rep = string_rep + &format!("\tAttribute:\n\
       //         \t\t- {}\n", attr.to_string());
       //}
       /* END CORRECT SUBSTITUTION FOR THE ABOVE CODE */

        string_rep
    }
}

attributes.rs

pub enum Attribute {
    Code(ATTRIBUTE_Code),
}

pub struct ATTRIBUTE_Code {
    pub attr_name_idx: u16,
    pub attr_length: u16,
}

impl Attribute {
    pub fn to_string(&self) -> String {
        match *self {
            Attribute::Code(ref s) => format!(
                "ATTRIBUTE_Code[attr_name_idx={}, attr_length={}]",
                        s.attr_name_idx, s.attr_length),
        }
    }
}

$rustc --version --verbose:
rustc 1.0.0-dev (93f7fe3 2015-04-10) (built 2015-04-10)
binary: rustc
commit-hash: 93f7fe3
commit-date: 2015-04-10
build-date: 2015-04-10
host: x86_64-unknown-linux-gnu
release: 1.0.0-dev

Backtrace:
Compiling rusted_jvm v0.0.1 (file:///home/mquinn/RustedJVM)
Running rustc src/rustedjvm/lib.rs --crate-name rustedjvm --crate-type lib -g -C metadata=71ad650c91a5c7b5 -C extra-filename=-71ad650c91a5c7b5 --out-dir /home/mquinn/RustedJVM/target/debug --emit=dep-info,link -L dependency=/home/mquinn/RustedJVM/target/debug -L dependency=/home/mquinn/RustedJVM/target/debug/deps
src/rustedjvm/methods.rs:53:17: 53:35 error: attempted access of field attr_name_idx on type attributes::Attribute, but no field with that name was found
src/rustedjvm/methods.rs:53 attr.attr_name_idx, attr.attr_length);
^~~~~~~~~~~~~~~~~~
note: in expansion of format_args!
:2:26: 2:59 note: expansion site
:1:1: 2:61 note: in expansion of format!
src/rustedjvm/methods.rs:50:39: 53:55 note: expansion site
error: internal compiler error: ID not mapped to struct fields: enum attributes::Attribute::Attribute (id=1155)
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 'Box', /home/mquinn/rust/src/libsyntax/diagnostic.rs:191

stack backtrace:
1: 0x7f56d1f7f619 - sys::backtrace::write::h18e58796ebd1d3c13JC
2: 0x7f56d1fa3ec7 - panicking::on_panic::hd41e16c2b3e4492d9aJ
3: 0x7f56d1eede52 - rt::unwind::begin_unwind_inner::h9765aad314ad1b4dhQI
4: 0x7f56cf4b150d - rt::unwind::begin_unwind::h5309693530743254994
5: 0x7f56cf4b1c7b - diagnostic::Handler::bug::hf75a5730928b8949LlB
6: 0x7f56cfef3016 - middle::ty::lookup_struct_fields::h8ae8673fe10e9771G77
7: 0x7f56d0dc79f3 - check::check_expr_with_unifier::suggest_field_names::h88608c9c654e2557PXq
8: 0x7f56d0d99532 - check::check_expr_with_unifier::check_field::h7ac13deb0b49aa68JRq
9: 0x7f56d0db5a76 - check::check_expr_with_unifier::h2183527311110853776
10: 0x7f56d0db20fa - check::check_expr_with_unifier::h2247865789248415537
11: 0x7f56d0d97c9f - check::check_expr_with_unifier::closure.33434
12: 0x7f56d0da0efe - vec::Vec.FromIterator::from_iter::h7936511826546032352
13: 0x7f56d0d9c4c6 - check::check_expr_with_unifier::h5081375255117599892
14: 0x7f56d0cc0a90 - check::_match::check_match::h8048da634ce4d38aZmb
15: 0x7f56d0db5641 - check::check_expr_with_unifier::h2183527311110853776
16: 0x7f56d0d808fc - check::check_expr_with_unifier::h5928011805846542261
17: 0x7f56d0d5ae08 - check::check_argument_types::hd0f650fe764473b6Xcq
18: 0x7f56d0d5802b - check::callee::confirm_builtin_call::hacd86568d5ed9eafPym
19: 0x7f56d0d56907 - check::callee::check_call::ha94772a466a1ab81kpm
20: 0x7f56d0d7d15a - check::check_expr_with_unifier::h5928011805846542261
21: 0x7f56d0d5ae08 - check::check_argument_types::hd0f650fe764473b6Xcq
22: 0x7f56d0d5802b - check::callee::confirm_builtin_call::hacd86568d5ed9eafPym
23: 0x7f56d0d56907 - check::callee::check_call::ha94772a466a1ab81kpm
24: 0x7f56d0da1b9d - check::check_expr_with_unifier::h11371956447038667724
25: 0x7f56d0d64363 - check::op::check_binop::h4c0bec0b4c03e67boin
26: 0x7f56d0da1d2f - check::check_expr_with_unifier::h11371956447038667724
27: 0x7f56d0dbbf21 - check::check_expr_with_unifier::h6210470634066893654
28: 0x7f56d0d705f4 - check::check_block_with_expected::h5733744b147f1afaNps
29: 0x7f56d0daefe6 - check::check_expr_with_unifier::h2247865789248415537
30: 0x7f56d0cc0e5e - check::_match::check_match::closure.28933
31: 0x7f56d0cc0c12 - check::_match::check_match::h8048da634ce4d38aZmb
32: 0x7f56d0da21a7 - check::check_expr_with_unifier::h11371956447038667724
33: 0x7f56d0d7090c - check::check_block_with_expected::h5733744b147f1afaNps
34: 0x7f56d0d87b04 - check::check_block_no_value::hfa79bd95eda5b773Oos
35: 0x7f56d0daeeed - check::check_expr_with_unifier::h2247865789248415537
36: 0x7f56d0cc0e5e - check::_match::check_match::closure.28933
37: 0x7f56d0cc0c12 - check::_match::check_match::h8048da634ce4d38aZmb
38: 0x7f56d0da21a7 - check::check_expr_with_unifier::h11371956447038667724
39: 0x7f56d0dca84b - check::check_decl_local::ha1d7685c67d10dabHjs
40: 0x7f56d0d705a1 - check::check_block_with_expected::h5733744b147f1afaNps
41: 0x7f56d0d9b798 - check::check_expr_with_unifier::h5081375255117599892
42: 0x7f56d0d7056f - check::check_block_with_expected::h5733744b147f1afaNps
43: 0x7f56d0d54186 - check::check_fn::h90484a4ffe1ca508Abo
44: 0x7f56d0d6bf87 - check::check_bare_fn::h1a3ab5c0cd11563590n
45: 0x7f56d0d710dc - check::check_method_body::hdbc9f81709163b85Zyo
46: 0x7f56d0d6901d - check::check_item::h77171b1af212ea76Ujo
47: 0x7f56d0d6a552 - visit::walk_item::h16852749654633779859
48: 0x7f56d0e2cf71 - check_crate::closure.36512
49: 0x7f56d0e283a0 - check_crate::h733d9630ef3865f2zxC
50: 0x7f56d25f5878 - driver::phase_3_run_analysis_passes::hfe88369659d0848dpGa
51: 0x7f56d25d6945 - driver::compile_input::hc670b94e199ddf6dQba
52: 0x7f56d2695661 - run_compiler::h4ffbc497265942ddL4b
53: 0x7f56d26932b2 - boxed::F.FnBox::call_box::h17881275858697386353
54: 0x7f56d26927e9 - rt::unwind::try::try_fn::h13022630299838337922
55: 0x7f56d2022ab8 - rust_try_inner
56: 0x7f56d2022aa5 - rust_try
57: 0x7f56d2692a98 - boxed::F.FnBox::call_box::h3800468468544546307
58: 0x7f56d1f91841 - sys::thread::create::thread_start::h4365e3ef51128cd6rLH
59: 0x7f56cc97d0a3 - start_thread
60: 0x7f56d1b5f04c - __clone
61: 0x0 -

Could not compile rusted_jvm.

Caused by:
Process didn't exit successfully: rustc src/rustedjvm/lib.rs --crate-name rustedjvm --crate-type lib -g -C metadata=71ad650c91a5c7b5 -C extra-filename=-71ad650c91a5c7b5 --out-dir /home/mquinn/RustedJVM/target/debug --emit=dep-info,link -L dependency=/home/mquinn/RustedJVM/target/debug -L dependency=/home/mquinn/RustedJVM/target/debug/deps (exit code: 101)

@ghost ghost changed the title ID not mapped to struct fields ICE: ID not mapped to struct fields Apr 13, 2015
@ebfull
Copy link
Contributor

ebfull commented Apr 13, 2015

Smaller demonstration of the ICE:

pub enum Foo {
    Test(Bar)
}

pub struct Bar {
    a: u32,
    b: u32
}

fn test(a: Vec<Foo>) {
    for lol in a {
        println!("test: {}", lol.b);
    }
}

fn main() { }

@oli-obk
Copy link
Contributor

oli-obk commented Apr 13, 2015

too slow by a few seconds :D but note the difference between references and values:

pub enum Attribute {
    Code {attr_name_idx: u16},
}

fn main() {
    let x = Attribute::Code {
        attr_name_idx: 42,
    };
    let z = (&x).attr_name_idx; // no ice
    let y = x.attr_name_idx; // ice
}

PlayPen

@ebfull
Copy link
Contributor

ebfull commented Apr 13, 2015

It's actually even more subtle than that:

pub enum Foo {
    Bar
}

fn test(a: Foo) {
    println!("{}", a.b);
}

fn main() { }

It's trying to suggest field names for you, thinking it's a struct, but I'm not sure how it manages to think that. Anyway, keep in mind this is intentional language behavior. You cannot address a field name of a variant of an enum without destructuring with a pattern match first.

@sanxiyn sanxiyn added the I-ICE Issue: The compiler panicked, giving an Internal Compilation Error (ICE) ❄️ label Apr 13, 2015
arielb1 added a commit to arielb1/rust that referenced this issue Apr 13, 2015
alexcrichton added a commit to alexcrichton/rust that referenced this issue Apr 14, 2015
@nstoddard
Copy link

Is this the same as #21797?

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

Successfully merging a pull request may close this issue.

4 participants