Fix more clippy (#32740)

This commit is contained in:
石蕊 (Pi-Cla) 2024-07-09 04:47:43 +00:00 committed by GitHub
parent 4e1f623666
commit f29dd64a7b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
25 changed files with 72 additions and 90 deletions

View file

@ -157,14 +157,12 @@ impl Actor for BrowsingContextActor {
fn handle_message( fn handle_message(
&self, &self,
_registry: &ActorRegistry, _registry: &ActorRegistry,
msg_type: &str, _msg_type: &str,
_msg: &Map<String, Value>, _msg: &Map<String, Value>,
_stream: &mut TcpStream, _stream: &mut TcpStream,
_id: StreamId, _id: StreamId,
) -> Result<ActorMessageStatus, ()> { ) -> Result<ActorMessageStatus, ()> {
Ok(match msg_type { Ok(ActorMessageStatus::Ignored)
_ => ActorMessageStatus::Ignored,
})
} }
fn cleanup(&self, id: StreamId) { fn cleanup(&self, id: StreamId) {

View file

@ -193,11 +193,8 @@ impl Actor for WatcherActor {
let target = let target =
registry.find::<BrowsingContextActor>(&self.browsing_context_actor); registry.find::<BrowsingContextActor>(&self.browsing_context_actor);
match resource { if resource == "document-event" {
"document-event" => { target.document_event(stream);
target.document_event(stream);
},
_ => {},
} }
let _ = stream.write_json_packet(&EmptyReplyMsg { from: self.name() }); let _ = stream.write_json_packet(&EmptyReplyMsg { from: self.name() });

View file

@ -1505,7 +1505,7 @@ impl Fragment {
if let Some(ref inline_fragment_context) = self.inline_context { if let Some(ref inline_fragment_context) = self.inline_context {
for node in &inline_fragment_context.nodes { for node in &inline_fragment_context.nodes {
if node.style.get_box().position == Position::Relative { if node.style.get_box().position == Position::Relative {
rel_pos = rel_pos + from_style(&*node.style, containing_block_size); rel_pos = rel_pos + from_style(&node.style, containing_block_size);
} }
} }
} }

View file

@ -1711,14 +1711,14 @@ impl InlineFormattingContext {
} }
fn next_character_prevents_soft_wrap_opportunity(&self, index: usize) -> bool { fn next_character_prevents_soft_wrap_opportunity(&self, index: usize) -> bool {
let Some(character) = self.text_content[index..].chars().skip(1).next() else { let Some(character) = self.text_content[index..].chars().nth(1) else {
return false; return false;
}; };
char_prevents_soft_wrap_opportunity_when_before_or_after_atomic(character) char_prevents_soft_wrap_opportunity_when_before_or_after_atomic(character)
} }
fn previous_character_prevents_soft_wrap_opportunity(&self, index: usize) -> bool { fn previous_character_prevents_soft_wrap_opportunity(&self, index: usize) -> bool {
let Some(character) = self.text_content[0..index].chars().rev().next() else { let Some(character) = self.text_content[0..index].chars().next_back() else {
return false; return false;
}; };
char_prevents_soft_wrap_opportunity_when_before_or_after_atomic(character) char_prevents_soft_wrap_opportunity_when_before_or_after_atomic(character)

View file

@ -306,9 +306,7 @@ impl Layout for LayoutThread {
} }
fn query_content_box(&self, node: OpaqueNode) -> Option<UntypedRect<Au>> { fn query_content_box(&self, node: OpaqueNode) -> Option<UntypedRect<Au>> {
let Some(mut root_flow) = self.root_flow_for_query() else { let mut root_flow = self.root_flow_for_query()?;
return None;
};
let root_flow_ref = FlowRef::deref_mut(&mut root_flow); let root_flow_ref = FlowRef::deref_mut(&mut root_flow);
process_content_box_request(node, root_flow_ref) process_content_box_request(node, root_flow_ref)
@ -1010,7 +1008,7 @@ impl LayoutThread {
for stylesheet in &ua_stylesheets.user_or_user_agent_stylesheets { for stylesheet in &ua_stylesheets.user_or_user_agent_stylesheets {
self.stylist self.stylist
.append_stylesheet(stylesheet.clone(), &ua_or_user_guard); .append_stylesheet(stylesheet.clone(), &ua_or_user_guard);
self.load_all_web_fonts_from_stylesheet_with_guard(&stylesheet, &ua_or_user_guard); self.load_all_web_fonts_from_stylesheet_with_guard(stylesheet, &ua_or_user_guard);
} }
if self.stylist.quirks_mode() != QuirksMode::NoQuirks { if self.stylist.quirks_mode() != QuirksMode::NoQuirks {

View file

@ -178,10 +178,10 @@ where
} }
#[inline] #[inline]
pub fn get<Q: ?Sized>(&self, k: &Q) -> Option<&V> pub fn get<Q>(&self, k: &Q) -> Option<&V>
where where
K: std::borrow::Borrow<Q>, K: std::borrow::Borrow<Q>,
Q: Hash + Eq, Q: Hash + Eq + ?Sized,
{ {
self.0.get(k) self.0.get(k)
} }

View file

@ -2987,9 +2987,10 @@ impl Document {
/// <https://drafts.csswg.org/resize-observer/#deliver-resize-loop-error-notification> /// <https://drafts.csswg.org/resize-observer/#deliver-resize-loop-error-notification>
pub(crate) fn deliver_resize_loop_error_notification(&self) { pub(crate) fn deliver_resize_loop_error_notification(&self) {
let global_scope = self.window.upcast::<GlobalScope>(); let global_scope = self.window.upcast::<GlobalScope>();
let mut error_info: ErrorInfo = Default::default(); let error_info: ErrorInfo = crate::dom::bindings::error::ErrorInfo {
error_info.message = message: "ResizeObserver loop completed with undelivered notifications.".to_string(),
"ResizeObserver loop completed with undelivered notifications.".to_string(); ..Default::default()
};
global_scope.report_an_error(error_info, HandleValue::null()); global_scope.report_an_error(error_info, HandleValue::null());
} }
} }

View file

@ -3107,7 +3107,7 @@ impl GlobalScope {
DeviceLostReason::Unknown => GPUDeviceLostReason::Unknown, DeviceLostReason::Unknown => GPUDeviceLostReason::Unknown,
DeviceLostReason::Destroyed => GPUDeviceLostReason::Destroyed, DeviceLostReason::Destroyed => GPUDeviceLostReason::Destroyed,
}; };
let _ac = enter_realm(&*self); let _ac = enter_realm(self);
if let Some(device) = self if let Some(device) = self
.gpu_devices .gpu_devices
.borrow_mut() .borrow_mut()

View file

@ -780,7 +780,7 @@ impl HTMLMediaElement {
// Step 9.obj. // Step 9.obj.
Mode::Object => { Mode::Object => {
// Step 9.obj.1. // Step 9.obj.1.
*self.current_src.borrow_mut() = "".to_owned(); "".clone_into(&mut self.current_src.borrow_mut());
// Step 9.obj.2. // Step 9.obj.2.
// FIXME(nox): The rest of the steps should be ran in parallel. // FIXME(nox): The rest of the steps should be ran in parallel.

View file

@ -88,11 +88,8 @@ impl HTMLMetaElement {
// https://html.spec.whatwg.org/multipage/#attr-meta-http-equiv // https://html.spec.whatwg.org/multipage/#attr-meta-http-equiv
} else if !self.HttpEquiv().is_empty() { } else if !self.HttpEquiv().is_empty() {
// TODO: Implement additional http-equiv candidates // TODO: Implement additional http-equiv candidates
match self.HttpEquiv().to_ascii_lowercase().as_str() { if self.HttpEquiv().to_ascii_lowercase().as_str() == "refresh" {
"refresh" => { self.declarative_refresh();
self.declarative_refresh();
},
_ => {},
} }
} }
} }

View file

@ -529,7 +529,7 @@ impl RequestMethods for Request {
// https://fetch.spec.whatwg.org/#dom-request-url // https://fetch.spec.whatwg.org/#dom-request-url
fn Url(&self) -> USVString { fn Url(&self) -> USVString {
let r = self.request.borrow(); let r = self.request.borrow();
USVString(r.url_list.get(0).map_or("", |u| u.as_str()).into()) USVString(r.url_list.first().map_or("", |u| u.as_str()).into())
} }
// https://fetch.spec.whatwg.org/#dom-request-headers // https://fetch.spec.whatwg.org/#dom-request-headers

View file

@ -118,11 +118,11 @@ impl ResizeObserver {
let height = box_size.height().to_f64_px(); let height = box_size.height().to_f64_px();
let size_impl = ResizeObserverSizeImpl::new(width, height); let size_impl = ResizeObserverSizeImpl::new(width, height);
let window = window_from_node(&**target); let window = window_from_node(&**target);
let observer_size = ResizeObserverSize::new(&*window, size_impl); let observer_size = ResizeObserverSize::new(&window, size_impl);
// Note: content rect is built from content box size. // Note: content rect is built from content box size.
let content_rect = DOMRectReadOnly::new( let content_rect = DOMRectReadOnly::new(
&*window.upcast(), window.upcast(),
None, None,
box_size.origin.x.to_f64_px(), box_size.origin.x.to_f64_px(),
box_size.origin.y.to_f64_px(), box_size.origin.y.to_f64_px(),
@ -130,9 +130,9 @@ impl ResizeObserver {
height, height,
); );
let entry = ResizeObserverEntry::new( let entry = ResizeObserverEntry::new(
&*window, &window,
target, target,
&*content_rect, &content_rect,
&[], &[],
&[&*observer_size], &[&*observer_size],
&[], &[],

View file

@ -206,10 +206,10 @@ impl RTCPeerConnection {
let signaller = this.make_signaller(); let signaller = this.make_signaller();
*this.controller.borrow_mut() = Some(ServoMedia::get().unwrap().create_webrtc(signaller)); *this.controller.borrow_mut() = Some(ServoMedia::get().unwrap().create_webrtc(signaller));
if let Some(ref servers) = config.iceServers { if let Some(ref servers) = config.iceServers {
if let Some(server) = servers.get(0) { if let Some(server) = servers.first() {
let server = match server.urls { let server = match server.urls {
StringOrStringSequence::String(ref s) => Some(s.clone()), StringOrStringSequence::String(ref s) => Some(s.clone()),
StringOrStringSequence::StringSequence(ref s) => s.get(0).cloned(), StringOrStringSequence::StringSequence(ref s) => s.first().cloned(),
}; };
if let Some(server) = server { if let Some(server) = server {
let policy = match config.bundlePolicy { let policy = match config.bundlePolicy {

View file

@ -134,7 +134,7 @@ fn start_element<S: Serializer>(node: &Element, serializer: &mut S) -> io::Resul
}) })
.collect::<Vec<_>>(); .collect::<Vec<_>>();
let attr_refs = attrs.iter().map(|(qname, value)| { let attr_refs = attrs.iter().map(|(qname, value)| {
let ar: AttrRef = (&qname, &**value); let ar: AttrRef = (qname, &**value);
ar ar
}); });
serializer.start_elem(name, attr_refs)?; serializer.start_elem(name, attr_refs)?;

View file

@ -622,8 +622,8 @@ impl TestBindingMethods for TestBinding {
arg.type_.as_ref().map(|s| s == "success").unwrap_or(false) && arg.type_.as_ref().map(|s| s == "success").unwrap_or(false) &&
arg.nonRequiredNullable.is_none() && arg.nonRequiredNullable.is_none() &&
arg.nonRequiredNullable2 == Some(None) && arg.nonRequiredNullable2 == Some(None) &&
arg.noCallbackImport == None && arg.noCallbackImport.is_none() &&
arg.noCallbackImport2 == None arg.noCallbackImport2.is_none()
} }
fn PassBoolean(&self, _: bool) {} fn PassBoolean(&self, _: bool) {}

View file

@ -3134,16 +3134,14 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
let buff = IpcSharedMemory::from_bytes(unsafe { &src_data.as_slice()[src_byte_offset..] }); let buff = IpcSharedMemory::from_bytes(unsafe { &src_data.as_slice()[src_byte_offset..] });
let expected_byte_length = match { let expected_byte_length = match self.base.validate_tex_image_2d_data(
self.base.validate_tex_image_2d_data( width,
width, height,
height, format,
format, data_type,
data_type, unpacking_alignment,
unpacking_alignment, Some(&*src_data),
Some(&*src_data), ) {
)
} {
Ok(byte_length) => byte_length, Ok(byte_length) => byte_length,
Err(()) => return Ok(()), Err(()) => return Ok(()),
}; };
@ -3968,7 +3966,7 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
buffer.map(|b| b.id()), buffer.map(|b| b.id()),
)); ));
for slot in &[&generic_slot, &indexed_binding.buffer] { for slot in &[generic_slot, &indexed_binding.buffer] {
if let Some(old) = slot.get() { if let Some(old) = slot.get() {
old.decrement_attached_counter(Operation::Infallible); old.decrement_attached_counter(Operation::Infallible);
} }
@ -4046,7 +4044,7 @@ impl WebGL2RenderingContextMethods for WebGL2RenderingContext {
size, size,
)); ));
for slot in &[&generic_slot, &indexed_binding.buffer] { for slot in &[generic_slot, &indexed_binding.buffer] {
if let Some(old) = slot.get() { if let Some(old) = slot.get() {
old.decrement_attached_counter(Operation::Infallible); old.decrement_attached_counter(Operation::Infallible);
} }

View file

@ -279,11 +279,11 @@ impl WebGLExtensions {
} }
pub fn is_tex_type_enabled(&self, data_type: GLenum) -> bool { pub fn is_tex_type_enabled(&self, data_type: GLenum) -> bool {
self.features !self
.features
.borrow() .borrow()
.disabled_tex_types .disabled_tex_types
.get(&data_type) .contains(&data_type)
.is_none()
} }
pub fn add_effective_tex_internal_format( pub fn add_effective_tex_internal_format(
@ -321,11 +321,11 @@ impl WebGLExtensions {
} }
pub fn is_filterable(&self, text_data_type: u32) -> bool { pub fn is_filterable(&self, text_data_type: u32) -> bool {
self.features !self
.features
.borrow() .borrow()
.not_filterable_tex_types .not_filterable_tex_types
.get(&text_data_type) .contains(&text_data_type)
.is_none()
} }
pub fn enable_hint_target(&self, name: GLenum) { pub fn enable_hint_target(&self, name: GLenum) {

View file

@ -4292,16 +4292,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
let unpacking_alignment = self.texture_unpacking_alignment.get(); let unpacking_alignment = self.texture_unpacking_alignment.get();
let expected_byte_length = match { let expected_byte_length = match self.validate_tex_image_2d_data(
self.validate_tex_image_2d_data( width,
width, height,
height, format,
format, data_type,
data_type, unpacking_alignment,
unpacking_alignment, pixels.as_ref(),
pixels.as_ref(), ) {
)
} {
Ok(byte_length) => byte_length, Ok(byte_length) => byte_length,
Err(()) => return Ok(()), Err(()) => return Ok(()),
}; };
@ -4479,16 +4477,14 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
let unpacking_alignment = self.texture_unpacking_alignment.get(); let unpacking_alignment = self.texture_unpacking_alignment.get();
let expected_byte_length = match { let expected_byte_length = match self.validate_tex_image_2d_data(
self.validate_tex_image_2d_data( width,
width, height,
height, format,
format, data_type,
data_type, unpacking_alignment,
unpacking_alignment, pixels.as_ref(),
pixels.as_ref(), ) {
)
} {
Ok(byte_length) => byte_length, Ok(byte_length) => byte_length,
Err(()) => return Ok(()), Err(()) => return Ok(()),
}; };

View file

@ -1053,7 +1053,7 @@ impl XMLHttpRequest {
}, },
}; };
*self.response_url.borrow_mut() = metadata.final_url[..Position::AfterQuery].to_owned(); metadata.final_url[..Position::AfterQuery].clone_into(&mut self.response_url.borrow_mut());
// XXXManishearth Clear cache entries in case of a network error // XXXManishearth Clear cache entries in case of a network error
self.process_partial_response(XHRProgress::HeadersReceived( self.process_partial_response(XHRProgress::HeadersReceived(

View file

@ -438,10 +438,7 @@ impl XRSession {
self.outside_raf.set(false); self.outside_raf.set(false);
let len = self.current_raf_callback_list.borrow().len(); let len = self.current_raf_callback_list.borrow().len();
for i in 0..len { for i in 0..len {
let callback = self.current_raf_callback_list.borrow()[i] let callback = self.current_raf_callback_list.borrow()[i].1.clone();
.1
.as_ref()
.map(Rc::clone);
if let Some(callback) = callback { if let Some(callback) = callback {
let _ = callback.Call__(time, &frame, ExceptionHandling::Report); let _ = callback.Call__(time, &frame, ExceptionHandling::Report);
} }

View file

@ -9,7 +9,7 @@
// crate. Issue a warning if `crown` is not being used to compile, but not when // crate. Issue a warning if `crown` is not being used to compile, but not when
// building rustdoc or running clippy. // building rustdoc or running clippy.
#![register_tool(crown)] #![register_tool(crown)]
#![cfg_attr(any(doc, clippy, feature = "cargo-clippy"), allow(unknown_lints))] #![cfg_attr(any(doc, clippy), allow(unknown_lints))]
#![deny(crown_is_not_used)] #![deny(crown_is_not_used)]
// These are used a lot so let's keep them for now // These are used a lot so let's keep them for now

View file

@ -578,7 +578,7 @@ impl ModuleTree {
let url = ModuleTree::resolve_module_specifier( let url = ModuleTree::resolve_module_specifier(
*cx, *cx,
&base_url, base_url,
specifier.handle().into_handle(), specifier.handle().into_handle(),
); );
@ -815,7 +815,7 @@ impl ModuleTree {
if incomplete_count_before_remove > 0 { if incomplete_count_before_remove > 0 {
parent_tree.remove_incomplete_fetch_url(&self.url); parent_tree.remove_incomplete_fetch_url(&self.url);
parent_tree.advance_finished_and_link(&global); parent_tree.advance_finished_and_link(global);
} }
} }
} }
@ -831,7 +831,7 @@ impl ModuleTree {
(None, None) => { (None, None) => {
let module_record = self.get_record().borrow(); let module_record = self.get_record().borrow();
if let Some(record) = &*module_record { if let Some(record) = &*module_record {
let instantiated = self.instantiate_module_tree(&global, record.handle()); let instantiated = self.instantiate_module_tree(global, record.handle());
if let Err(exception) = instantiated { if let Err(exception) = instantiated {
self.set_rethrow_error(exception); self.set_rethrow_error(exception);

View file

@ -748,8 +748,8 @@ pub unsafe fn get_reports(cx: *mut RawJSContext, path_seg: String) -> Vec<Report
reports reports
} }
thread_local!(static GC_CYCLE_START: Cell<Option<Instant>> = Cell::new(None)); thread_local!(static GC_CYCLE_START: Cell<Option<Instant>> = const { Cell::new(None) });
thread_local!(static GC_SLICE_START: Cell<Option<Instant>> = Cell::new(None)); thread_local!(static GC_SLICE_START: Cell<Option<Instant>> = const { Cell::new(None) });
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe extern "C" fn gc_slice_callback( unsafe extern "C" fn gc_slice_callback(
@ -803,7 +803,7 @@ unsafe extern "C" fn debug_gc_callback(
} }
thread_local!( thread_local!(
static THREAD_ACTIVE: Cell<bool> = Cell::new(true); static THREAD_ACTIVE: Cell<bool> = const { Cell::new(true) };
); );
pub(crate) fn runtime_is_alive() -> bool { pub(crate) fn runtime_is_alive() -> bool {

View file

@ -165,7 +165,7 @@ use crate::{devtools, webdriver_handlers};
pub type ImageCacheMsg = (PipelineId, PendingImageResponse); pub type ImageCacheMsg = (PipelineId, PendingImageResponse);
thread_local!(static SCRIPT_THREAD_ROOT: Cell<Option<*const ScriptThread>> = Cell::new(None)); thread_local!(static SCRIPT_THREAD_ROOT: Cell<Option<*const ScriptThread>> = const { Cell::new(None) });
pub unsafe fn trace_thread(tr: *mut JSTracer) { pub unsafe fn trace_thread(tr: *mut JSTracer) {
SCRIPT_THREAD_ROOT.with(|root| { SCRIPT_THREAD_ROOT.with(|root| {

View file

@ -982,7 +982,7 @@ impl<T: ClipboardProvider> TextInput<T> {
/// Whether the content is empty. /// Whether the content is empty.
pub fn is_empty(&self) -> bool { pub fn is_empty(&self) -> bool {
self.lines.len() <= 1 && self.lines.get(0).map_or(true, |line| line.is_empty()) self.lines.len() <= 1 && self.lines.first().map_or(true, |line| line.is_empty())
} }
/// The length of the content in bytes. /// The length of the content in bytes.