diff options
| author | bors <bors@rust-lang.org> | 2022-06-08 23:07:22 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-06-08 23:07:22 +0000 |
| commit | 15f5622a53210099a19ab46ce2316494fb413d7c (patch) | |
| tree | 633084d6eb33de525f55ae47663320370d9e6fc0 /library/std | |
| parent | 7466d5492b2d28d2ba5114dbe71511a6502ac822 (diff) | |
| parent | cfc0677992662076f8fa65062a229aaae495f030 (diff) | |
| download | rust-15f5622a53210099a19ab46ce2316494fb413d7c.tar.gz rust-15f5622a53210099a19ab46ce2316494fb413d7c.zip | |
Auto merge of #97896 - compiler-errors:rollup-mrl7ng0, r=compiler-errors
Rollup of 9 pull requests Successful merges: - #97557 (Fix indices and remove some unwraps in arg mismatch algorithm) - #97830 (Add std::alloc::set_alloc_error_hook example) - #97856 (Don't suggest adding `let` in certain `if` conditions) - #97857 (Suggest escaping `box` as identifier) - #97871 (Suggest using `iter()` or `into_iter()` for `Vec`) - #97882 (Add regresion test for #67498) - #97883 (Remove `ignore-compare-mode-nll` annotations from tests) - #97891 (Update books) - #97894 (Fix polonius compare mode.) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std')
| -rw-r--r-- | library/std/src/alloc.rs | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/library/std/src/alloc.rs b/library/std/src/alloc.rs index 63c527b64da..d3879273f5b 100644 --- a/library/std/src/alloc.rs +++ b/library/std/src/alloc.rs @@ -296,6 +296,20 @@ static HOOK: AtomicPtr<()> = AtomicPtr::new(ptr::null_mut()); /// about the allocation that failed. /// /// The allocation error hook is a global resource. +/// +/// # Examples +/// +/// ``` +/// #![feature(alloc_error_hook)] +/// +/// use std::alloc::{Layout, set_alloc_error_hook}; +/// +/// fn custom_alloc_error_hook(layout: Layout) { +/// panic!("memory allocation of {} bytes failed", layout.size()); +/// } +/// +/// set_alloc_error_hook(custom_alloc_error_hook); +/// ``` #[unstable(feature = "alloc_error_hook", issue = "51245")] pub fn set_alloc_error_hook(hook: fn(Layout)) { HOOK.store(hook as *mut (), Ordering::SeqCst); |
