rust-lang/rust · error
Called extract_element on a non-vector type
Error message
Called extract_element on a non-vector type
What it means
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.
Source
Thrown at compiler/rustc_codegen_gcc/src/builder.rs:1513
fn va_arg(&mut self, _list: RValue<'gcc>, _ty: Type<'gcc>) -> RValue<'gcc> {
unimplemented!();
}
#[cfg(feature = "master")]
fn extract_element(&mut self, vec: RValue<'gcc>, idx: RValue<'gcc>) -> RValue<'gcc> {
self.context.new_vector_access(self.location, vec, idx).to_rvalue()
}
#[cfg(not(feature = "master"))]
fn extract_element(&mut self, vec: RValue<'gcc>, idx: RValue<'gcc>) -> RValue<'gcc> {
use crate::context::new_array_type;
let vector_type = vec
.get_type()
.unqualified()
.dyncast_vector()
.expect("Called extract_element on a non-vector type");
let element_type = vector_type.get_element_type();
let vec_num_units = vector_type.get_num_units();
let array_type =
new_array_type(self.context, self.location, element_type, vec_num_units as u64);
let array = self.context.new_bitcast(self.location, vec, array_type).to_rvalue();
self.context.new_array_access(self.location, array, idx).to_rvalue()
}
fn vector_splat(&mut self, _num_elts: usize, _elt: RValue<'gcc>) -> RValue<'gcc> {
unimplemented!();
}
fn extract_value(&mut self, aggregate_value: RValue<'gcc>, idx: u64) -> RValue<'gcc> {
// FIXME(antoyo): it would be better if the API only called this on struct, not on arrays.
assert_eq!(idx as usize as u64, idx);
let value_type = aggregate_value.get_type();
if value_type.dyncast_array().is_some() {View on GitHub (pinned to 22057b88b0)
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
Example fix
# before - built against old libgccjit, master feature off
cargo build -p rustc_codegen_gcc
# after - enable master feature (requires newer libgccjit)
cargo build -p rustc_codegen_gcc --features master
# or in the crate that depends on cg_gcc, ensure:
# [dependencies]
# rustc_codegen_gcc = { version = "...", features = ["master"] } Defensive patterns
Strategy: type-guard
Type guard
// extract_element (without the `master` libgccjit feature) panics via
// .expect() when the value's type does not dyncast to a vector.
fn is_vector_value<'gcc>(v: RValue<'gcc>) -> bool {
v.get_type().unqualified().dyncast_vector().is_some()
}
// Guard before calling:
if !is_vector_value(vec) {
return Err("extract_element requires a vector-typed value");
}
// safe to call builder.extract_element(vec, idx) Try / catch
match std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
builder.extract_element(vec, idx)
})) {
Ok(v) => v,
Err(_) => return Err("extract_element called on a non-vector value"),
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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`.
Related errors
- first index in inbounds_gep
- `rustc_codegen_gcc` doesn't support scalable vectors yet
- cannot cast a non-native integer to type {:?}
- cannot cast a {:?} to non-native integer
- Kind: {:?}
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/f2af72fc61007051.json.
Report an issue: GitHub.