Skip to content

Commit

Permalink
clippy: fix several lint warns (#32126)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
l4l committed Apr 22, 2024
1 parent 025a987 commit 67f239d
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 83 deletions.
12 changes: 6 additions & 6 deletions components/layout_thread/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ impl LayoutThread {
}

/// 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 {
Request::FromPipeline(LayoutControlMsg::SetScrollStates(new_scroll_states)) => {
self.handle_request_helper(Msg::SetScrollStates(new_scroll_states))
Expand Down Expand Up @@ -754,7 +754,7 @@ impl LayoutThread {
}

/// 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);
}

Expand Down Expand Up @@ -1339,7 +1339,7 @@ impl LayoutThread {
profile_time::ProfilerCategory::LayoutGeneratedContent,
self.profiler_metadata(),
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.
Expand Down Expand Up @@ -1375,7 +1375,7 @@ impl LayoutThread {
);
} else {
//Sequential mode
LayoutThread::solve_constraints(FlowRef::deref_mut(root_flow), &context)
LayoutThread::solve_constraints(FlowRef::deref_mut(root_flow), context)
}
},
);
Expand All @@ -1396,7 +1396,7 @@ impl LayoutThread {
fn perform_post_main_layout_passes(
&self,
data: &Reflow,
mut root_flow: &mut FlowRef,
root_flow: &mut FlowRef,
reflow_goal: &ReflowGoal,
document: Option<&ServoLayoutDocument>,
layout_context: &mut LayoutContext,
Expand All @@ -1406,7 +1406,7 @@ impl LayoutThread {
data,
reflow_goal,
document,
FlowRef::deref_mut(&mut root_flow),
FlowRef::deref_mut(root_flow),
&mut *layout_context,
);

Expand Down
24 changes: 12 additions & 12 deletions components/layout_thread_2020/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ impl LayoutThread {
}

/// 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 {
Request::FromPipeline(LayoutControlMsg::SetScrollStates(new_scroll_states)) => {
self.handle_request_helper(Msg::SetScrollStates(new_scroll_states))
Expand Down Expand Up @@ -629,13 +629,13 @@ impl LayoutThread {
) {
// Find all font-face rules and notify the font cache of them.
// 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
.font_cache_thread
.lock()
.add_all_web_fonts_from_stylesheet(
&*stylesheet,
&guard,
stylesheet,
guard,
self.stylist.device(),
&self.font_cache_sender,
self.debug.load_webfonts_synchronously,
Expand All @@ -658,7 +658,7 @@ impl LayoutThread {
}

/// 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);
}

Expand Down Expand Up @@ -1048,7 +1048,7 @@ impl LayoutThread {
.borrow()
.iter()
.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 {
browsing_context_id: *browsing_context_id,
size: *size,
Expand Down Expand Up @@ -1145,17 +1145,17 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
// (Does it make a difference?)
let mut user_or_user_agent_stylesheets = vec![
parse_ua_stylesheet(
&shared_lock,
shared_lock,
"user-agent.css",
&resources::read_bytes(Resource::UserAgentCSS),
)?,
parse_ua_stylesheet(
&shared_lock,
shared_lock,
"servo.css",
&resources::read_bytes(Resource::ServoCSS),
)?,
parse_ua_stylesheet(
&shared_lock,
shared_lock,
"presentational-hints.css",
&resources::read_bytes(Resource::PresentationalHintsCSS),
)?,
Expand All @@ -1164,7 +1164,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
for &(ref contents, ref url) in &opts::get().user_stylesheets {
user_or_user_agent_stylesheets.push(DocumentStyleSheet(ServoArc::new(
Stylesheet::from_bytes(
&contents,
contents,
UrlExtraData(url.get_arc()),
None,
None,
Expand All @@ -1179,7 +1179,7 @@ fn get_ua_stylesheets() -> Result<UserAgentStylesheets, &'static str> {
}

let quirks_mode_stylesheet = parse_ua_stylesheet(
&shared_lock,
shared_lock,
"quirks-mode.css",
&resources::read_bytes(Resource::QuirksModeCSS),
)?;
Expand Down Expand Up @@ -1248,7 +1248,7 @@ struct RegisteredPaintersImpl(FnvHashMap<Atom, RegisteredPainterImpl>);
impl RegisteredSpeculativePainters for RegisteredPaintersImpl {
fn get(&self, name: &Atom) -> Option<&dyn RegisteredSpeculativePainter> {
self.0
.get(&name)
.get(name)
.map(|painter| painter as &dyn RegisteredSpeculativePainter)
}
}
Expand Down
19 changes: 6 additions & 13 deletions components/script/dom/audiobuffersourcenode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,8 @@ impl AudioBufferSourceNode {
loop_start: Cell::new(*options.loopStart),
loop_end: Cell::new(*options.loopEnd),
};
if let Some(ref buffer) = options.buffer {
if let Some(ref buffer) = buffer {
node.SetBuffer(Some(&**buffer))?
}
if let Some(Some(ref buffer)) = options.buffer {
node.SetBuffer(Some(buffer))?;
}
Ok(node)
}
Expand Down Expand Up @@ -267,15 +265,10 @@ impl AudioBufferSourceNodeMethods for AudioBufferSourceNode {
impl<'a> From<&'a AudioBufferSourceOptions> for AudioBufferSourceNodeOptions {
fn from(options: &'a AudioBufferSourceOptions) -> Self {
Self {
buffer: if let Some(ref buffer) = options.buffer {
if let Some(ref buffer) = buffer {
(*buffer.get_channels()).clone()
} else {
None
}
} else {
None
},
buffer: options
.buffer
.as_ref()
.and_then(|b| (*b.as_ref()?.get_channels()).clone()),
detune: *options.detune,
loop_enabled: options.loop_,
loop_end: Some(*options.loopEnd),
Expand Down
8 changes: 4 additions & 4 deletions components/script/dom/blob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,18 +197,18 @@ pub fn blob_parts_to_bytes(
let mut ret = vec![];
for blobpart in &mut blobparts {
match blobpart {
&mut ArrayBufferOrArrayBufferViewOrBlobOrString::String(ref s) => {
ArrayBufferOrArrayBufferViewOrBlobOrString::String(s) => {
ret.extend(s.as_bytes());
},
&mut ArrayBufferOrArrayBufferViewOrBlobOrString::Blob(ref b) => {
ArrayBufferOrArrayBufferViewOrBlobOrString::Blob(b) => {
let bytes = b.get_bytes().unwrap_or(vec![]);
ret.extend(bytes);
},
&mut ArrayBufferOrArrayBufferViewOrBlobOrString::ArrayBuffer(ref mut a) => unsafe {
ArrayBufferOrArrayBufferViewOrBlobOrString::ArrayBuffer(a) => unsafe {
let bytes = a.as_slice();
ret.extend(bytes);
},
&mut ArrayBufferOrArrayBufferViewOrBlobOrString::ArrayBufferView(ref mut a) => unsafe {
ArrayBufferOrArrayBufferViewOrBlobOrString::ArrayBufferView(a) => unsafe {
let bytes = a.as_slice();
ret.extend(bytes);
},
Expand Down
9 changes: 2 additions & 7 deletions components/script/dom/customelementregistry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,15 @@ use crate::script_runtime::JSContext;
use crate::script_thread::ScriptThread;

/// <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 {
Undefined,
Failed,
#[default]
Uncustomized,
Custom,
}

impl Default for CustomElementState {
fn default() -> CustomElementState {
CustomElementState::Uncustomized
}
}

/// <https://html.spec.whatwg.org/multipage/#customelementregistry>
#[dom_struct]
pub struct CustomElementRegistry {
Expand Down
15 changes: 6 additions & 9 deletions components/script/dom/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1305,10 +1305,7 @@ impl Element {
match xmlSerialize::serialize(
&mut writer,
&self.upcast::<Node>(),
XmlSerializeOpts {
traversal_scope,
..Default::default()
},
XmlSerializeOpts { traversal_scope },
) {
Ok(()) => Ok(DOMString::from(String::from_utf8(writer).unwrap())),
Err(_) => panic!("Cannot serialize element"),
Expand Down Expand Up @@ -3065,10 +3062,10 @@ impl VirtualMethods for Element {
}

fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
match name {
&local_name!("id") => AttrValue::from_atomic(value.into()),
&local_name!("name") => AttrValue::from_atomic(value.into()),
&local_name!("class") => AttrValue::from_serialized_tokenlist(value.into()),
match *name {
local_name!("id") => AttrValue::from_atomic(value.into()),
local_name!("name") => AttrValue::from_atomic(value.into()),
local_name!("class") => AttrValue::from_serialized_tokenlist(value.into()),
_ => self
.super_type()
.unwrap()
Expand Down Expand Up @@ -3198,7 +3195,7 @@ impl VirtualMethods for Element {
}
}

impl<'a> SelectorsElement for DomRoot<Element> {
impl SelectorsElement for DomRoot<Element> {
type Impl = SelectorImpl;

#[allow(unsafe_code)]
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/elementinternals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl ElementInternals {
}

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;
}
let name = self
Expand All @@ -169,7 +169,7 @@ impl ElementInternals {
entry_list.push(FormDatum {
ty: DOMString::from("file"),
name,
value: FormDatumValue::File(DomRoot::from_ref(&*file)),
value: FormDatumValue::File(DomRoot::from_ref(file)),
});
},
}
Expand Down
12 changes: 2 additions & 10 deletions components/script/dom/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,16 +264,8 @@ impl Event {
}
}

let timeline_window = match DomRoot::downcast::<Window>(target.global()) {
Some(window) => {
if window.need_emit_timeline_marker(TimelineMarkerType::DOMEvent) {
Some(window)
} else {
None
}
},
_ => None,
};
let timeline_window = DomRoot::downcast::<Window>(target.global())
.filter(|window| window.need_emit_timeline_marker(TimelineMarkerType::DOMEvent));

// Step 5.13
for object in event_path.iter().rev() {
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/htmlelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ impl VirtualMethods for HTMLElement {
}

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);
}
let element = self.as_element();
Expand All @@ -975,7 +975,7 @@ impl VirtualMethods for HTMLElement {
}

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);
}

Expand Down
7 changes: 3 additions & 4 deletions components/script/dom/htmlformelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1569,10 +1569,9 @@ pub trait FormControl: DomObject {
if html_elem.is_form_associated_custom_element() {
ScriptThread::enqueue_callback_reaction(
elem,
CallbackReaction::FormAssociated(match new_owner {
None => None,
Some(ref form) => Some(DomRoot::from_ref(&**form)),
}),
CallbackReaction::FormAssociated(
new_owner.as_ref().map(|form| DomRoot::from_ref(&**form)),
),
None,
)
}
Expand Down
9 changes: 2 additions & 7 deletions components/script/dom/htmlinputelement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ const DEFAULT_SUBMIT_VALUE: &str = "Submit";
const DEFAULT_RESET_VALUE: &str = "Reset";
const PASSWORD_REPLACEMENT_CHAR: char = '●';

#[derive(Clone, Copy, JSTraceable, PartialEq)]
#[derive(Clone, Copy, Default, JSTraceable, PartialEq)]
#[allow(dead_code)]
#[derive(MallocSizeOf)]
pub enum InputType {
Expand All @@ -108,6 +108,7 @@ pub enum InputType {
Search,
Submit,
Tel,
#[default]
Text,
Time,
Url,
Expand Down Expand Up @@ -224,12 +225,6 @@ impl<'a> From<&'a Atom> for InputType {
}
}

impl Default for InputType {
fn default() -> InputType {
InputType::Text
}
}

#[derive(Debug, PartialEq)]
enum ValueMode {
Value,
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/navigator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ impl Navigator {
fn shrink_gamepads_list(&self) {
let mut gamepad_list = self.gamepads.borrow_mut();
for i in (0..gamepad_list.len()).rev() {
if gamepad_list.get(i as usize).is_none() {
gamepad_list.remove(i as usize);
if gamepad_list.get(i).is_none() {
gamepad_list.remove(i);
} else {
break;
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3455,7 +3455,7 @@ impl UniqueId {
if (*ptr).is_none() {
*ptr = Some(Box::new(Uuid::new_v4()));
}
(&*ptr).as_ref().unwrap()
(*ptr).as_ref().unwrap()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/servoparser/html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl Iterator for SerializationIterator {
if let Some(SerializationCommand::OpenElement(ref e)) = res {
self.stack
.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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ impl Window {

let mut images = self.pending_layout_images.borrow_mut();
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) =
ProfiledIpc::channel(self.global().time_profiler_chan().clone()).unwrap();
let image_cache_chan = self.image_cache_chan.clone();
Expand Down

0 comments on commit 67f239d

Please sign in to comment.