aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--components/allocator/lib.rs4
-rw-r--r--components/background_hang_monitor/background_hang_monitor.rs35
-rw-r--r--components/background_hang_monitor/sampler.rs9
-rw-r--r--components/background_hang_monitor/sampler_linux.rs16
-rw-r--r--components/background_hang_monitor/sampler_mac.rs2
-rw-r--r--components/background_hang_monitor/sampler_windows.rs2
-rw-r--r--components/dom_struct/lib.rs4
-rw-r--r--components/domobject_derive/lib.rs1
-rw-r--r--components/hyper_serde/lib.rs2
-rw-r--r--components/layout/display_list/builder.rs4
-rw-r--r--components/layout/parallel.rs9
-rw-r--r--components/media/lib.rs1
-rw-r--r--components/media/media_channel/mod.rs1
-rw-r--r--components/media/media_thread.rs8
-rw-r--r--components/pixels/lib.rs6
-rw-r--r--components/profile/mem.rs24
-rw-r--r--components/profile/time.rs36
-rw-r--r--components/profile/trace_dump.rs2
-rw-r--r--components/range/lib.rs5
-rw-r--r--components/remutex/lib.rs28
-rw-r--r--components/script/build.rs8
-rw-r--r--components/servo/lib.rs2
-rw-r--r--components/url/lib.rs2
-rw-r--r--components/webgpu/lib.rs14
24 files changed, 107 insertions, 118 deletions
diff --git a/components/allocator/lib.rs b/components/allocator/lib.rs
index f6cf47eada5..507c0e380f6 100644
--- a/components/allocator/lib.rs
+++ b/components/allocator/lib.rs
@@ -13,9 +13,7 @@ pub use crate::platform::*;
mod platform {
use std::os::raw::c_void;
- use jemallocator;
-
- pub use self::jemallocator::Jemalloc as Allocator;
+ pub use jemallocator::Jemalloc as Allocator;
/// Get the size of a heap block.
pub unsafe extern "C" fn usable_size(ptr: *const c_void) -> usize {
diff --git a/components/background_hang_monitor/background_hang_monitor.rs b/components/background_hang_monitor/background_hang_monitor.rs
index 1aacadfa19a..b364bcea7ca 100644
--- a/components/background_hang_monitor/background_hang_monitor.rs
+++ b/components/background_hang_monitor/background_hang_monitor.rs
@@ -92,19 +92,19 @@ impl BackgroundHangMonitorRegister for HangMonitorRegister {
target_os = "windows",
any(target_arch = "x86_64", target_arch = "x86")
))]
- let sampler = crate::sampler_windows::WindowsSampler::new();
+ let sampler = crate::sampler_windows::WindowsSampler::new_boxed();
#[cfg(target_os = "macos")]
- let sampler = crate::sampler_mac::MacOsSampler::new();
+ let sampler = crate::sampler_mac::MacOsSampler::new_boxed();
#[cfg(all(
target_os = "linux",
not(any(target_arch = "arm", target_arch = "aarch64"))
))]
- let sampler = crate::sampler_linux::LinuxSampler::new();
+ let sampler = crate::sampler_linux::LinuxSampler::new_boxed();
#[cfg(any(
target_os = "android",
all(target_os = "linux", any(target_arch = "arm", target_arch = "aarch64"))
))]
- let sampler = crate::sampler::DummySampler::new();
+ let sampler = crate::sampler::DummySampler::new_boxed();
// When a component is registered, and there's an exit request that
// reached BHM, we want an exit signal to be delivered to the
@@ -208,7 +208,7 @@ impl BackgroundHangMonitorChan {
BackgroundHangMonitorChan {
sender,
_tether: tether,
- component_id: component_id,
+ component_id,
disconnected: Default::default(),
monitoring_enabled,
}
@@ -312,14 +312,14 @@ struct BackgroundHangMonitorWorker {
monitoring_enabled: bool,
}
+type MonitoredComponentSender = Sender<(MonitoredComponentId, MonitoredComponentMsg)>;
+type MonitoredComponentReceiver = Receiver<(MonitoredComponentId, MonitoredComponentMsg)>;
+
impl BackgroundHangMonitorWorker {
fn new(
constellation_chan: IpcSender<HangMonitorAlert>,
control_port: IpcReceiver<BackgroundHangMonitorControlMsg>,
- (port_sender, port): (
- Arc<Sender<(MonitoredComponentId, MonitoredComponentMsg)>>,
- Receiver<(MonitoredComponentId, MonitoredComponentMsg)>,
- ),
+ (port_sender, port): (Arc<MonitoredComponentSender>, MonitoredComponentReceiver),
tether_port: Receiver<Never>,
monitoring_enabled: bool,
) -> Self {
@@ -360,7 +360,7 @@ impl BackgroundHangMonitorWorker {
let profile = stack.to_hangprofile();
let name = match self.component_names.get(&id) {
Some(ref s) => format!("\"{}\"", s),
- None => format!("null"),
+ None => "null".to_string(),
};
let json = format!(
"{}{{ \"name\": {}, \"namespace\": {}, \"index\": {}, \"type\": \"{:?}\", \
@@ -389,12 +389,10 @@ impl BackgroundHangMonitorWorker {
.checked_sub(Instant::now() - self.last_sample)
.unwrap_or_else(|| Duration::from_millis(0));
after(duration)
+ } else if self.monitoring_enabled {
+ after(Duration::from_millis(100))
} else {
- if self.monitoring_enabled {
- after(Duration::from_millis(100))
- } else {
- never()
- }
+ never()
};
let received = select! {
@@ -403,13 +401,8 @@ impl BackgroundHangMonitorWorker {
// gets disconnected.
Some(event.unwrap())
},
- recv(self.tether_port) -> event => {
+ recv(self.tether_port) -> _ => {
// This arm can only reached by a tether disconnection
- match event {
- Ok(x) => match x {}
- Err(_) => {}
- }
-
// All associated `HangMonitorRegister` and
// `BackgroundHangMonitorChan` have been dropped. Suppress
// `signal_to_exit` and exit the BHM.
diff --git a/components/background_hang_monitor/sampler.rs b/components/background_hang_monitor/sampler.rs
index 593401a08a5..82f6b7e0fde 100644
--- a/components/background_hang_monitor/sampler.rs
+++ b/components/background_hang_monitor/sampler.rs
@@ -4,7 +4,6 @@
use std::ptr;
-use backtrace;
use msg::constellation_msg::{HangProfile, HangProfileSymbol};
const MAX_NATIVE_FRAMES: usize = 1024;
@@ -18,7 +17,7 @@ pub struct DummySampler;
impl DummySampler {
#[allow(dead_code)]
- pub fn new() -> Box<dyn Sampler> {
+ pub fn new_boxed() -> Box<dyn Sampler> {
Box::new(DummySampler)
}
}
@@ -64,12 +63,12 @@ impl NativeStack {
instruction_ptr: *mut std::ffi::c_void,
stack_ptr: *mut std::ffi::c_void,
) -> Result<(), ()> {
- if !(self.count < MAX_NATIVE_FRAMES) {
+ if self.count >= MAX_NATIVE_FRAMES {
return Err(());
}
self.instruction_ptrs[self.count] = instruction_ptr;
self.stack_ptrs[self.count] = stack_ptr;
- self.count = self.count + 1;
+ self.count += 1;
Ok(())
}
@@ -85,7 +84,7 @@ impl NativeStack {
// TODO: use the demangled or C++ demangled symbols if available.
let name = symbol
.name()
- .map(|n| String::from_utf8_lossy(&n.as_bytes()).to_string());
+ .map(|n| String::from_utf8_lossy(n.as_bytes()).to_string());
let filename = symbol.filename().map(|n| n.to_string_lossy().to_string());
let lineno = symbol.lineno();
profile.backtrace.push(HangProfileSymbol {
diff --git a/components/background_hang_monitor/sampler_linux.rs b/components/background_hang_monitor/sampler_linux.rs
index b24edac3356..b392e49b06d 100644
--- a/components/background_hang_monitor/sampler_linux.rs
+++ b/components/background_hang_monitor/sampler_linux.rs
@@ -6,9 +6,8 @@
use std::cell::UnsafeCell;
use std::sync::atomic::{AtomicPtr, Ordering};
-use std::{io, mem, process, ptr, thread};
+use std::{cmp, io, mem, process, ptr, thread};
-use libc;
use nix::sys::signal::{sigaction, SaFlags, SigAction, SigHandler, SigSet, Signal};
use unwind_sys::{
unw_cursor_t, unw_get_reg, unw_init_local, unw_step, UNW_ESUCCESS, UNW_REG_IP, UNW_REG_SP,
@@ -138,7 +137,7 @@ pub struct LinuxSampler {
impl LinuxSampler {
#[allow(unsafe_code, dead_code)]
- pub fn new() -> Box<dyn Sampler> {
+ pub fn new_boxed() -> Box<dyn Sampler> {
let thread_id = unsafe { libc::syscall(libc::SYS_gettid) as libc::pid_t };
let handler = SigHandler::SigAction(sigprof_handler);
let action = SigAction::new(
@@ -181,12 +180,10 @@ fn step(cursor: *mut unw_cursor_t) -> Result<bool, i32> {
}
let ret = unw_step(cursor);
- if ret > 0 {
- Ok(true)
- } else if ret == 0 {
- Ok(false)
- } else {
- Err(ret)
+ match ret.cmp(&0) {
+ cmp::Ordering::Less => Err(ret),
+ cmp::Ordering::Greater => Ok(true),
+ cmp::Ordering::Equal => Ok(false),
}
}
}
@@ -222,6 +219,7 @@ impl Sampler for LinuxSampler {
let ret = unsafe { unw_init_local(cursor.as_mut_ptr(), context) };
result = if ret == UNW_ESUCCESS {
let mut native_stack = NativeStack::new();
+ #[allow(clippy::while_let_loop)] // False positive
loop {
let ip = match get_register(cursor.as_mut_ptr(), RegNum::Ip) {
Ok(ip) => ip,
diff --git a/components/background_hang_monitor/sampler_mac.rs b/components/background_hang_monitor/sampler_mac.rs
index ed85ef8d904..18b3be43a75 100644
--- a/components/background_hang_monitor/sampler_mac.rs
+++ b/components/background_hang_monitor/sampler_mac.rs
@@ -16,7 +16,7 @@ pub struct MacOsSampler {
impl MacOsSampler {
#[allow(unsafe_code)]
- pub fn new() -> Box<dyn Sampler> {
+ pub fn new_boxed() -> Box<dyn Sampler> {
let thread_id = unsafe { mach2::mach_init::mach_thread_self() };
Box::new(MacOsSampler { thread_id })
}
diff --git a/components/background_hang_monitor/sampler_windows.rs b/components/background_hang_monitor/sampler_windows.rs
index cbc88d42156..ed3b58cca1b 100644
--- a/components/background_hang_monitor/sampler_windows.rs
+++ b/components/background_hang_monitor/sampler_windows.rs
@@ -13,7 +13,7 @@ pub struct WindowsSampler {
impl WindowsSampler {
#[allow(unsafe_code, dead_code)]
- pub fn new() -> Box<dyn Sampler> {
+ pub fn new_boxed() -> Box<dyn Sampler> {
let thread_id = 0; // TODO: use winapi::um::processthreadsapi::GetThreadId
Box::new(WindowsSampler { thread_id })
}
diff --git a/components/dom_struct/lib.rs b/components/dom_struct/lib.rs
index 3cafbb48731..31b41459ebb 100644
--- a/components/dom_struct/lib.rs
+++ b/components/dom_struct/lib.rs
@@ -20,13 +20,13 @@ pub fn dom_struct(args: TokenStream, input: TokenStream) -> TokenStream {
// Work around https://github.com/rust-lang/rust/issues/46489
let attributes: TokenStream = attributes.to_string().parse().unwrap();
- let output: TokenStream = attributes.into_iter().chain(input.into_iter()).collect();
+ let output: TokenStream = attributes.into_iter().chain(input).collect();
let item: Item = syn::parse(output).unwrap();
if let Item::Struct(s) = item {
let s2 = s.clone();
- if s.generics.params.len() > 0 {
+ if !s.generics.params.is_empty() {
return quote!(#s2).into();
}
if let Fields::Named(ref f) = s.fields {
diff --git a/components/domobject_derive/lib.rs b/components/domobject_derive/lib.rs
index f15cc0be971..81c9b89be79 100644
--- a/components/domobject_derive/lib.rs
+++ b/components/domobject_derive/lib.rs
@@ -4,7 +4,6 @@
#![recursion_limit = "128"]
-use proc_macro2;
use quote::{quote, TokenStreamExt};
use syn::parse_quote;
diff --git a/components/hyper_serde/lib.rs b/components/hyper_serde/lib.rs
index 22f79c8ad65..bb48b1c47e5 100644
--- a/components/hyper_serde/lib.rs
+++ b/components/hyper_serde/lib.rs
@@ -531,7 +531,7 @@ impl<'a> Serialize for Ser<'a, Mime> {
where
S: Serializer,
{
- serializer.serialize_str(&self.v.as_ref())
+ serializer.serialize_str(self.v.as_ref())
}
}
diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs
index c813def2142..d453fdfe8e8 100644
--- a/components/layout/display_list/builder.rs
+++ b/components/layout/display_list/builder.rs
@@ -80,7 +80,7 @@ static THREAD_TINT_COLORS: [ColorF; 8] = [
a: 0.7,
},
ColorF {
- r: 255.0 / 255.0,
+ r: 1.0,
g: 212.0 / 255.0,
b: 83.0 / 255.0,
a: 0.7,
@@ -110,7 +110,7 @@ static THREAD_TINT_COLORS: [ColorF; 8] = [
a: 0.7,
},
ColorF {
- r: 255.0 / 255.0,
+ r: 1.0,
g: 249.0 / 255.0,
b: 201.0 / 255.0,
a: 0.7,
diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs
index cd15063ea57..22f542655cb 100644
--- a/components/layout/parallel.rs
+++ b/components/layout/parallel.rs
@@ -29,16 +29,23 @@ const CHUNK_SIZE: usize = 16;
pub type FlowList = SmallVec<[UnsafeFlow; CHUNK_SIZE]>;
/// Vtable + pointer representation of a Flow trait object.
-#[derive(Clone, Copy, Eq, PartialEq)]
+#[derive(Clone, Copy, Eq)]
pub struct UnsafeFlow(*const dyn Flow);
unsafe impl Sync for UnsafeFlow {}
unsafe impl Send for UnsafeFlow {}
+impl PartialEq for UnsafeFlow {
+ fn eq(&self, other: &Self) -> bool {
+ // Compare the pointers explicitly to avoid clippy lint
+ self.0 as *const u8 == other.0 as *const u8
+ }
+}
fn null_unsafe_flow() -> UnsafeFlow {
UnsafeFlow(ptr::null::<BlockFlow>())
}
+#[allow(clippy::not_unsafe_ptr_arg_deref)] // It has an unsafe block inside
pub fn mut_owned_flow_to_unsafe_flow(flow: *mut FlowRef) -> UnsafeFlow {
unsafe { UnsafeFlow(&**flow) }
}
diff --git a/components/media/lib.rs b/components/media/lib.rs
index e746d668ba1..f29493eb4b3 100644
--- a/components/media/lib.rs
+++ b/components/media/lib.rs
@@ -3,6 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
#![deny(unsafe_code)]
+#![allow(clippy::type_complexity)]
mod media_channel;
mod media_thread;
diff --git a/components/media/media_channel/mod.rs b/components/media/media_channel/mod.rs
index 21586e0456e..00259e4e499 100644
--- a/components/media/media_channel/mod.rs
+++ b/components/media/media_channel/mod.rs
@@ -74,6 +74,7 @@ where
}
}
+ #[allow(clippy::wrong_self_convention)] // It is an alias to the underlying module
pub fn to_opaque(self) -> ipc_channel::ipc::OpaqueIpcReceiver {
match self {
GLPlayerReceiver::Ipc(receiver) => receiver.to_opaque(),
diff --git a/components/media/media_thread.rs b/components/media/media_thread.rs
index c6cf45dbe2d..9bd556d6b72 100644
--- a/components/media/media_thread.rs
+++ b/components/media/media_thread.rs
@@ -79,14 +79,14 @@ impl GLPlayerThread {
}
},
GLPlayerMsg::Lock(id, handler_sender) => {
- self.players.get(&id).map(|sender| {
+ if let Some(sender) = self.players.get(&id) {
sender.send(GLPlayerMsgForward::Lock(handler_sender)).ok();
- });
+ }
},
GLPlayerMsg::Unlock(id) => {
- self.players.get(&id).map(|sender| {
+ if let Some(sender) = self.players.get(&id) {
sender.send(GLPlayerMsgForward::Unlock()).ok();
- });
+ }
},
GLPlayerMsg::Exit => return true,
}
diff --git a/components/pixels/lib.rs b/components/pixels/lib.rs
index d9a7fcc39d0..2b26af3dd7c 100644
--- a/components/pixels/lib.rs
+++ b/components/pixels/lib.rs
@@ -49,9 +49,7 @@ pub fn rgba8_get_rect(pixels: &[u8], size: Size2D<u64>, rect: Rect<u64>) -> Cow<
pub fn rgba8_byte_swap_colors_inplace(pixels: &mut [u8]) {
assert!(pixels.len() % 4 == 0);
for rgba in pixels.chunks_mut(4) {
- let b = rgba[0];
- rgba[0] = rgba[2];
- rgba[2] = b;
+ rgba.swap(0, 2);
}
}
@@ -79,7 +77,7 @@ pub fn rgba8_premultiply_inplace(pixels: &mut [u8]) -> bool {
}
pub fn multiply_u8_color(a: u8, b: u8) -> u8 {
- return (a as u32 * b as u32 / 255) as u8;
+ (a as u32 * b as u32 / 255) as u8
}
pub fn clip(
diff --git a/components/profile/mem.rs b/components/profile/mem.rs
index 53990d7f05f..0fdeb76715c 100644
--- a/components/profile/mem.rs
+++ b/components/profile/mem.rs
@@ -30,8 +30,8 @@ pub struct Profiler {
created: Instant,
}
-const JEMALLOC_HEAP_ALLOCATED_STR: &'static str = "jemalloc-heap-allocated";
-const SYSTEM_HEAP_ALLOCATED_STR: &'static str = "system-heap-allocated";
+const JEMALLOC_HEAP_ALLOCATED_STR: &str = "jemalloc-heap-allocated";
+const SYSTEM_HEAP_ALLOCATED_STR: &str = "system-heap-allocated";
impl Profiler {
pub fn create(period: Option<f64>) -> ProfilerChan {
@@ -84,7 +84,7 @@ impl Profiler {
pub fn new(port: IpcReceiver<ProfilerMsg>) -> Profiler {
Profiler {
- port: port,
+ port,
reporters: HashMap::new(),
created: Instant::now(),
}
@@ -212,7 +212,7 @@ impl Profiler {
println!("|");
println!("End memory reports");
- println!("");
+ println!();
}
}
@@ -239,7 +239,7 @@ impl ReportsTree {
ReportsTree {
size: 0,
count: 0,
- path_seg: path_seg,
+ path_seg,
children: vec![],
}
}
@@ -259,7 +259,7 @@ impl ReportsTree {
fn insert(&mut self, path: &[String], size: usize) {
let mut t: &mut ReportsTree = self;
for path_seg in path {
- let i = match t.find_child(&path_seg) {
+ let i = match t.find_child(path_seg) {
Some(i) => i,
None => {
let new_t = ReportsTree::new(path_seg.clone());
@@ -352,7 +352,7 @@ impl ReportsForest {
fn print(&mut self) {
// Fill in sizes of interior nodes, and recursively sort the sub-trees.
- for (_, tree) in &mut self.trees {
+ for tree in self.trees.values_mut() {
tree.compute_interior_node_sizes_and_sort();
}
@@ -360,7 +360,7 @@ impl ReportsForest {
// single node) come after non-degenerate trees. Secondary sort: alphabetical order of the
// root node's path_seg.
let mut v = vec![];
- for (_, tree) in &self.trees {
+ for tree in self.trees.values() {
v.push(tree);
}
v.sort_by(|a, b| {
@@ -412,9 +412,9 @@ mod system_reporter {
let mut report = |path, size| {
if let Some(size) = size {
reports.push(Report {
- path: path,
+ path,
kind: ReportKind::NonExplicitSize,
- size: size,
+ size,
});
}
};
@@ -663,7 +663,7 @@ mod system_reporter {
// Construct the segment name from its pathname and permissions.
curr_seg_name.clear();
- if pathname == "" || pathname.starts_with("[stack:") {
+ if pathname.is_empty() || pathname.starts_with("[stack:") {
// Anonymous memory. Entries marked with "[stack:nnn]"
// look like thread stacks but they may include other
// anonymous mappings, so we can't trust them and just
@@ -674,7 +674,7 @@ mod system_reporter {
}
curr_seg_name.push_str(" (");
curr_seg_name.push_str(perms);
- curr_seg_name.push_str(")");
+ curr_seg_name.push(')');
looking_for = LookingFor::Rss;
} else {
diff --git a/components/profile/time.rs b/components/profile/time.rs
index e54542b9a8a..f07e273735d 100644
--- a/components/profile/time.rs
+++ b/components/profile/time.rs
@@ -184,9 +184,9 @@ impl Profiler {
})
.expect("Thread spawning failed");
// decide if we need to spawn the timer thread
- match option {
- &OutputOptions::FileName(_) => { /* no timer thread needed */ },
- &OutputOptions::Stdout(period) => {
+ match *option {
+ OutputOptions::FileName(_) => { /* no timer thread needed */ },
+ OutputOptions::Stdout(period) => {
// Spawn a timer thread
let chan = chan.clone();
thread::Builder::new()
@@ -241,11 +241,11 @@ impl Profiler {
output: Option<OutputOptions>,
) -> Profiler {
Profiler {
- port: port,
+ port,
buckets: BTreeMap::new(),
- output: output,
+ output,
last_msg: None,
- trace: trace,
+ trace,
blocked_layout_queries: HashMap::new(),
}
}
@@ -259,7 +259,7 @@ impl Profiler {
}
fn find_or_insert(&mut self, k: (ProfilerCategory, Option<TimerMetadata>), t: f64) {
- self.buckets.entry(k).or_insert_with(Vec::new).push(t);
+ self.buckets.entry(k).or_default().push(t);
}
fn handle_msg(&mut self, msg: ProfilerMsg) -> bool {
@@ -321,24 +321,24 @@ impl Profiler {
match self.output {
Some(OutputOptions::FileName(ref filename)) => {
let path = Path::new(&filename);
- let mut file = match File::create(&path) {
+ let mut file = match File::create(path) {
Err(e) => panic!("Couldn't create {}: {}", path.display(), e),
Ok(file) => file,
};
- write!(
+ writeln!(
file,
"_category_\t_incremental?_\t_iframe?_\t_url_\t_mean (ms)_\t\
- _median (ms)_\t_min (ms)_\t_max (ms)_\t_events_\n"
+ _median (ms)_\t_min (ms)_\t_max (ms)_\t_events_"
)
.unwrap();
- for (&(ref category, ref meta), ref mut data) in &mut self.buckets {
+ for ((category, meta), ref mut data) in &mut self.buckets {
data.sort_by(|a, b| a.partial_cmp(b).expect("No NaN values in profiles"));
let data_len = data.len();
if data_len > 0 {
let (mean, median, min, max) = Self::get_statistics(data);
- write!(
+ writeln!(
file,
- "{}\t{}\t{:15.4}\t{:15.4}\t{:15.4}\t{:15.4}\t{:15}\n",
+ "{}\t{}\t{:15.4}\t{:15.4}\t{:15.4}\t{:15.4}\t{:15}",
category.format(&self.output),
meta.format(&self.output),
mean,
@@ -351,9 +351,9 @@ impl Profiler {
}
}
- write!(file, "_url\t_blocked layout queries_\n").unwrap();
+ writeln!(file, "_url\t_blocked layout queries_").unwrap();
for (url, count) in &self.blocked_layout_queries {
- write!(file, "{}\t{}\n", url, count).unwrap();
+ writeln!(file, "{}\t{}", url, count).unwrap();
}
},
Some(OutputOptions::Stdout(_)) => {
@@ -374,7 +374,7 @@ impl Profiler {
" _events_"
)
.unwrap();
- for (&(ref category, ref meta), ref mut data) in &mut self.buckets {
+ for ((category, meta), ref mut data) in &mut self.buckets {
data.sort_by(|a, b| a.partial_cmp(b).expect("No NaN values in profiles"));
let data_len = data.len();
if data_len > 0 {
@@ -393,13 +393,13 @@ impl Profiler {
.unwrap();
}
}
- writeln!(&mut lock, "").unwrap();
+ writeln!(&mut lock).unwrap();
writeln!(&mut lock, "_url_\t_blocked layout queries_").unwrap();
for (url, count) in &self.blocked_layout_queries {
writeln!(&mut lock, "{}\t{}", url, count).unwrap();
}
- writeln!(&mut lock, "").unwrap();
+ writeln!(&mut lock).unwrap();
},
None => { /* Do nothing if no output option has been set */ },
};
diff --git a/components/profile/trace_dump.rs b/components/profile/trace_dump.rs
index 3051e08ee11..66614a28b98 100644
--- a/components/profile/trace_dump.rs
+++ b/components/profile/trace_dump.rs
@@ -37,7 +37,7 @@ impl TraceDump {
{
let mut file = fs::File::create(trace_file_path)?;
write_prologue(&mut file)?;
- Ok(TraceDump { file: file })
+ Ok(TraceDump { file })
}
/// Write one trace to the trace dump file.
diff --git a/components/range/lib.rs b/components/range/lib.rs
index 6b98b68a658..8c5ca095f53 100644
--- a/components/range/lib.rs
+++ b/components/range/lib.rs
@@ -204,10 +204,7 @@ impl<I: RangeIndex> Range<I> {
/// ~~~
#[inline]
pub fn new(begin: I, length: I) -> Range<I> {
- Range {
- begin: begin,
- length: length,
- }
+ Range { begin, length }
}
#[inline]
diff --git a/components/remutex/lib.rs b/components/remutex/lib.rs
index 94efae26199..9ee51305a45 100644
--- a/components/remutex/lib.rs
+++ b/components/remutex/lib.rs
@@ -36,7 +36,7 @@ impl ThreadId {
ThreadId(NonZeroUsize::new(number).unwrap())
}
pub fn current() -> ThreadId {
- THREAD_ID.with(|tls| tls.clone())
+ THREAD_ID.with(|tls| *tls)
}
}
@@ -46,10 +46,13 @@ thread_local! { static THREAD_ID: ThreadId = ThreadId::new() }
#[derive(Debug)]
pub struct AtomicOptThreadId(AtomicUsize);
-impl AtomicOptThreadId {
- pub fn new() -> AtomicOptThreadId {
+impl Default for AtomicOptThreadId {
+ fn default() -> Self {
AtomicOptThreadId(AtomicUsize::new(0))
}
+}
+
+impl AtomicOptThreadId {
pub fn store(&self, value: Option<ThreadId>, ordering: Ordering) {
let number = value.map(|id| id.0.get()).unwrap_or(0);
self.0.store(number, ordering);
@@ -75,14 +78,17 @@ pub struct HandOverHandMutex {
guard: UnsafeCell<Option<MutexGuard<'static, ()>>>,
}
-impl HandOverHandMutex {
- pub fn new() -> HandOverHandMutex {
- HandOverHandMutex {
+impl Default for HandOverHandMutex {
+ fn default() -> Self {
+ Self {
mutex: Mutex::new(()),
- owner: AtomicOptThreadId::new(),
+ owner: AtomicOptThreadId::default(),
guard: UnsafeCell::new(None),
}
}
+}
+
+impl HandOverHandMutex {
#[allow(unsafe_code)]
unsafe fn set_guard_and_owner<'a>(&'a self, guard: MutexGuard<'a, ()>) {
// The following two lines allow us to unsafely store
@@ -107,7 +113,7 @@ impl HandOverHandMutex {
assert_eq!(old_owner, Some(ThreadId::current()));
}
#[allow(unsafe_code)]
- pub fn lock<'a>(&'a self) -> LockResult<()> {
+ pub fn lock(&self) -> LockResult<()> {
let (guard, result) = match self.mutex.lock() {
Ok(guard) => (guard, Ok(())),
Err(err) => (err.into_inner(), Err(PoisonError::new(()))),
@@ -163,9 +169,9 @@ impl<T> ReentrantMutex<T> {
pub fn new(data: T) -> ReentrantMutex<T> {
trace!("{:?} Creating new lock.", ThreadId::current());
ReentrantMutex {
- mutex: HandOverHandMutex::new(),
+ mutex: HandOverHandMutex::default(),
count: Cell::new(0),
- data: data,
+ data,
}
}
@@ -173,7 +179,7 @@ impl<T> ReentrantMutex<T> {
trace!("{:?} Locking.", ThreadId::current());
if self.mutex.owner() != Some(ThreadId::current()) {
trace!("{:?} Becoming owner.", ThreadId::current());
- if let Err(_) = self.mutex.lock() {
+ if self.mutex.lock().is_err() {
trace!("{:?} Poison!", ThreadId::current());
return Err(PoisonError::new(self.mk_guard()));
}
diff --git a/components/script/build.rs b/components/script/build.rs
index 3fabbeee1fa..d002cdb6982 100644
--- a/components/script/build.rs
+++ b/components/script/build.rs
@@ -31,16 +31,16 @@ fn main() {
println!("Binding generation completed in {:?}", start.elapsed());
let json = out_dir.join("InterfaceObjectMapData.json");
- let json: Value = serde_json::from_reader(File::open(&json).unwrap()).unwrap();
+ let json: Value = serde_json::from_reader(File::open(json).unwrap()).unwrap();
let mut map = phf_codegen::Map::new();
for (key, value) in json.as_object().unwrap() {
map.entry(Bytes(key), value.as_str().unwrap());
}
let phf = PathBuf::from(env::var_os("OUT_DIR").unwrap()).join("InterfaceObjectMapPhf.rs");
- let mut phf = File::create(&phf).unwrap();
- write!(
+ let mut phf = File::create(phf).unwrap();
+ writeln!(
&mut phf,
- "pub static MAP: phf::Map<&'static [u8], fn(JSContext, HandleObject)> = {};\n",
+ "pub static MAP: phf::Map<&'static [u8], fn(JSContext, HandleObject)> = {};",
map.build(),
)
.unwrap();
diff --git a/components/servo/lib.rs b/components/servo/lib.rs
index 4b78eac3106..7c25f74df8b 100644
--- a/components/servo/lib.rs
+++ b/components/servo/lib.rs
@@ -387,7 +387,7 @@ where
embedder.register_webxr(&mut webxr_main_thread, embedder_proxy.clone());
}
- let wgpu_image_handler = webgpu::WGPUExternalImages::new();
+ let wgpu_image_handler = webgpu::WGPUExternalImages::default();
let wgpu_image_map = wgpu_image_handler.images.clone();
external_image_handlers.set_handler(
Box::new(wgpu_image_handler),
diff --git a/components/url/lib.rs b/components/url/lib.rs
index f9576cce161..89ff2c3f96b 100644
--- a/components/url/lib.rs
+++ b/components/url/lib.rs
@@ -176,7 +176,7 @@ impl ServoUrl {
// Strip `scheme://`, which is hardly useful for identifying websites
let mut st = self.as_str();
st = st.strip_prefix(self.scheme()).unwrap_or(st);
- st = st.strip_prefix(":").unwrap_or(st);
+ st = st.strip_prefix(':').unwrap_or(st);
st = st.trim_start_matches('/');
// Don't want to return an empty string
diff --git a/components/webgpu/lib.rs b/components/webgpu/lib.rs
index 7f95db0850f..20a1b0cdaa8 100644
--- a/components/webgpu/lib.rs
+++ b/components/webgpu/lib.rs
@@ -919,8 +919,8 @@ impl<'a> WGPU<'a> {
pipeline_id,
} => {
let desc = DeviceDescriptor {
- label: descriptor.label.as_ref().map(|l| crate::Cow::from(l)),
- features: descriptor.features.clone(),
+ label: descriptor.label.as_ref().map(crate::Cow::from),
+ features: descriptor.features,
limits: descriptor.limits.clone(),
};
let global = &self.global;
@@ -1336,20 +1336,12 @@ webgpu_resource!(WebGPUSurface, id::SurfaceId);
webgpu_resource!(WebGPUTexture, id::TextureId);
webgpu_resource!(WebGPUTextureView, id::TextureViewId);
+#[derive(Default)]
pub struct WGPUExternalImages {
pub images: Arc<Mutex<HashMap<u64, PresentationData>>>,
pub locked_ids: HashMap<u64, Vec<u8>>,
}
-impl WGPUExternalImages {
- pub fn new() -> Self {
- Self {
- images: Arc::new(Mutex::new(HashMap::new())),
- locked_ids: HashMap::new(),
- }
- }
-}
-
impl WebrenderExternalImageApi for WGPUExternalImages {
fn lock(&mut self, id: u64) -> (WebrenderImageSource, Size2D<i32>) {
let size;