diff options
author | Oluwatobi Sofela <60105594+oluwatobiss@users.noreply.github.com> | 2024-03-22 14:48:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-03-22 13:48:03 +0000 |
commit | bae77671f85481503ab563c20ed488cf883436fa (patch) | |
tree | cd718b8b5e9949052ebde65f9f5f2ce7fc60ef07 /components | |
parent | 3e9b8089381492edeb0992c93776d39bf1df2607 (diff) | |
download | servo-bae77671f85481503ab563c20ed488cf883436fa.tar.gz servo-bae77671f85481503ab563c20ed488cf883436fa.zip |
clippy: Fix `unnecessary_cast` warnings in `components/script` (#31823)
* clippy: Fix unnecessary cast warnings
* clippy: Replace redundant field names with their shorthand alternatives
* clippy: Delete struct pattern dereferencings
Diffstat (limited to 'components')
21 files changed, 32 insertions, 45 deletions
diff --git a/components/script/canvas_state.rs b/components/script/canvas_state.rs index 7e9286bac7d..4d3b23d310d 100644 --- a/components/script/canvas_state.rs +++ b/components/script/canvas_state.rs @@ -607,7 +607,7 @@ impl CanvasState { ) -> (Rect<f64>, Rect<f64>) { let image_rect = Rect::new( Point2D::new(0f64, 0f64), - Size2D::new(image_size.width as f64, image_size.height as f64), + Size2D::new(image_size.width, image_size.height), ); // The source rectangle is the rectangle whose corners are the four points (sx, sy), diff --git a/components/script/dom/bindings/buffer_source.rs b/components/script/dom/bindings/buffer_source.rs index a01a52d37c5..dd78186aee9 100644 --- a/components/script/dom/bindings/buffer_source.rs +++ b/components/script/dom/bindings/buffer_source.rs @@ -422,14 +422,13 @@ where } unsafe { - let mapping_slice_ptr = - mapping.lock().unwrap().borrow_mut()[offset as usize..m_end as usize].as_mut_ptr(); + let mapping_slice_ptr = mapping.lock().unwrap().borrow_mut()[offset..m_end].as_mut_ptr(); // rooted! is needed to ensure memory safety and prevent potential garbage collection issues. // https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples/blob/esr78/docs/GC%20Rooting%20Guide.md#performance-tweaking rooted!(in(*cx) let array_buffer = NewExternalArrayBuffer( *cx, - range_size as usize, + range_size, mapping_slice_ptr as _, Some(free_func), Arc::into_raw(mapping) as _, diff --git a/components/script/dom/bindings/conversions.rs b/components/script/dom/bindings/conversions.rs index 0c79b67134c..c33cbad479c 100644 --- a/components/script/dom/bindings/conversions.rs +++ b/components/script/dom/bindings/conversions.rs @@ -228,8 +228,8 @@ pub unsafe fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString let mut length = 0; let chars = JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), s, &mut length); assert!(!chars.is_null()); - let potentially_ill_formed_utf16 = slice::from_raw_parts(chars, length as usize); - let mut s = String::with_capacity(length as usize); + let potentially_ill_formed_utf16 = slice::from_raw_parts(chars, length); + let mut s = String::with_capacity(length); for item in char::decode_utf16(potentially_ill_formed_utf16.iter().cloned()) { match item { Ok(c) => s.push(c), @@ -282,7 +282,7 @@ impl FromJSValConvertible for USVString { let mut length = 0; let chars = JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), jsstr, &mut length); assert!(!chars.is_null()); - let char_vec = slice::from_raw_parts(chars as *const u16, length as usize); + let char_vec = slice::from_raw_parts(chars as *const u16, length); Ok(ConversionResult::Success(USVString( String::from_utf16_lossy(char_vec), ))) @@ -324,7 +324,7 @@ impl FromJSValConvertible for ByteString { let chars = JS_GetLatin1StringCharsAndLength(cx, ptr::null(), string, &mut length); assert!(!chars.is_null()); - let char_slice = slice::from_raw_parts(chars as *mut u8, length as usize); + let char_slice = slice::from_raw_parts(chars as *mut u8, length); return Ok(ConversionResult::Success(ByteString::new( char_slice.to_vec(), ))); @@ -332,7 +332,7 @@ impl FromJSValConvertible for ByteString { let mut length = 0; let chars = JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), string, &mut length); - let char_vec = slice::from_raw_parts(chars, length as usize); + let char_vec = slice::from_raw_parts(chars, length); if char_vec.iter().any(|&c| c > 0xFF) { throw_type_error(cx, "Invalid ByteString"); diff --git a/components/script/dom/bindings/str.rs b/components/script/dom/bindings/str.rs index 8fc1ce4591b..ae0e1f585a7 100644 --- a/components/script/dom/bindings/str.rs +++ b/components/script/dom/bindings/str.rs @@ -776,7 +776,7 @@ fn max_day_in_month(year_num: i32, month_num: u32) -> Option<u32> { /// <https://html.spec.whatwg.org/multipage/#week-number-of-the-last-day> fn max_week_in_year(year: i32) -> u32 { - Utc.with_ymd_and_hms(year as i32, 1, 1, 0, 0, 0) + Utc.with_ymd_and_hms(year, 1, 1, 0, 0, 0) .earliest() .map(|date_time| match date_time.weekday() { Weekday::Thu => 53, diff --git a/components/script/dom/bindings/utils.rs b/components/script/dom/bindings/utils.rs index adfd9017037..402b60fc2b6 100644 --- a/components/script/dom/bindings/utils.rs +++ b/components/script/dom/bindings/utils.rs @@ -451,7 +451,7 @@ pub unsafe extern "C" fn resolve_global( let mut length = 0; let ptr = JS_GetLatin1StringCharsAndLength(cx, ptr::null(), string, &mut length); assert!(!ptr.is_null()); - let bytes = slice::from_raw_parts(ptr, length as usize); + let bytes = slice::from_raw_parts(ptr, length); if let Some(init_fun) = InterfaceObjectMap::MAP.get(bytes) { init_fun(SafeJSContext::from_ptr(cx), Handle::from_raw(obj)); diff --git a/components/script/dom/canvasgradient.rs b/components/script/dom/canvasgradient.rs index bbadd171aed..20791998951 100644 --- a/components/script/dom/canvasgradient.rs +++ b/components/script/dom/canvasgradient.rs @@ -59,7 +59,7 @@ impl CanvasGradientMethods for CanvasGradient { }; self.stops.borrow_mut().push(CanvasGradientStop { - offset: (*offset) as f64, + offset: (*offset), color, }); Ok(()) diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 04c5933eef5..f0029bdf3d3 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -2001,7 +2001,7 @@ impl GlobalScope { let stream = ReadableStream::new_with_external_underlying_source( self, - ExternalUnderlyingSource::Blob(size as usize), + ExternalUnderlyingSource::Blob(size), ); let recv = self.send_msg(file_id); @@ -3171,7 +3171,7 @@ impl GlobalScope { } } for i in (0..gamepad_list.Length()).rev() { - if gamepad_list.Item(i as u32).is_none() { + if gamepad_list.Item(i).is_none() { gamepad_list.remove_gamepad(i as usize); } else { break; @@ -3211,7 +3211,7 @@ impl GlobalScope { if !window.Navigator().has_gamepad_gesture() && contains_user_gesture(update_type) { window.Navigator().set_has_gamepad_gesture(true); for i in 0..gamepad_list.Length() { - if let Some(gamepad) = gamepad_list.Item(i as u32) { + if let Some(gamepad) = gamepad_list.Item(i) { gamepad.set_exposed(true); gamepad.update_timestamp(*current_time); let new_gamepad = Trusted::new(&*gamepad); diff --git a/components/script/dom/htmlareaelement.rs b/components/script/dom/htmlareaelement.rs index e499d6960cd..59a55b22f04 100644 --- a/components/script/dom/htmlareaelement.rs +++ b/components/script/dom/htmlareaelement.rs @@ -222,8 +222,8 @@ impl Area { .iter() .enumerate() .map(|(index, point)| match index % 2 { - 0 => point + p.x as f32, - _ => point + p.y as f32, + 0 => point + p.x, + _ => point + p.y, }); Area::Polygon { points: iter.collect::<Vec<_>>(), diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs index b5312932bfe..4793f5a6af7 100644 --- a/components/script/dom/htmlformelement.rs +++ b/components/script/dom/htmlformelement.rs @@ -393,7 +393,7 @@ impl HTMLFormElementMethods for HTMLFormElement { // https://html.spec.whatwg.org/multipage/#dom-form-length fn Length(&self) -> u32 { - self.Elements().Length() as u32 + self.Elements().Length() } // https://html.spec.whatwg.org/multipage/#dom-form-item diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 347a63b1e08..669a12a3024 100755 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -2155,7 +2155,7 @@ impl HTMLInputElement { .map(|time| time.and_utc().timestamp_millis() as f64), InputType::Time => match value.parse_time_string() { Some((hours, minutes, seconds)) => { - Some((seconds as f64 + 60.0 * minutes as f64 + 3600.0 * hours as f64) * 1000.0) + Some((seconds + 60.0 * minutes as f64 + 3600.0 * hours as f64) * 1000.0) }, _ => None, }, @@ -2543,7 +2543,7 @@ impl VirtualMethods for HTMLInputElement { let TextIndexResponse(index) = window.text_index_query(self.upcast::<Node>(), point_in_target); if let Some(i) = index { - self.textinput.borrow_mut().set_edit_point_index(i as usize); + self.textinput.borrow_mut().set_edit_point_index(i); // trigger redraw self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage); event.PreventDefault(); diff --git a/components/script/dom/htmlmediaelement.rs b/components/script/dom/htmlmediaelement.rs index 7931a8b10c1..cc3be0c58af 100644 --- a/components/script/dom/htmlmediaelement.rs +++ b/components/script/dom/htmlmediaelement.rs @@ -2334,7 +2334,7 @@ impl HTMLMediaElementMethods for HTMLMediaElement { if let Some(ref player) = *self.player.borrow() { if let Ok(ranges) = player.lock().unwrap().buffered() { for range in ranges { - let _ = buffered.add(range.start as f64, range.end as f64); + let _ = buffered.add(range.start, range.end); } } } @@ -2504,7 +2504,7 @@ impl MicrotaskRunnable for MediaElementMicrotask { elem.resource_selection_algorithm_sync(base_url.clone()); } }, - &MediaElementMicrotask::PauseIfNotInDocumentTask { ref elem } => { + MediaElementMicrotask::PauseIfNotInDocumentTask { elem } => { if !elem.upcast::<Node>().is_connected() { elem.internal_pause_steps(); } diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index 8ea043af2c8..089e73cf889 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -2803,7 +2803,7 @@ impl NodeMethods for Node { .ranges .drain_to_preceding_text_sibling(&sibling, &node, length); self.ranges - .move_to_text_child_at(self, index as u32, &node, length as u32); + .move_to_text_child_at(self, index as u32, &node, length); let sibling_cdata = sibling.downcast::<CharacterData>().unwrap(); length += sibling_cdata.Length(); cdata.append_data(&sibling_cdata.data()); diff --git a/components/script/dom/nodelist.rs b/components/script/dom/nodelist.rs index 5514b9afd49..c20d3d57d44 100644 --- a/components/script/dom/nodelist.rs +++ b/components/script/dom/nodelist.rs @@ -172,7 +172,7 @@ impl ChildrenList { pub fn item(&self, index: u32) -> Option<DomRoot<Node>> { // This always start traversing the children from the closest element // among parent's first and last children and the last visited one. - let len = self.len() as u32; + let len = self.len(); if index >= len { return None; } diff --git a/components/script/dom/paintworkletglobalscope.rs b/components/script/dom/paintworkletglobalscope.rs index a6b2c0e2d07..154b3c73d02 100644 --- a/components/script/dom/paintworkletglobalscope.rs +++ b/components/script/dom/paintworkletglobalscope.rs @@ -379,8 +379,8 @@ impl PaintWorkletGlobalScope { ) -> DrawAPaintImageResult { debug!("Returning an invalid image."); DrawAPaintImageResult { - width: size.width as u32, - height: size.height as u32, + width: size.width, + height: size.height, format: PixelFormat::BGRA8, image_key: None, missing_image_urls, diff --git a/components/script/dom/readablestream.rs b/components/script/dom/readablestream.rs index fd3e89b246f..ca2bdca8c80 100644 --- a/components/script/dom/readablestream.rs +++ b/components/script/dom/readablestream.rs @@ -497,7 +497,7 @@ impl ExternalUnderlyingSourceController { fn get_chunk_with_length(&self, length: usize) -> Vec<u8> { let mut buffer = self.buffer.borrow_mut(); let buffer_len = buffer.len(); - assert!(buffer_len >= length as usize); + assert!(buffer_len >= length); buffer.split_off(buffer_len - length) } diff --git a/components/script/dom/texttracklist.rs b/components/script/dom/texttracklist.rs index 00e7b925ec8..6924603384a 100644 --- a/components/script/dom/texttracklist.rs +++ b/components/script/dom/texttracklist.rs @@ -40,7 +40,7 @@ impl TextTrackList { pub fn item(&self, idx: usize) -> Option<DomRoot<TextTrack>> { self.dom_tracks .borrow() - .get(idx as usize) + .get(idx) .map(|t| DomRoot::from_ref(&**t)) } diff --git a/components/script/dom/webgl_validations/tex_image_2d.rs b/components/script/dom/webgl_validations/tex_image_2d.rs index 55f0a272201..4e02e82d76b 100644 --- a/components/script/dom/webgl_validations/tex_image_2d.rs +++ b/components/script/dom/webgl_validations/tex_image_2d.rs @@ -765,7 +765,7 @@ impl<'a> WebGLValidator for TexStorageValidator<'a> { return Err(TexImageValidationError::InvalidTextureFormat); } - let max_level = log2(cmp::max(width, height) as u32) + 1; + let max_level = log2(cmp::max(width, height)) + 1; if level > max_level { context.webgl_error(InvalidOperation); return Err(TexImageValidationError::LevelTooHigh); diff --git a/components/script/dom/webglrenderingcontext.rs b/components/script/dom/webglrenderingcontext.rs index b5acebd9357..e7d7662a1db 100644 --- a/components/script/dom/webglrenderingcontext.rs +++ b/components/script/dom/webglrenderingcontext.rs @@ -2664,15 +2664,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext { // NB: TexImage2D depth is always equal to 1 handle_potential_webgl_error!( self, - texture.initialize( - target, - width as u32, - height as u32, - 1, - internal_format, - level as u32, - None - ) + texture.initialize(target, width, height, 1, internal_format, level, None) ); let msg = WebGLCommand::CopyTexImage2D( diff --git a/components/script/layout_dom/node.rs b/components/script/layout_dom/node.rs index 32b4fce1180..ae9d8ec00d1 100644 --- a/components/script/layout_dom/node.rs +++ b/components/script/layout_dom/node.rs @@ -285,7 +285,7 @@ impl<'dom, LayoutDataType: LayoutDataTrait> ServoThreadSafeLayoutNode<'dom, Layo /// Creates a new `ServoThreadSafeLayoutNode` from the given `ServoLayoutNode`. pub fn new(node: ServoLayoutNode<'dom, LayoutDataType>) -> Self { ServoThreadSafeLayoutNode { - node: node, + node, pseudo: PseudoElementType::Normal, } } diff --git a/components/script/script_module.rs b/components/script/script_module.rs index b9a8a3f0916..7a4c5966504 100644 --- a/components/script/script_module.rs +++ b/components/script/script_module.rs @@ -1658,7 +1658,7 @@ fn fetch_single_module_script( data: vec![], metadata: None, url: url.clone(), - destination: destination, + destination, options, status: Ok(()), resource_timing: ResourceFetchTiming::new(ResourceTimingType::Resource), diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 1e975874253..591b4adece6 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -700,11 +700,7 @@ pub fn get_reports(cx: *mut RawJSContext, path_seg: String) -> Vec<Report> { let mut report = |mut path_suffix, kind, size| { let mut path = path![path_seg, "js"]; path.append(&mut path_suffix); - reports.push(Report { - path, - kind, - size: size as usize, - }) + reports.push(Report { path, kind, size }) }; // A note about possibly confusing terminology: the JS GC "heap" is allocated via |