{"id":"a09e7222fff0d935","repo":"rust-lang/rust","slug":"unexpected-type","errorCode":null,"errorMessage":"Unexpected type {:?}","messagePattern":"Unexpected type (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_codegen_gcc/src/builder.rs","lineNumber":1544,"sourceCode":"    fn extract_value(&mut self, aggregate_value: RValue<'gcc>, idx: u64) -> RValue<'gcc> {\n        // FIXME(antoyo): it would be better if the API only called this on struct, not on arrays.\n        assert_eq!(idx as usize as u64, idx);\n        let value_type = aggregate_value.get_type();\n\n        if value_type.dyncast_array().is_some() {\n            let index = self\n                .context\n                .new_rvalue_from_long(self.u64_type, i64::try_from(idx).expect(\"i64::try_from\"));\n            let element = self.context.new_array_access(self.location, aggregate_value, index);\n            element.get_address(self.location)\n        } else if value_type.dyncast_vector().is_some() {\n            panic!();\n        } else if let Some(struct_type) = value_type.is_struct() {\n            aggregate_value\n                .access_field(self.location, struct_type.get_field(idx as i32))\n                .to_rvalue()\n        } else {\n            panic!(\"Unexpected type {:?}\", value_type);\n        }\n    }\n\n    fn insert_value(\n        &mut self,\n        aggregate_value: RValue<'gcc>,\n        value: RValue<'gcc>,\n        idx: u64,\n    ) -> RValue<'gcc> {\n        // FIXME(antoyo): it would be better if the API only called this on struct, not on arrays.\n        assert_eq!(idx as usize as u64, idx);\n        let value_type = aggregate_value.get_type();\n\n        let new_val = self.current_func().new_local(None, value_type, \"aggregate_value\");\n        self.block.add_assignment(None, new_val, aggregate_value);\n\n        let lvalue = if value_type.dyncast_array().is_some() {\n            let index = self","sourceCodeStart":1526,"sourceCodeEnd":1562,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_gcc/src/builder.rs#L1526-L1562","documentation":"Panics in extract_value when the aggregate value is neither an array, a vector, nor a struct. The message prints the offending value_type, indicating rustc asked the backend to extract a field from a value whose GCC type the backend does not recognise as an aggregate kind.","triggerScenarios":"extract_value is called on a RValue whose value_type returns None for dyncast_array, dyncast_vector, and is_struct. This occurs when a non-aggregate (e.g. a scalar, pointer, or opaque libgccjit type) reaches the aggregate-extraction code path.","commonSituations":"Arises after rustc internals change how certain types are represented, or when libgccjit returns an unexpected type kind for a fat-pointer/unsized value. Crates exercising DSTs, trait-object fat pointers, or exotic representations are common triggers.","solutions":["Reproduce with the failing crate, capture the printed value_type, and report it upstream so the missing type kind can be handled.","Update rustc_codegen_gcc to a commit that recognises the additional aggregate type and routes it correctly.","As a temporary local workaround, lower the offending construct differently in the source crate (e.g. avoid the type/representation that triggers extract_value on it)."],"exampleFix":"// before\n} else {\n    panic!(\"Unexpected type {:?}\", value_type);\n}\n// after\n} else {\n    bug!(\"extract_value on unsupported aggregate type {:?}\", value_type);\n}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"use gccjit::Type;\n\n#[derive(Debug)]\nenum SupportedAggregate { Array, Struct }\n\nfn classify_for_extract_value(ty: Type<'_>) -> Option<SupportedAggregate> {\n    if ty.dyncast_array().is_some() {\n        Some(SupportedAggregate::Array)\n    } else if ty.is_struct().is_some() {\n        Some(SupportedAggregate::Struct)\n    } else {\n        None // vector, union, opaque, fn, etc. -> would hit \"Unexpected type\"\n    }\n}\n\n// guard before extract_value:\nmatch classify_for_extract_value(aggregate_value.get_type()) {\n    Some(kind) => extract_value(aggregate_value, idx),\n    None => return Err(format!(\"extract_value: unsupported aggregate kind\")),\n}","tryCatchPattern":null,"preventionTips":["extract_value in cg_gcc only handles arrays and structs — reject unions, vectors, opaque/fn types, or any non-aggregate before codegen.","Avoid unions and repr(packed) aggregates that lower to extractvalue; lower them to explicit byte loads instead.","Run the crate's codegen tests under cg_gcc in CI to surface unsupported aggregate shapes before they reach users.","When wrapping the builder, classify the type up front and emit a clear, localized error rather than letting the backend hit the generic panic."],"tags":["codegen-gcc","panic","type-mismatch","internal-compiler-error"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}