Skip to content

Commit f984df9

Browse files
authored
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 ```
1 parent e6ceffb commit f984df9

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

src/scope/lifetime/static_lifetime.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,16 @@ live for the entire duration, but only from the leaking point onward.
7373
extern crate rand;
7474
use rand::Fill;
7575
76-
fn random_vec() -> &'static [usize; 100] {
77-
let mut rng = rand::thread_rng();
76+
fn random_vec() -> &'static [u64; 100] {
77+
let mut rng = rand::rng();
7878
let mut boxed = Box::new([0; 100]);
79-
boxed.try_fill(&mut rng).unwrap();
79+
boxed.fill(&mut rng);
8080
Box::leak(boxed)
8181
}
8282
8383
fn main() {
84-
let first: &'static [usize; 100] = random_vec();
85-
let second: &'static [usize; 100] = random_vec();
84+
let first: &'static [u64; 100] = random_vec();
85+
let second: &'static [u64; 100] = random_vec();
8686
assert_ne!(first, second)
8787
}
8888
```

0 commit comments

Comments
 (0)