Skip to content

Commit 04cd9d5

Browse files
committed
Auto merge of #142839 - oli-obk:denullarification, r=RalfJung,celinval
Stop backends from needing to support nullary intrinsics And then remove our infrastructure special casing them. Further improvements can now be done to them by avoiding the intermediate ConstValue step, but let's leave that to follow up work r? `@RalfJung`
2 parents 164fae4 + 9f85757 commit 04cd9d5

3 files changed

Lines changed: 19 additions & 21 deletions

File tree

example/mini_core.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ pub mod intrinsics {
660660
#[rustc_intrinsic]
661661
pub unsafe fn ctlz_nonzero<T>(x: T) -> u32;
662662
#[rustc_intrinsic]
663-
pub fn needs_drop<T: ?::Sized>() -> bool;
663+
pub const fn needs_drop<T: ?::Sized>() -> bool;
664664
#[rustc_intrinsic]
665665
pub fn bitreverse<T>(x: T) -> T;
666666
#[rustc_intrinsic]

example/mini_core_hello_world.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
#![feature(no_core, lang_items, never_type, linkage, extern_types, thread_local, repr_simd)]
1+
#![feature(
2+
no_core,
3+
lang_items,
4+
never_type,
5+
linkage,
6+
extern_types,
7+
thread_local,
8+
repr_simd,
9+
rustc_private
10+
)]
211
#![no_core]
312
#![allow(dead_code, non_camel_case_types, internal_features)]
413

@@ -207,10 +216,14 @@ fn main() {
207216
assert_eq!(intrinsics::align_of::<u16>() as u8, 2);
208217
assert_eq!(intrinsics::align_of_val(&a) as u8, intrinsics::align_of::<&str>() as u8);
209218

210-
assert!(!intrinsics::needs_drop::<u8>());
211-
assert!(!intrinsics::needs_drop::<[u8]>());
212-
assert!(intrinsics::needs_drop::<NoisyDrop>());
213-
assert!(intrinsics::needs_drop::<NoisyDropUnsized>());
219+
let u8_needs_drop = const { intrinsics::needs_drop::<u8>() };
220+
assert!(!u8_needs_drop);
221+
let slice_needs_drop = const { intrinsics::needs_drop::<[u8]>() };
222+
assert!(!slice_needs_drop);
223+
let noisy_drop = const { intrinsics::needs_drop::<NoisyDrop>() };
224+
assert!(noisy_drop);
225+
let noisy_unsized_drop = const { intrinsics::needs_drop::<NoisyDropUnsized>() };
226+
assert!(noisy_unsized_drop);
214227

215228
Unique { pointer: NonNull(1 as *mut &str), _marker: PhantomData } as Unique<dyn SomeTrait>;
216229

src/intrinsics/mod.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -812,21 +812,6 @@ fn codegen_regular_intrinsic_call<'tcx>(
812812
dest.write_cvalue(fx, val);
813813
}
814814

815-
sym::needs_drop | sym::type_id | sym::type_name | sym::variant_count => {
816-
intrinsic_args!(fx, args => (); intrinsic);
817-
818-
let const_val = fx
819-
.tcx
820-
.const_eval_instance(
821-
ty::TypingEnv::fully_monomorphized(),
822-
instance,
823-
source_info.span,
824-
)
825-
.unwrap();
826-
let val = crate::constant::codegen_const_value(fx, const_val, ret.layout().ty);
827-
ret.write_cvalue(fx, val);
828-
}
829-
830815
sym::ptr_offset_from | sym::ptr_offset_from_unsigned => {
831816
intrinsic_args!(fx, args => (ptr, base); intrinsic);
832817
let ptr = ptr.load_scalar(fx);

0 commit comments

Comments
 (0)