diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-10-23 06:51:25 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-10-23 06:51:25 +0200 |
| commit | af356d6d7357dc0cbbfe4fc5ca3c5e180bfff60f (patch) | |
| tree | 0c382d9efe020245d150e0f8cd491f2e243603a3 /tests/codegen | |
| parent | 5b602201eda2770697d1beacbbad008672c2602b (diff) | |
| parent | 0a963ab2da139b177ef1e7f09efed7e4e1e8e930 (diff) | |
| download | rust-af356d6d7357dc0cbbfe4fc5ca3c5e180bfff60f.tar.gz rust-af356d6d7357dc0cbbfe4fc5ca3c5e180bfff60f.zip | |
Rollup merge of #132031 - slanterns:rc_default, r=ibraheemdev
Optimize `Rc<T>::default` The missing piece of https://github.com/rust-lang/rust/pull/131460. Also refactored `Arc<T>::default` by using a safe `NonNull::from(Box::leak(_))` to replace the unnecessarily unsafe call to `NonNull::new_unchecked(Box::into_raw(_))`. The remaining unsafety is coming from `[Rc|Arc]::from_inner`, which is safe from the construction of `[Rc|Arc]Inner`.
Diffstat (limited to 'tests/codegen')
| -rw-r--r-- | tests/codegen/placement-new.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/tests/codegen/placement-new.rs b/tests/codegen/placement-new.rs index edb25df5eb4..0ec2b6a6f20 100644 --- a/tests/codegen/placement-new.rs +++ b/tests/codegen/placement-new.rs @@ -1,9 +1,11 @@ //@ compile-flags: -O +//@ compile-flags: -Zmerge-functions=disabled #![crate_type = "lib"] // Test to check that types with "complex" destructors, but trivial `Default` impls // are constructed directly into the allocation in `Box::default` and `Arc::default`. +use std::rc::Rc; use std::sync::Arc; // CHECK-LABEL: @box_default_inplace @@ -16,6 +18,16 @@ pub fn box_default_inplace() -> Box<(String, String)> { Box::default() } +// CHECK-LABEL: @rc_default_inplace +#[no_mangle] +pub fn rc_default_inplace() -> Rc<(String, String)> { + // CHECK-NOT: alloca + // CHECK: [[RC:%.*]] = {{.*}}call {{.*}}__rust_alloc( + // CHECK-NOT: call void @llvm.memcpy + // CHECK: ret ptr [[RC]] + Rc::default() +} + // CHECK-LABEL: @arc_default_inplace #[no_mangle] pub fn arc_default_inplace() -> Arc<(String, String)> { |
