Skip to content

Commit

Permalink
Auto merge of rust-lang#128862 - cblh:fix/128855, r=scottmcm
Browse files Browse the repository at this point in the history
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`
  • Loading branch information
bors committed Aug 12, 2024
2 parents 13f8a57 + 3dc083d commit 1d8f135
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
13 changes: 13 additions & 0 deletions tests/codegen/array-from_fn.rs
Original file line number Diff line number Diff line change
@@ -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 _)
}

0 comments on commit 1d8f135

Please sign in to comment.