From f984df99719a030f1dd3173e79c55b0f6e5c5263 Mon Sep 17 00:00:00 2001 From: Ansel Bobrow Date: Fri, 23 Jan 2026 16:27:22 -0500 Subject: [PATCH] Update deprecated functions in `Box::leak` example Previously, this example wasn't compiling because of the deprecated `thread_rng` and `fill` functions. Upon making the changes the compiler suggests and swapping `usize` for `u64`, the example compiles properly. Here are the compile errors: ```sh Compiling playground v0.0.1 (/playground) warning: unused import: `rand::Fill` --> src/main.rs:2:5 | 2 | use rand::Fill; | ^^^^^^^^^^ | = note: `#[warn(unused_imports)]` (part of `#[warn(unused)]`) on by default warning: use of deprecated function `rand::thread_rng`: Renamed to `rng` --> src/main.rs:5:25 | 5 | let mut rng = rand::thread_rng(); | ^^^^^^^^^^ | = note: `#[warn(deprecated)]` on by default error[E0599]: no method named `try_fill` found for struct `Box<[{integer}; 100]>` in the current scope --> src/main.rs:7:11 | 7 | boxed.try_fill(&mut rng).unwrap(); | ^^^^^^^^ | help: there is a method `fill` with a similar name | 7 - boxed.try_fill(&mut rng).unwrap(); 7 + boxed.fill(&mut rng).unwrap(); | For more information about this error, try `rustc --explain E0599`. warning: `playground` (bin "playground") generated 2 warnings error: could not compile `playground` (bin "playground") due to 1 previous error; 2 warnings emitted ``` --- src/scope/lifetime/static_lifetime.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/scope/lifetime/static_lifetime.md b/src/scope/lifetime/static_lifetime.md index f4286f6675..aebf95c287 100644 --- a/src/scope/lifetime/static_lifetime.md +++ b/src/scope/lifetime/static_lifetime.md @@ -73,16 +73,16 @@ live for the entire duration, but only from the leaking point onward. extern crate rand; use rand::Fill; -fn random_vec() -> &'static [usize; 100] { - let mut rng = rand::thread_rng(); +fn random_vec() -> &'static [u64; 100] { + let mut rng = rand::rng(); let mut boxed = Box::new([0; 100]); - boxed.try_fill(&mut rng).unwrap(); + boxed.fill(&mut rng); Box::leak(boxed) } fn main() { - let first: &'static [usize; 100] = random_vec(); - let second: &'static [usize; 100] = random_vec(); + let first: &'static [u64; 100] = random_vec(); + let second: &'static [u64; 100] = random_vec(); assert_ne!(first, second) } ```