rng ranges: Forbid use of panicky Rng::gen_range

Fixes #920
This commit is contained in:
Ian Jackson 2023-07-07 13:34:38 +01:00
parent b151237a7f
commit d1ed505b61
2 changed files with 2 additions and 0 deletions

View File

@ -1,3 +1,4 @@
disallowed-methods = [
{ path = "rand::Rng::gen_range", reason = "Prefer tor_basic_utils::RngExt::gen_range_checked to avoid uncontrolled panics, or gen_range_infallible if applicable" },
# { path = "std::time::SystemTime::now", reason = "prefer using SleepProvider::wallclock instead when possible" },
]

View File

@ -123,6 +123,7 @@ pub trait RngExt: Rng {
if range.is_empty() {
None
} else {
#[allow(clippy::disallowed_methods)]
Some(Rng::gen_range(self, range))
}
}