mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
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
This commit is contained in:
parent
3e9b808938
commit
bae77671f8
21 changed files with 32 additions and 45 deletions
|
@ -607,7 +607,7 @@ impl CanvasState {
|
||||||
) -> (Rect<f64>, Rect<f64>) {
|
) -> (Rect<f64>, Rect<f64>) {
|
||||||
let image_rect = Rect::new(
|
let image_rect = Rect::new(
|
||||||
Point2D::new(0f64, 0f64),
|
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),
|
// The source rectangle is the rectangle whose corners are the four points (sx, sy),
|
||||||
|
|
|
@ -422,14 +422,13 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let mapping_slice_ptr =
|
let mapping_slice_ptr = mapping.lock().unwrap().borrow_mut()[offset..m_end].as_mut_ptr();
|
||||||
mapping.lock().unwrap().borrow_mut()[offset as usize..m_end as usize].as_mut_ptr();
|
|
||||||
|
|
||||||
// rooted! is needed to ensure memory safety and prevent potential garbage collection issues.
|
// 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
|
// https://github.com/mozilla-spidermonkey/spidermonkey-embedding-examples/blob/esr78/docs/GC%20Rooting%20Guide.md#performance-tweaking
|
||||||
rooted!(in(*cx) let array_buffer = NewExternalArrayBuffer(
|
rooted!(in(*cx) let array_buffer = NewExternalArrayBuffer(
|
||||||
*cx,
|
*cx,
|
||||||
range_size as usize,
|
range_size,
|
||||||
mapping_slice_ptr as _,
|
mapping_slice_ptr as _,
|
||||||
Some(free_func),
|
Some(free_func),
|
||||||
Arc::into_raw(mapping) as _,
|
Arc::into_raw(mapping) as _,
|
||||||
|
|
|
@ -228,8 +228,8 @@ pub unsafe fn jsstring_to_str(cx: *mut JSContext, s: *mut JSString) -> DOMString
|
||||||
let mut length = 0;
|
let mut length = 0;
|
||||||
let chars = JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), s, &mut length);
|
let chars = JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), s, &mut length);
|
||||||
assert!(!chars.is_null());
|
assert!(!chars.is_null());
|
||||||
let potentially_ill_formed_utf16 = slice::from_raw_parts(chars, length as usize);
|
let potentially_ill_formed_utf16 = slice::from_raw_parts(chars, length);
|
||||||
let mut s = String::with_capacity(length as usize);
|
let mut s = String::with_capacity(length);
|
||||||
for item in char::decode_utf16(potentially_ill_formed_utf16.iter().cloned()) {
|
for item in char::decode_utf16(potentially_ill_formed_utf16.iter().cloned()) {
|
||||||
match item {
|
match item {
|
||||||
Ok(c) => s.push(c),
|
Ok(c) => s.push(c),
|
||||||
|
@ -282,7 +282,7 @@ impl FromJSValConvertible for USVString {
|
||||||
let mut length = 0;
|
let mut length = 0;
|
||||||
let chars = JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), jsstr, &mut length);
|
let chars = JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), jsstr, &mut length);
|
||||||
assert!(!chars.is_null());
|
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(
|
Ok(ConversionResult::Success(USVString(
|
||||||
String::from_utf16_lossy(char_vec),
|
String::from_utf16_lossy(char_vec),
|
||||||
)))
|
)))
|
||||||
|
@ -324,7 +324,7 @@ impl FromJSValConvertible for ByteString {
|
||||||
let chars = JS_GetLatin1StringCharsAndLength(cx, ptr::null(), string, &mut length);
|
let chars = JS_GetLatin1StringCharsAndLength(cx, ptr::null(), string, &mut length);
|
||||||
assert!(!chars.is_null());
|
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(
|
return Ok(ConversionResult::Success(ByteString::new(
|
||||||
char_slice.to_vec(),
|
char_slice.to_vec(),
|
||||||
)));
|
)));
|
||||||
|
@ -332,7 +332,7 @@ impl FromJSValConvertible for ByteString {
|
||||||
|
|
||||||
let mut length = 0;
|
let mut length = 0;
|
||||||
let chars = JS_GetTwoByteStringCharsAndLength(cx, ptr::null(), string, &mut length);
|
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) {
|
if char_vec.iter().any(|&c| c > 0xFF) {
|
||||||
throw_type_error(cx, "Invalid ByteString");
|
throw_type_error(cx, "Invalid ByteString");
|
||||||
|
|
|
@ -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>
|
/// <https://html.spec.whatwg.org/multipage/#week-number-of-the-last-day>
|
||||||
fn max_week_in_year(year: i32) -> u32 {
|
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()
|
.earliest()
|
||||||
.map(|date_time| match date_time.weekday() {
|
.map(|date_time| match date_time.weekday() {
|
||||||
Weekday::Thu => 53,
|
Weekday::Thu => 53,
|
||||||
|
|
|
@ -451,7 +451,7 @@ pub unsafe extern "C" fn resolve_global(
|
||||||
let mut length = 0;
|
let mut length = 0;
|
||||||
let ptr = JS_GetLatin1StringCharsAndLength(cx, ptr::null(), string, &mut length);
|
let ptr = JS_GetLatin1StringCharsAndLength(cx, ptr::null(), string, &mut length);
|
||||||
assert!(!ptr.is_null());
|
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) {
|
if let Some(init_fun) = InterfaceObjectMap::MAP.get(bytes) {
|
||||||
init_fun(SafeJSContext::from_ptr(cx), Handle::from_raw(obj));
|
init_fun(SafeJSContext::from_ptr(cx), Handle::from_raw(obj));
|
||||||
|
|
|
@ -59,7 +59,7 @@ impl CanvasGradientMethods for CanvasGradient {
|
||||||
};
|
};
|
||||||
|
|
||||||
self.stops.borrow_mut().push(CanvasGradientStop {
|
self.stops.borrow_mut().push(CanvasGradientStop {
|
||||||
offset: (*offset) as f64,
|
offset: (*offset),
|
||||||
color,
|
color,
|
||||||
});
|
});
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -2001,7 +2001,7 @@ impl GlobalScope {
|
||||||
|
|
||||||
let stream = ReadableStream::new_with_external_underlying_source(
|
let stream = ReadableStream::new_with_external_underlying_source(
|
||||||
self,
|
self,
|
||||||
ExternalUnderlyingSource::Blob(size as usize),
|
ExternalUnderlyingSource::Blob(size),
|
||||||
);
|
);
|
||||||
|
|
||||||
let recv = self.send_msg(file_id);
|
let recv = self.send_msg(file_id);
|
||||||
|
@ -3171,7 +3171,7 @@ impl GlobalScope {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i in (0..gamepad_list.Length()).rev() {
|
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);
|
gamepad_list.remove_gamepad(i as usize);
|
||||||
} else {
|
} else {
|
||||||
break;
|
break;
|
||||||
|
@ -3211,7 +3211,7 @@ impl GlobalScope {
|
||||||
if !window.Navigator().has_gamepad_gesture() && contains_user_gesture(update_type) {
|
if !window.Navigator().has_gamepad_gesture() && contains_user_gesture(update_type) {
|
||||||
window.Navigator().set_has_gamepad_gesture(true);
|
window.Navigator().set_has_gamepad_gesture(true);
|
||||||
for i in 0..gamepad_list.Length() {
|
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.set_exposed(true);
|
||||||
gamepad.update_timestamp(*current_time);
|
gamepad.update_timestamp(*current_time);
|
||||||
let new_gamepad = Trusted::new(&*gamepad);
|
let new_gamepad = Trusted::new(&*gamepad);
|
||||||
|
|
|
@ -222,8 +222,8 @@ impl Area {
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(index, point)| match index % 2 {
|
.map(|(index, point)| match index % 2 {
|
||||||
0 => point + p.x as f32,
|
0 => point + p.x,
|
||||||
_ => point + p.y as f32,
|
_ => point + p.y,
|
||||||
});
|
});
|
||||||
Area::Polygon {
|
Area::Polygon {
|
||||||
points: iter.collect::<Vec<_>>(),
|
points: iter.collect::<Vec<_>>(),
|
||||||
|
|
|
@ -393,7 +393,7 @@ impl HTMLFormElementMethods for HTMLFormElement {
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-form-length
|
// https://html.spec.whatwg.org/multipage/#dom-form-length
|
||||||
fn Length(&self) -> u32 {
|
fn Length(&self) -> u32 {
|
||||||
self.Elements().Length() as u32
|
self.Elements().Length()
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-form-item
|
// https://html.spec.whatwg.org/multipage/#dom-form-item
|
||||||
|
|
|
@ -2155,7 +2155,7 @@ impl HTMLInputElement {
|
||||||
.map(|time| time.and_utc().timestamp_millis() as f64),
|
.map(|time| time.and_utc().timestamp_millis() as f64),
|
||||||
InputType::Time => match value.parse_time_string() {
|
InputType::Time => match value.parse_time_string() {
|
||||||
Some((hours, minutes, seconds)) => {
|
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,
|
_ => None,
|
||||||
},
|
},
|
||||||
|
@ -2543,7 +2543,7 @@ impl VirtualMethods for HTMLInputElement {
|
||||||
let TextIndexResponse(index) =
|
let TextIndexResponse(index) =
|
||||||
window.text_index_query(self.upcast::<Node>(), point_in_target);
|
window.text_index_query(self.upcast::<Node>(), point_in_target);
|
||||||
if let Some(i) = index {
|
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
|
// trigger redraw
|
||||||
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
||||||
event.PreventDefault();
|
event.PreventDefault();
|
||||||
|
|
|
@ -2334,7 +2334,7 @@ impl HTMLMediaElementMethods for HTMLMediaElement {
|
||||||
if let Some(ref player) = *self.player.borrow() {
|
if let Some(ref player) = *self.player.borrow() {
|
||||||
if let Ok(ranges) = player.lock().unwrap().buffered() {
|
if let Ok(ranges) = player.lock().unwrap().buffered() {
|
||||||
for range in ranges {
|
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());
|
elem.resource_selection_algorithm_sync(base_url.clone());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
&MediaElementMicrotask::PauseIfNotInDocumentTask { ref elem } => {
|
MediaElementMicrotask::PauseIfNotInDocumentTask { elem } => {
|
||||||
if !elem.upcast::<Node>().is_connected() {
|
if !elem.upcast::<Node>().is_connected() {
|
||||||
elem.internal_pause_steps();
|
elem.internal_pause_steps();
|
||||||
}
|
}
|
||||||
|
|
|
@ -2803,7 +2803,7 @@ impl NodeMethods for Node {
|
||||||
.ranges
|
.ranges
|
||||||
.drain_to_preceding_text_sibling(&sibling, &node, length);
|
.drain_to_preceding_text_sibling(&sibling, &node, length);
|
||||||
self.ranges
|
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();
|
let sibling_cdata = sibling.downcast::<CharacterData>().unwrap();
|
||||||
length += sibling_cdata.Length();
|
length += sibling_cdata.Length();
|
||||||
cdata.append_data(&sibling_cdata.data());
|
cdata.append_data(&sibling_cdata.data());
|
||||||
|
|
|
@ -172,7 +172,7 @@ impl ChildrenList {
|
||||||
pub fn item(&self, index: u32) -> Option<DomRoot<Node>> {
|
pub fn item(&self, index: u32) -> Option<DomRoot<Node>> {
|
||||||
// This always start traversing the children from the closest element
|
// This always start traversing the children from the closest element
|
||||||
// among parent's first and last children and the last visited one.
|
// 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 {
|
if index >= len {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
|
@ -379,8 +379,8 @@ impl PaintWorkletGlobalScope {
|
||||||
) -> DrawAPaintImageResult {
|
) -> DrawAPaintImageResult {
|
||||||
debug!("Returning an invalid image.");
|
debug!("Returning an invalid image.");
|
||||||
DrawAPaintImageResult {
|
DrawAPaintImageResult {
|
||||||
width: size.width as u32,
|
width: size.width,
|
||||||
height: size.height as u32,
|
height: size.height,
|
||||||
format: PixelFormat::BGRA8,
|
format: PixelFormat::BGRA8,
|
||||||
image_key: None,
|
image_key: None,
|
||||||
missing_image_urls,
|
missing_image_urls,
|
||||||
|
|
|
@ -497,7 +497,7 @@ impl ExternalUnderlyingSourceController {
|
||||||
fn get_chunk_with_length(&self, length: usize) -> Vec<u8> {
|
fn get_chunk_with_length(&self, length: usize) -> Vec<u8> {
|
||||||
let mut buffer = self.buffer.borrow_mut();
|
let mut buffer = self.buffer.borrow_mut();
|
||||||
let buffer_len = buffer.len();
|
let buffer_len = buffer.len();
|
||||||
assert!(buffer_len >= length as usize);
|
assert!(buffer_len >= length);
|
||||||
buffer.split_off(buffer_len - length)
|
buffer.split_off(buffer_len - length)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ impl TextTrackList {
|
||||||
pub fn item(&self, idx: usize) -> Option<DomRoot<TextTrack>> {
|
pub fn item(&self, idx: usize) -> Option<DomRoot<TextTrack>> {
|
||||||
self.dom_tracks
|
self.dom_tracks
|
||||||
.borrow()
|
.borrow()
|
||||||
.get(idx as usize)
|
.get(idx)
|
||||||
.map(|t| DomRoot::from_ref(&**t))
|
.map(|t| DomRoot::from_ref(&**t))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -765,7 +765,7 @@ impl<'a> WebGLValidator for TexStorageValidator<'a> {
|
||||||
return Err(TexImageValidationError::InvalidTextureFormat);
|
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 {
|
if level > max_level {
|
||||||
context.webgl_error(InvalidOperation);
|
context.webgl_error(InvalidOperation);
|
||||||
return Err(TexImageValidationError::LevelTooHigh);
|
return Err(TexImageValidationError::LevelTooHigh);
|
||||||
|
|
|
@ -2664,15 +2664,7 @@ impl WebGLRenderingContextMethods for WebGLRenderingContext {
|
||||||
// NB: TexImage2D depth is always equal to 1
|
// NB: TexImage2D depth is always equal to 1
|
||||||
handle_potential_webgl_error!(
|
handle_potential_webgl_error!(
|
||||||
self,
|
self,
|
||||||
texture.initialize(
|
texture.initialize(target, width, height, 1, internal_format, level, None)
|
||||||
target,
|
|
||||||
width as u32,
|
|
||||||
height as u32,
|
|
||||||
1,
|
|
||||||
internal_format,
|
|
||||||
level as u32,
|
|
||||||
None
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
let msg = WebGLCommand::CopyTexImage2D(
|
let msg = WebGLCommand::CopyTexImage2D(
|
||||||
|
|
|
@ -285,7 +285,7 @@ impl<'dom, LayoutDataType: LayoutDataTrait> ServoThreadSafeLayoutNode<'dom, Layo
|
||||||
/// Creates a new `ServoThreadSafeLayoutNode` from the given `ServoLayoutNode`.
|
/// Creates a new `ServoThreadSafeLayoutNode` from the given `ServoLayoutNode`.
|
||||||
pub fn new(node: ServoLayoutNode<'dom, LayoutDataType>) -> Self {
|
pub fn new(node: ServoLayoutNode<'dom, LayoutDataType>) -> Self {
|
||||||
ServoThreadSafeLayoutNode {
|
ServoThreadSafeLayoutNode {
|
||||||
node: node,
|
node,
|
||||||
pseudo: PseudoElementType::Normal,
|
pseudo: PseudoElementType::Normal,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1658,7 +1658,7 @@ fn fetch_single_module_script(
|
||||||
data: vec![],
|
data: vec![],
|
||||||
metadata: None,
|
metadata: None,
|
||||||
url: url.clone(),
|
url: url.clone(),
|
||||||
destination: destination,
|
destination,
|
||||||
options,
|
options,
|
||||||
status: Ok(()),
|
status: Ok(()),
|
||||||
resource_timing: ResourceFetchTiming::new(ResourceTimingType::Resource),
|
resource_timing: ResourceFetchTiming::new(ResourceTimingType::Resource),
|
||||||
|
|
|
@ -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 report = |mut path_suffix, kind, size| {
|
||||||
let mut path = path![path_seg, "js"];
|
let mut path = path![path_seg, "js"];
|
||||||
path.append(&mut path_suffix);
|
path.append(&mut path_suffix);
|
||||||
reports.push(Report {
|
reports.push(Report { path, kind, size })
|
||||||
path,
|
|
||||||
kind,
|
|
||||||
size: size as usize,
|
|
||||||
})
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// A note about possibly confusing terminology: the JS GC "heap" is allocated via
|
// A note about possibly confusing terminology: the JS GC "heap" is allocated via
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue