From cafe6b84236f3b62a2533a57a99d0e9153d6f291 Mon Sep 17 00:00:00 2001 From: Bee Date: Sun, 25 Oct 2026 18:55:30 +0000 Subject: [PATCH] Remove `type_array` from `rustc_codegen_ssa` --- compiler/rustc_codegen_gcc/src/type_.rs | 30 +++++++++---------- compiler/rustc_codegen_llvm/src/type_.rs | 8 ++--- .../rustc_codegen_ssa/src/traits/type_.rs | 1 - 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/compiler/rustc_codegen_gcc/src/type_.rs b/compiler/rustc_codegen_gcc/src/type_.rs index 89057b022ee34..d3e2595ff701a 100644 --- a/compiler/rustc_codegen_gcc/src/type_.rs +++ b/compiler/rustc_codegen_gcc/src/type_.rs @@ -141,6 +141,21 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { pub fn is_two_register_pair_type(&self, typ: Type<'gcc>) -> bool { self.two_register_pair_type_set.borrow().contains(&typ) } + + #[cfg_attr(feature = "master", expect(unused_mut))] + pub fn type_array(&self, ty: Type<'gcc>, mut len: u64) -> Type<'gcc> { + #[cfg(not(feature = "master"))] + if let Some(struct_type) = ty.is_struct() + && struct_type.get_field_count() == 0 + { + // NOTE: since gccjit only supports i32 for the array size and libcore's tests uses a + // size of usize::MAX in test_binary_search, we workaround this by setting the size to + // zero for ZSTs. + len = 0; + } + + new_array_type(self.context, None, ty, len) + } } /// An attribute that can be set on a GCC struct type. @@ -411,21 +426,6 @@ impl<'gcc, 'tcx> BaseTypeCodegenMethods for CodegenCx<'gcc, 'tcx> { fn val_ty(&self, value: RValue<'gcc>) -> Type<'gcc> { value.get_type() } - - #[cfg_attr(feature = "master", expect(unused_mut))] - fn type_array(&self, ty: Type<'gcc>, mut len: u64) -> Type<'gcc> { - #[cfg(not(feature = "master"))] - if let Some(struct_type) = ty.is_struct() - && struct_type.get_field_count() == 0 - { - // NOTE: since gccjit only supports i32 for the array size and libcore's tests uses a - // size of usize::MAX in test_binary_search, we workaround this by setting the size to - // zero for ZSTs. - len = 0; - } - - new_array_type(self.context, None, ty, len) - } } impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { diff --git a/compiler/rustc_codegen_llvm/src/type_.rs b/compiler/rustc_codegen_llvm/src/type_.rs index f03eb3d4a36fa..31c43134dd3c1 100644 --- a/compiler/rustc_codegen_llvm/src/type_.rs +++ b/compiler/rustc_codegen_llvm/src/type_.rs @@ -183,6 +183,10 @@ impl<'ll, CX: Borrow>> GenericCx<'ll, CX> { pub(crate) fn type_bf16(&self) -> &'ll Type { unsafe { llvm::LLVMBFloatTypeInContext(self.llcx()) } } + + pub(crate) fn type_array(&self, ty: &'ll Type, len: u64) -> &'ll Type { + unsafe { llvm::LLVMArrayType2(ty, len) } + } } impl<'ll, CX: Borrow>> BaseTypeCodegenMethods for GenericCx<'ll, CX> { @@ -280,10 +284,6 @@ impl<'ll, CX: Borrow>> BaseTypeCodegenMethods for GenericCx<'ll, CX> { fn val_ty(&self, v: &'ll Value) -> &'ll Type { common::val_ty(v) } - - fn type_array(&self, ty: &'ll Type, len: u64) -> &'ll Type { - unsafe { llvm::LLVMArrayType2(ty, len) } - } } pub(crate) fn llvm_type_ptr(llcx: &llvm::Context) -> &Type { diff --git a/compiler/rustc_codegen_ssa/src/traits/type_.rs b/compiler/rustc_codegen_ssa/src/traits/type_.rs index c9b5cb7142978..11dad80fb3417 100644 --- a/compiler/rustc_codegen_ssa/src/traits/type_.rs +++ b/compiler/rustc_codegen_ssa/src/traits/type_.rs @@ -24,7 +24,6 @@ pub trait BaseTypeCodegenMethods: BackendTypes { fn type_f128(&self) -> Self::Type; fn type_ppcf128(&self) -> Self::Type; - fn type_array(&self, ty: Self::Type, len: u64) -> Self::Type; fn type_func(&self, args: &[Self::Type], ret: Self::Type) -> Self::FunctionSignature; fn type_kind(&self, ty: Self::Type) -> TypeKind; fn type_ptr(&self) -> Self::Type;