clippy: fix several lint warns (#32126)

As seems #31500 still remain opened here's the next partial fix.

Fixed list: `unused_mut`, `clippy::needless_borrow`,
`clippy::match_ref_pats`, `clippy::borrow_deref_ref`, `clippy::ptr_eq`,
`clippy::unnecessary_cast`, `clippy::derivable_impls`,
`clippy::collapsible_match`, `clippy::extra_unused_lifetimes`,
`clippy::map_clone`, `clippy::manual_filter`.


- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes are part of #31500.
- [x] These changes do not require tests because are only cosmetic.
This commit is contained in:
Kitsu 2024-04-22 03:45:39 -03:00 committed by GitHub
parent 025a987732
commit 67f239d1ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
17 changed files with 54 additions and 83 deletions

View file

@ -608,7 +608,7 @@ impl LayoutThread {
} }
/// Receives and dispatches messages from the script and constellation threads /// Receives and dispatches messages from the script and constellation threads
fn handle_request<'a, 'b>(&mut self, request: Request) { fn handle_request(&mut self, request: Request) {
match request { match request {
Request::FromPipeline(LayoutControlMsg::SetScrollStates(new_scroll_states)) => { Request::FromPipeline(LayoutControlMsg::SetScrollStates(new_scroll_states)) => {
self.handle_request_helper(Msg::SetScrollStates(new_scroll_states)) self.handle_request_helper(Msg::SetScrollStates(new_scroll_states))
@ -754,7 +754,7 @@ impl LayoutThread {
} }
/// Sets quirks mode for the document, causing the quirks mode stylesheet to be used. /// Sets quirks mode for the document, causing the quirks mode stylesheet to be used.
fn handle_set_quirks_mode<'a, 'b>(&mut self, quirks_mode: QuirksMode) { fn handle_set_quirks_mode(&mut self, quirks_mode: QuirksMode) {
self.stylist.set_quirks_mode(quirks_mode); self.stylist.set_quirks_mode(quirks_mode);
} }
@ -1339,7 +1339,7 @@ impl LayoutThread {
profile_time::ProfilerCategory::LayoutGeneratedContent, profile_time::ProfilerCategory::LayoutGeneratedContent,
self.profiler_metadata(), self.profiler_metadata(),
self.time_profiler_chan.clone(), self.time_profiler_chan.clone(),
|| sequential::resolve_generated_content(FlowRef::deref_mut(root_flow), &context), || sequential::resolve_generated_content(FlowRef::deref_mut(root_flow), context),
); );
// Guess float placement. // Guess float placement.
@ -1375,7 +1375,7 @@ impl LayoutThread {
); );
} else { } else {
//Sequential mode //Sequential mode
LayoutThread::solve_constraints(FlowRef::deref_mut(root_flow), &context) LayoutThread::solve_constraints(FlowRef::deref_mut(root_flow), context)
} }
}, },
); );
@ -1396,7 +1396,7 @@ impl LayoutThread {
fn perform_post_main_layout_passes( fn perform_post_main_layout_passes(
&self, &self,
data: &Reflow, data: &Reflow,
mut root_flow: &mut FlowRef, root_flow: &mut FlowRef,
reflow_goal: &ReflowGoal, reflow_goal: &ReflowGoal,
document: Option<&ServoLayoutDocument>, document: Option<&ServoLayoutDocument>,
layout_context: &mut LayoutContext, layout_context: &mut LayoutContext,
@ -1406,7 +1406,7 @@ impl LayoutThread {
data, data,
reflow_goal, reflow_goal,
document, document,
FlowRef::deref_mut(&mut root_flow), FlowRef::deref_mut(root_flow),
&mut *layout_context, &mut *layout_context,
); );

View file

@ -555,7 +555,7 @@ impl LayoutThread {
} }
/// Receives and dispatches messages from the script and constellation threads /// Receives and dispatches messages from the script and constellation threads
fn handle_request<'a, 'b>(&mut self, request: Request) { fn handle_request(&mut self, request: Request) {
match request { match request {
Request::FromPipeline(LayoutControlMsg::SetScrollStates(new_scroll_states)) => { Request::FromPipeline(LayoutControlMsg::SetScrollStates(new_scroll_states)) => {
self.handle_request_helper(Msg::SetScrollStates(new_scroll_states)) self.handle_request_helper(Msg::SetScrollStates(new_scroll_states))
@ -629,13 +629,13 @@ impl LayoutThread {
) { ) {
// Find all font-face rules and notify the font cache of them. // Find all font-face rules and notify the font cache of them.
// GWTODO: Need to handle unloading web fonts. // GWTODO: Need to handle unloading web fonts.
if stylesheet.is_effective_for_device(self.stylist.device(), &guard) { if stylesheet.is_effective_for_device(self.stylist.device(), guard) {
let newly_loading_font_count = self let newly_loading_font_count = self
.font_cache_thread .font_cache_thread
.lock() .lock()
.add_all_web_fonts_from_stylesheet( .add_all_web_fonts_from_stylesheet(
&*stylesheet, stylesheet,
&guard, guard,
self.stylist.device(), self.stylist.device(),
&self.font_cache_sender, &self.font_cache_sender,
self.debug.load_webfonts_synchronously, self.debug.load_webfonts_synchronously,
@ -658,7 +658,7 @@ impl LayoutThread {
} }
/// Sets quirks mode for the document, causing the quirks mode stylesheet to be used. /// Sets quirks mode for the document, causing the quirks mode stylesheet to be used.
fn handle_set_quirks_mode<'a, 'b>(&mut self, quirks_mode: QuirksMode) { fn handle_set_quirks_mode(&mut self, quirks_mode: QuirksMode) {
self.stylist.set_quirks_mode(quirks_mode); self.stylist.set_quirks_mode(quirks_mode);
} }
@ -1048,7 +1048,7 @@ impl LayoutThread {
.borrow() .borrow()
.iter() .iter()
.filter_map(|(browsing_context_id, size)| { .filter_map(|(browsing_context_id, size)| {
match old_iframe_sizes.get(&browsing_context_id) { match old_iframe_sizes.get(browsing_context_id) {
Some(old_size) if old_size != size => Some(IFrameSizeMsg { Some(old_size) if old_size != size => Some(IFrameSizeMsg {
browsing_context_id: *browsing_context_id, browsing_context_id: *browsing_context_id,
size: *size, size: *size,
@ -1145,17 +1145,17 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
// (Does it make a difference?) // (Does it make a difference?)
let mut user_or_user_agent_stylesheets = vec![ let mut user_or_user_agent_stylesheets = vec![
parse_ua_stylesheet( parse_ua_stylesheet(
&shared_lock, shared_lock,
"user-agent.css", "user-agent.css",
&resources::read_bytes(Resource::UserAgentCSS), &resources::read_bytes(Resource::UserAgentCSS),
)?, )?,
parse_ua_stylesheet( parse_ua_stylesheet(
&shared_lock, shared_lock,
"servo.css", "servo.css",
&resources::read_bytes(Resource::ServoCSS), &resources::read_bytes(Resource::ServoCSS),
)?, )?,
parse_ua_stylesheet( parse_ua_stylesheet(
&shared_lock, shared_lock,
"presentational-hints.css", "presentational-hints.css",
&resources::read_bytes(Resource::PresentationalHintsCSS), &resources::read_bytes(Resource::PresentationalHintsCSS),
)?, )?,
@ -1164,7 +1164,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
for &(ref contents, ref url) in &opts::get().user_stylesheets { for &(ref contents, ref url) in &opts::get().user_stylesheets {
user_or_user_agent_stylesheets.push(DocumentStyleSheet(ServoArc::new( user_or_user_agent_stylesheets.push(DocumentStyleSheet(ServoArc::new(
Stylesheet::from_bytes( Stylesheet::from_bytes(
&contents, contents,
UrlExtraData(url.get_arc()), UrlExtraData(url.get_arc()),
None, None,
None, None,
@ -1179,7 +1179,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
} }
let quirks_mode_stylesheet = parse_ua_stylesheet( let quirks_mode_stylesheet = parse_ua_stylesheet(
&shared_lock, shared_lock,
"quirks-mode.css", "quirks-mode.css",
&resources::read_bytes(Resource::QuirksModeCSS), &resources::read_bytes(Resource::QuirksModeCSS),
)?; )?;
@ -1248,7 +1248,7 @@ struct RegisteredPaintersImpl(FnvHashMap<Atom, RegisteredPainterImpl>);
impl RegisteredSpeculativePainters for RegisteredPaintersImpl { impl RegisteredSpeculativePainters for RegisteredPaintersImpl {
fn get(&self, name: &Atom) -> Option<&dyn RegisteredSpeculativePainter> { fn get(&self, name: &Atom) -> Option<&dyn RegisteredSpeculativePainter> {
self.0 self.0
.get(&name) .get(name)
.map(|painter| painter as &dyn RegisteredSpeculativePainter) .map(|painter| painter as &dyn RegisteredSpeculativePainter)
} }
} }

View file

@ -89,10 +89,8 @@ impl AudioBufferSourceNode {
loop_start: Cell::new(*options.loopStart), loop_start: Cell::new(*options.loopStart),
loop_end: Cell::new(*options.loopEnd), loop_end: Cell::new(*options.loopEnd),
}; };
if let Some(ref buffer) = options.buffer { if let Some(Some(ref buffer)) = options.buffer {
if let Some(ref buffer) = buffer { node.SetBuffer(Some(buffer))?;
node.SetBuffer(Some(&**buffer))?
}
} }
Ok(node) Ok(node)
} }
@ -267,15 +265,10 @@ impl AudioBufferSourceNodeMethods for AudioBufferSourceNode {
impl<'a> From<&'a AudioBufferSourceOptions> for AudioBufferSourceNodeOptions { impl<'a> From<&'a AudioBufferSourceOptions> for AudioBufferSourceNodeOptions {
fn from(options: &'a AudioBufferSourceOptions) -> Self { fn from(options: &'a AudioBufferSourceOptions) -> Self {
Self { Self {
buffer: if let Some(ref buffer) = options.buffer { buffer: options
if let Some(ref buffer) = buffer { .buffer
(*buffer.get_channels()).clone() .as_ref()
} else { .and_then(|b| (*b.as_ref()?.get_channels()).clone()),
None
}
} else {
None
},
detune: *options.detune, detune: *options.detune,
loop_enabled: options.loop_, loop_enabled: options.loop_,
loop_end: Some(*options.loopEnd), loop_end: Some(*options.loopEnd),

View file

@ -197,18 +197,18 @@ pub fn blob_parts_to_bytes(
let mut ret = vec![]; let mut ret = vec![];
for blobpart in &mut blobparts { for blobpart in &mut blobparts {
match blobpart { match blobpart {
&mut ArrayBufferOrArrayBufferViewOrBlobOrString::String(ref s) => { ArrayBufferOrArrayBufferViewOrBlobOrString::String(s) => {
ret.extend(s.as_bytes()); ret.extend(s.as_bytes());
}, },
&mut ArrayBufferOrArrayBufferViewOrBlobOrString::Blob(ref b) => { ArrayBufferOrArrayBufferViewOrBlobOrString::Blob(b) => {
let bytes = b.get_bytes().unwrap_or(vec![]); let bytes = b.get_bytes().unwrap_or(vec![]);
ret.extend(bytes); ret.extend(bytes);
}, },
&mut ArrayBufferOrArrayBufferViewOrBlobOrString::ArrayBuffer(ref mut a) => unsafe { ArrayBufferOrArrayBufferViewOrBlobOrString::ArrayBuffer(a) => unsafe {
let bytes = a.as_slice(); let bytes = a.as_slice();
ret.extend(bytes); ret.extend(bytes);
}, },
&mut ArrayBufferOrArrayBufferViewOrBlobOrString::ArrayBufferView(ref mut a) => unsafe { ArrayBufferOrArrayBufferViewOrBlobOrString::ArrayBufferView(a) => unsafe {
let bytes = a.as_slice(); let bytes = a.as_slice();
ret.extend(bytes); ret.extend(bytes);
}, },

View file

@ -51,20 +51,15 @@ use crate::script_runtime::JSContext;
use crate::script_thread::ScriptThread; use crate::script_thread::ScriptThread;
/// <https://dom.spec.whatwg.org/#concept-element-custom-element-state> /// <https://dom.spec.whatwg.org/#concept-element-custom-element-state>
#[derive(Clone, Copy, Eq, JSTraceable, MallocSizeOf, PartialEq)] #[derive(Clone, Copy, Default, Eq, JSTraceable, MallocSizeOf, PartialEq)]
pub enum CustomElementState { pub enum CustomElementState {
Undefined, Undefined,
Failed, Failed,
#[default]
Uncustomized, Uncustomized,
Custom, Custom,
} }
impl Default for CustomElementState {
fn default() -> CustomElementState {
CustomElementState::Uncustomized
}
}
/// <https://html.spec.whatwg.org/multipage/#customelementregistry> /// <https://html.spec.whatwg.org/multipage/#customelementregistry>
#[dom_struct] #[dom_struct]
pub struct CustomElementRegistry { pub struct CustomElementRegistry {

View file

@ -1305,10 +1305,7 @@ impl Element {
match xmlSerialize::serialize( match xmlSerialize::serialize(
&mut writer, &mut writer,
&self.upcast::<Node>(), &self.upcast::<Node>(),
XmlSerializeOpts { XmlSerializeOpts { traversal_scope },
traversal_scope,
..Default::default()
},
) { ) {
Ok(()) => Ok(DOMString::from(String::from_utf8(writer).unwrap())), Ok(()) => Ok(DOMString::from(String::from_utf8(writer).unwrap())),
Err(_) => panic!("Cannot serialize element"), Err(_) => panic!("Cannot serialize element"),
@ -3065,10 +3062,10 @@ impl VirtualMethods for Element {
} }
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue { fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name { match *name {
&local_name!("id") => AttrValue::from_atomic(value.into()), local_name!("id") => AttrValue::from_atomic(value.into()),
&local_name!("name") => AttrValue::from_atomic(value.into()), local_name!("name") => AttrValue::from_atomic(value.into()),
&local_name!("class") => AttrValue::from_serialized_tokenlist(value.into()), local_name!("class") => AttrValue::from_serialized_tokenlist(value.into()),
_ => self _ => self
.super_type() .super_type()
.unwrap() .unwrap()
@ -3198,7 +3195,7 @@ impl VirtualMethods for Element {
} }
} }
impl<'a> SelectorsElement for DomRoot<Element> { impl SelectorsElement for DomRoot<Element> {
type Impl = SelectorImpl; type Impl = SelectorImpl;
#[allow(unsafe_code)] #[allow(unsafe_code)]

View file

@ -143,7 +143,7 @@ impl ElementInternals {
} }
if let SubmissionValue::FormData(datums) = &*self.submission_value.borrow() { if let SubmissionValue::FormData(datums) = &*self.submission_value.borrow() {
entry_list.extend(datums.iter().map(|d| d.clone())); entry_list.extend(datums.iter().cloned());
return; return;
} }
let name = self let name = self
@ -169,7 +169,7 @@ impl ElementInternals {
entry_list.push(FormDatum { entry_list.push(FormDatum {
ty: DOMString::from("file"), ty: DOMString::from("file"),
name, name,
value: FormDatumValue::File(DomRoot::from_ref(&*file)), value: FormDatumValue::File(DomRoot::from_ref(file)),
}); });
}, },
} }

View file

@ -264,16 +264,8 @@ impl Event {
} }
} }
let timeline_window = match DomRoot::downcast::<Window>(target.global()) { let timeline_window = DomRoot::downcast::<Window>(target.global())
Some(window) => { .filter(|window| window.need_emit_timeline_marker(TimelineMarkerType::DOMEvent));
if window.need_emit_timeline_marker(TimelineMarkerType::DOMEvent) {
Some(window)
} else {
None
}
},
_ => None,
};
// Step 5.13 // Step 5.13
for object in event_path.iter().rev() { for object in event_path.iter().rev() {

View file

@ -954,7 +954,7 @@ impl VirtualMethods for HTMLElement {
} }
fn bind_to_tree(&self, context: &BindContext) { fn bind_to_tree(&self, context: &BindContext) {
if let Some(ref super_type) = self.super_type() { if let Some(super_type) = self.super_type() {
super_type.bind_to_tree(context); super_type.bind_to_tree(context);
} }
let element = self.as_element(); let element = self.as_element();
@ -975,7 +975,7 @@ impl VirtualMethods for HTMLElement {
} }
fn unbind_from_tree(&self, context: &UnbindContext) { fn unbind_from_tree(&self, context: &UnbindContext) {
if let Some(ref super_type) = self.super_type() { if let Some(super_type) = self.super_type() {
super_type.unbind_from_tree(context); super_type.unbind_from_tree(context);
} }

View file

@ -1569,10 +1569,9 @@ pub trait FormControl: DomObject {
if html_elem.is_form_associated_custom_element() { if html_elem.is_form_associated_custom_element() {
ScriptThread::enqueue_callback_reaction( ScriptThread::enqueue_callback_reaction(
elem, elem,
CallbackReaction::FormAssociated(match new_owner { CallbackReaction::FormAssociated(
None => None, new_owner.as_ref().map(|form| DomRoot::from_ref(&**form)),
Some(ref form) => Some(DomRoot::from_ref(&**form)), ),
}),
None, None,
) )
} }

View file

@ -86,7 +86,7 @@ const DEFAULT_SUBMIT_VALUE: &str = "Submit";
const DEFAULT_RESET_VALUE: &str = "Reset"; const DEFAULT_RESET_VALUE: &str = "Reset";
const PASSWORD_REPLACEMENT_CHAR: char = '●'; const PASSWORD_REPLACEMENT_CHAR: char = '●';
#[derive(Clone, Copy, JSTraceable, PartialEq)] #[derive(Clone, Copy, Default, JSTraceable, PartialEq)]
#[allow(dead_code)] #[allow(dead_code)]
#[derive(MallocSizeOf)] #[derive(MallocSizeOf)]
pub enum InputType { pub enum InputType {
@ -108,6 +108,7 @@ pub enum InputType {
Search, Search,
Submit, Submit,
Tel, Tel,
#[default]
Text, Text,
Time, Time,
Url, Url,
@ -224,12 +225,6 @@ impl<'a> From<&'a Atom> for InputType {
} }
} }
impl Default for InputType {
fn default() -> InputType {
InputType::Text
}
}
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
enum ValueMode { enum ValueMode {
Value, Value,

View file

@ -120,8 +120,8 @@ impl Navigator {
fn shrink_gamepads_list(&self) { fn shrink_gamepads_list(&self) {
let mut gamepad_list = self.gamepads.borrow_mut(); let mut gamepad_list = self.gamepads.borrow_mut();
for i in (0..gamepad_list.len()).rev() { for i in (0..gamepad_list.len()).rev() {
if gamepad_list.get(i as usize).is_none() { if gamepad_list.get(i).is_none() {
gamepad_list.remove(i as usize); gamepad_list.remove(i);
} else { } else {
break; break;
} }

View file

@ -3455,7 +3455,7 @@ impl UniqueId {
if (*ptr).is_none() { if (*ptr).is_none() {
*ptr = Some(Box::new(Uuid::new_v4())); *ptr = Some(Box::new(Uuid::new_v4()));
} }
(&*ptr).as_ref().unwrap() (*ptr).as_ref().unwrap()
} }
} }
} }

View file

@ -202,7 +202,7 @@ impl Iterator for SerializationIterator {
if let Some(SerializationCommand::OpenElement(ref e)) = res { if let Some(SerializationCommand::OpenElement(ref e)) = res {
self.stack self.stack
.push(SerializationCommand::CloseElement(e.clone())); .push(SerializationCommand::CloseElement(e.clone()));
for c in rev_children_iter(&*e.upcast::<Node>()) { for c in rev_children_iter(e.upcast::<Node>()) {
self.push_node(&c); self.push_node(&c);
} }
} }

View file

@ -1910,7 +1910,7 @@ impl Window {
let mut images = self.pending_layout_images.borrow_mut(); let mut images = self.pending_layout_images.borrow_mut();
let nodes = images.entry(id).or_default(); let nodes = images.entry(id).or_default();
if !nodes.iter().any(|n| &**n as *const _ == &*node as *const _) { if !nodes.iter().any(|n| std::ptr::eq(&**n, &*node)) {
let (responder, responder_listener) = let (responder, responder_listener) =
ProfiledIpc::channel(self.global().time_profiler_chan().clone()).unwrap(); ProfiledIpc::channel(self.global().time_profiler_chan().clone()).unwrap();
let image_cache_chan = self.image_cache_chan.clone(); let image_cache_chan = self.image_cache_chan.clone();

View file

@ -201,7 +201,7 @@ impl WindowProxy {
SetProxyReservedSlot( SetProxyReservedSlot(
js_proxy.get(), js_proxy.get(),
0, 0,
&PrivateValue((&*window_proxy).as_void_ptr()), &PrivateValue((*window_proxy).as_void_ptr()),
); );
// Notify the JS engine about the new window proxy binding. // Notify the JS engine about the new window proxy binding.

View file

@ -837,7 +837,7 @@ impl XRSessionMethods for XRSession {
.borrow() .borrow()
.granted_features() .granted_features()
.iter() .iter()
.any(|f| &*f == "hit-test") .any(|f| f == "hit-test")
{ {
p.reject_error(Error::NotSupported); p.reject_error(Error::NotSupported);
return p; return p;