Skip to content

Commit 1d8f135

Browse files
committed
Auto merge of rust-lang#128862 - cblh:fix/128855, r=scottmcm
fix: rust-lang#128855 Ensure `Guard`'s `drop` method is removed at `opt-level=s` for `… fix: rust-lang#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`
2 parents 13f8a57 + 3dc083d commit 1d8f135

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

library/core/src/array/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,7 @@ impl<T> Guard<'_, T> {
889889
}
890890

891891
impl<T> Drop for Guard<'_, T> {
892+
#[inline]
892893
fn drop(&mut self) {
893894
debug_assert!(self.initialized <= self.array_mut.len());
894895

tests/codegen/array-from_fn.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//@ revisions: NORMAL OPT
2+
//@ [NORMAL] compile-flags: -C opt-level=0 -C debuginfo=2
3+
//@ [OPT] compile-flags: -C opt-level=s -C debuginfo=0
4+
5+
#![crate_type = "lib"]
6+
#![feature(array_from_fn)]
7+
8+
#[no_mangle]
9+
pub fn iota() -> [u8; 16] {
10+
// OPT-NOT: core..array..Guard
11+
// NORMAL: core..array..Guard
12+
std::array::from_fn(|i| i as _)
13+
}

0 commit comments

Comments
 (0)