mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 06:44:35 +00:00
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`
This commit is contained in:
commit
1d8f135b20
@ -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());
|
||||
|
||||
|
13
tests/codegen/array-from_fn.rs
Normal file
13
tests/codegen/array-from_fn.rs
Normal file
@ -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 _)
|
||||
}
|
Loading…
Reference in New Issue
Block a user