{"id":"f2af72fc61007051","repo":"rust-lang/rust","slug":"called-extract-element-on-a-non-vector-type","errorCode":null,"errorMessage":"Called extract_element on a non-vector type","messagePattern":"Called extract_element on a non-vector type","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"compiler/rustc_codegen_gcc/src/builder.rs","lineNumber":1513,"sourceCode":"\n    fn va_arg(&mut self, _list: RValue<'gcc>, _ty: Type<'gcc>) -> RValue<'gcc> {\n        unimplemented!();\n    }\n\n    #[cfg(feature = \"master\")]\n    fn extract_element(&mut self, vec: RValue<'gcc>, idx: RValue<'gcc>) -> RValue<'gcc> {\n        self.context.new_vector_access(self.location, vec, idx).to_rvalue()\n    }\n\n    #[cfg(not(feature = \"master\"))]\n    fn extract_element(&mut self, vec: RValue<'gcc>, idx: RValue<'gcc>) -> RValue<'gcc> {\n        use crate::context::new_array_type;\n\n        let vector_type = vec\n            .get_type()\n            .unqualified()\n            .dyncast_vector()\n            .expect(\"Called extract_element on a non-vector type\");\n        let element_type = vector_type.get_element_type();\n        let vec_num_units = vector_type.get_num_units();\n        let array_type =\n            new_array_type(self.context, self.location, element_type, vec_num_units as u64);\n        let array = self.context.new_bitcast(self.location, vec, array_type).to_rvalue();\n        self.context.new_array_access(self.location, array, idx).to_rvalue()\n    }\n\n    fn vector_splat(&mut self, _num_elts: usize, _elt: RValue<'gcc>) -> RValue<'gcc> {\n        unimplemented!();\n    }\n\n    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() {","sourceCodeStart":1495,"sourceCodeEnd":1531,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_codegen_gcc/src/builder.rs#L1495-L1531","documentation":"In the non-`master`-feature build of `extract_element`, the code calls `.dyncast_vector().expect(\"Called extract_element on a non-vector type\")` and panics if the operand's GCC type is not a vector. The `master`-feature build instead uses `context.new_vector_access` and avoids this path; the fallback (for older libgccjit) bitcasts the vector to an array first, so a non-vector operand is a type mismatch at the codegen boundary.","triggerScenarios":"rustc emits `extract_element` on an RValue whose GCC type fails to `dyncast_vector()` — a scalar, pointer, struct, or array that lost its vector typing (e.g. after a bitcast). Only fires when rustc_codegen_gcc is built WITHOUT the `master` feature (older libgccjit).","commonSituations":"Using `core::intrinsics::simd::simd_extract`, `std::simd` lane extraction, or vendor SIMD intrinsics where the operand type doesn't line up with a gccjit vector type, while running cg_gcc built against an older libgccjit that lacks `new_vector_access`.","solutions":["Build rustc_codegen_gcc WITH the `master` feature (newer libgccjit) so `extract_element` uses `new_vector_access` and bypasses this expect entirely","Upgrade libgccjit to a version that exposes the `master`-feature APIs","Ensure the operand passed to the extract intrinsic is genuinely a `#[repr(simd)]` / `std::simd` vector type before the call","File a bug with the type that failed to dyncast as a vector"],"exampleFix":"# before - built against old libgccjit, master feature off\ncargo build -p rustc_codegen_gcc\n\n# after - enable master feature (requires newer libgccjit)\ncargo build -p rustc_codegen_gcc --features master\n\n# or in the crate that depends on cg_gcc, ensure:\n# [dependencies]\n# rustc_codegen_gcc = { version = \"...\", features = [\"master\"] }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// extract_element (without the `master` libgccjit feature) panics via\n// .expect() when the value's type does not dyncast to a vector.\nfn is_vector_value<'gcc>(v: RValue<'gcc>) -> bool {\n    v.get_type().unqualified().dyncast_vector().is_some()\n}\n\n// Guard before calling:\nif !is_vector_value(vec) {\n    return Err(\"extract_element requires a vector-typed value\");\n}\n// safe to call builder.extract_element(vec, idx)","tryCatchPattern":"match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {\n    builder.extract_element(vec, idx)\n})) {\n    Ok(v) => v,\n    Err(_) => return Err(\"extract_element called on a non-vector value\"),\n}","preventionTips":["Only call extract_element on values whose type dyncasts to a vector; check `.get_type().unqualified().dyncast_vector().is_some()` first.","Before element access on aggregates, branch on dyncast_vector / dyncast_array to select the correct API.","Prefer building with the `master` libgccjit feature, where extract_element uses new_vector_access and does not require this guard."],"tags":["rust","codegen","gcc","gccjit","simd","libgccjit","panic"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}