about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-08-12 05:22:03 +0000
committerbors <bors@rust-lang.org>2024-08-12 05:22:03 +0000
commit1d8f135b20fac63c493d5963ce02963b46ca0986 (patch)
tree1b3fb08c7d2feb330d961dbea2eeb05f05fb28c6
parent13f8a57cfb57d527abe797230beabb64758bb888 (diff)
parent3dc083dfd80d0436560c34c41be815b88510ffdc (diff)
downloadrust-1d8f135b20fac63c493d5963ce02963b46ca0986.tar.gz
rust-1d8f135b20fac63c493d5963ce02963b46ca0986.zip
Auto merge of #128862 - cblh:fix/128855, r=scottmcm
fix:  #128855 Ensure `Guard`'s `drop` method is removed at `opt-level=s` for `…

fix: #128855

…Copy` types

Added `#[inline]` to the `drop` method in the `Guard` implementation to ensure that the method is removed by the compiler at optimization level `opt-level=s` for `Copy` types. This change aims to align the method's behavior with optimization expectations and ensure it does not affect performance.

r​? `@scottmcm`
-rw-r--r--library/core/src/array/mod.rs1
-rw-r--r--tests/codegen/array-from_fn.rs13
2 files changed, 14 insertions, 0 deletions
diff --git a/library/core/src/array/mod.rs b/library/core/src/array/mod.rs
index 5c826b9993f..61c713c9e81 100644
--- a/library/core/src/array/mod.rs
+++ b/library/core/src/array/mod.rs
@@ -889,6 +889,7 @@ impl<T> Guard<'_, T> {
 }
 
 impl<T> Drop for Guard<'_, T> {
+    #[inline]
     fn drop(&mut self) {
         debug_assert!(self.initialized <= self.array_mut.len());
 
diff --git a/tests/codegen/array-from_fn.rs b/tests/codegen/array-from_fn.rs
new file mode 100644
index 00000000000..7202d0c67e6
--- /dev/null
+++ b/tests/codegen/array-from_fn.rs
@@ -0,0 +1,13 @@
+//@ revisions: NORMAL OPT
+//@ [NORMAL] compile-flags: -C opt-level=0 -C debuginfo=2
+//@ [OPT] compile-flags: -C opt-level=s -C debuginfo=0
+
+#![crate_type = "lib"]
+#![feature(array_from_fn)]
+
+#[no_mangle]
+pub fn iota() -> [u8; 16] {
+    // OPT-NOT: core..array..Guard
+    // NORMAL: core..array..Guard
+    std::array::from_fn(|i| i as _)
+}