Fix clippy warnings in components/rand (#31549)

* resolved clippy warnings in components/rand

Signed-off-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local>

* replaced new() with default()

Signed-off-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local>

* replaced ServoRng::new() with ServoRng::default()

Signed-off-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local>

* moved the contents of the new() method into the default() method

Signed-off-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local>

---------

Signed-off-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local>
Co-authored-by: Sandeep Pillai <sandeeppillai@Sandeeps-MacBook-Air.local>
This commit is contained in:
sandeep 2024-03-08 04:46:42 +05:30 committed by GitHub
parent e4ac047a9c
commit 64d013d473
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 6 additions and 6 deletions

View file

@ -144,7 +144,7 @@ fn run_server(
}); });
// A token shared with the embedder to bypass permission prompt. // A token shared with the embedder to bypass permission prompt.
let token = format!("{:X}", servo_rand::ServoRng::new().next_u32()); let token = format!("{:X}", servo_rand::ServoRng::default().next_u32());
let port = bound.as_ref().map(|(_, port)| *port).ok_or(()); let port = bound.as_ref().map(|(_, port)| *port).ok_or(());
embedder.send((None, EmbedderMsg::OnDevtoolsStarted(port, token.clone()))); embedder.send((None, EmbedderMsg::OnDevtoolsStarted(port, token.clone())));

View file

@ -95,12 +95,12 @@ impl ServoRng {
} }
} }
impl ServoRng { impl Default for ServoRng {
/// Create an auto-reseeding instance of `ServoRng`. /// Create an auto-reseeding instance of `ServoRng`.
/// ///
/// This uses the shared `OsRng`, so avoids consuming /// This uses the shared `OsRng`, so avoids consuming
/// a file descriptor. /// a file descriptor.
pub fn new() -> ServoRng { fn default() -> Self {
trace!("Creating new ServoRng."); trace!("Creating new ServoRng.");
let mut os_rng = OS_RNG.lock().expect("Poisoned lock."); let mut os_rng = OS_RNG.lock().expect("Poisoned lock.");
let isaac_rng = IsaacCore::from_rng(&mut *os_rng).unwrap(); let isaac_rng = IsaacCore::from_rng(&mut *os_rng).unwrap();
@ -156,7 +156,7 @@ pub fn thread_rng() -> ServoThreadRng {
} }
thread_local! { thread_local! {
static SERVO_THREAD_RNG: ServoThreadRng = ServoThreadRng { rng: Rc::new(RefCell::new(ServoRng::new())) }; static SERVO_THREAD_RNG: ServoThreadRng = ServoThreadRng { rng: Rc::new(RefCell::new(ServoRng::default())) };
} }
impl RngCore for ServoThreadRng { impl RngCore for ServoThreadRng {

View file

@ -29,7 +29,7 @@ impl Crypto {
fn new_inherited() -> Crypto { fn new_inherited() -> Crypto {
Crypto { Crypto {
reflector_: Reflector::new(), reflector_: Reflector::new(),
rng: DomRefCell::new(ServoRng::new()), rng: DomRefCell::new(ServoRng::default()),
} }
} }

View file

@ -862,5 +862,5 @@ impl WebrenderIpcSender {
} }
lazy_static! { lazy_static! {
pub static ref PRIVILEGED_SECRET: u32 = servo_rand::ServoRng::new().next_u32(); pub static ref PRIVILEGED_SECRET: u32 = servo_rand::ServoRng::default().next_u32();
} }