clippy: Fix some warnings in components/script (#31735)

* fix clippy problems

* fix clippy error

* fix clippy error

* fix clippy error

* fix clippy error

* fix clippy error

* fix clippy errors
This commit is contained in:
Rosemary Ajayi 2024-03-19 08:01:23 +00:00 committed by GitHub
parent 291fbce434
commit 06a021db55
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 60 additions and 69 deletions

View file

@ -44,25 +44,23 @@ use std::rc::Rc;
use std::str::FromStr; use std::str::FromStr;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
const KEY_CONVERSION_ERROR: &'static str = const KEY_CONVERSION_ERROR: &str =
"This `manufacturerData` key can not be parsed as unsigned short:"; "This `manufacturerData` key can not be parsed as unsigned short:";
const FILTER_EMPTY_ERROR: &'static str = const FILTER_EMPTY_ERROR: &str =
"'filters' member, if present, must be nonempty to find any devices."; "'filters' member, if present, must be nonempty to find any devices.";
const FILTER_ERROR: &'static str = "A filter must restrict the devices in some way."; const FILTER_ERROR: &str = "A filter must restrict the devices in some way.";
const MANUFACTURER_DATA_ERROR: &'static str = const MANUFACTURER_DATA_ERROR: &str =
"'manufacturerData', if present, must be non-empty to filter devices."; "'manufacturerData', if present, must be non-empty to filter devices.";
const MASK_LENGTH_ERROR: &'static str = const MASK_LENGTH_ERROR: &str = "`mask`, if present, must have the same length as `dataPrefix`.";
"`mask`, if present, must have the same length as `dataPrefix`.";
// 248 is the maximum number of UTF-8 code units in a Bluetooth Device Name. // 248 is the maximum number of UTF-8 code units in a Bluetooth Device Name.
const MAX_DEVICE_NAME_LENGTH: usize = 248; const MAX_DEVICE_NAME_LENGTH: usize = 248;
const NAME_PREFIX_ERROR: &'static str = "'namePrefix', if present, must be nonempty."; const NAME_PREFIX_ERROR: &str = "'namePrefix', if present, must be nonempty.";
const NAME_TOO_LONG_ERROR: &'static str = "A device name can't be longer than 248 bytes."; const NAME_TOO_LONG_ERROR: &str = "A device name can't be longer than 248 bytes.";
const SERVICE_DATA_ERROR: &'static str = const SERVICE_DATA_ERROR: &str = "'serviceData', if present, must be non-empty to filter devices.";
"'serviceData', if present, must be non-empty to filter devices."; const SERVICE_ERROR: &str = "'services', if present, must contain at least one service.";
const SERVICE_ERROR: &'static str = "'services', if present, must contain at least one service."; const OPTIONS_ERROR: &str = "Fields of 'options' conflict with each other.
const OPTIONS_ERROR: &'static str = "Fields of 'options' conflict with each other.
Either 'acceptAllDevices' member must be true, or 'filters' member must be set to a value."; Either 'acceptAllDevices' member must be true, or 'filters' member must be set to a value.";
const BT_DESC_CONVERSION_ERROR: &'static str = const BT_DESC_CONVERSION_ERROR: &str =
"Can't convert to an IDL value of type BluetoothPermissionDescriptor"; "Can't convert to an IDL value of type BluetoothPermissionDescriptor";
#[derive(JSTraceable, MallocSizeOf)] #[derive(JSTraceable, MallocSizeOf)]

View file

@ -43,10 +43,10 @@ impl BluetoothAdvertisingEvent {
BluetoothAdvertisingEvent { BluetoothAdvertisingEvent {
event: Event::new_inherited(), event: Event::new_inherited(),
device: Dom::from_ref(device), device: Dom::from_ref(device),
name: name, name,
appearance: appearance, appearance,
tx_power: tx_power, tx_power,
rssi: rssi, rssi,
} }
} }

View file

@ -39,15 +39,15 @@ impl BluetoothCharacteristicProperties {
) -> BluetoothCharacteristicProperties { ) -> BluetoothCharacteristicProperties {
BluetoothCharacteristicProperties { BluetoothCharacteristicProperties {
reflector_: Reflector::new(), reflector_: Reflector::new(),
broadcast: broadcast, broadcast,
read: read, read,
write_without_response: write_without_response, write_without_response,
write: write, write,
notify: notify, notify,
indicate: indicate, indicate,
authenticated_signed_writes: authenticated_signed_writes, authenticated_signed_writes,
reliable_write: reliable_write, reliable_write,
writable_auxiliaries: writable_auxiliaries, writable_auxiliaries,
} }
} }

View file

@ -57,8 +57,8 @@ impl BluetoothDevice {
) -> BluetoothDevice { ) -> BluetoothDevice {
BluetoothDevice { BluetoothDevice {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
id: id, id,
name: name, name,
gatt: Default::default(), gatt: Default::default(),
context: Dom::from_ref(context), context: Dom::from_ref(context),
attribute_instance_map: ( attribute_instance_map: (

View file

@ -56,10 +56,10 @@ impl BluetoothRemoteGATTCharacteristic {
BluetoothRemoteGATTCharacteristic { BluetoothRemoteGATTCharacteristic {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
service: Dom::from_ref(service), service: Dom::from_ref(service),
uuid: uuid, uuid,
properties: Dom::from_ref(properties), properties: Dom::from_ref(properties),
value: DomRefCell::new(None), value: DomRefCell::new(None),
instance_id: instance_id, instance_id,
} }
} }

View file

@ -40,9 +40,9 @@ impl BluetoothRemoteGATTService {
BluetoothRemoteGATTService { BluetoothRemoteGATTService {
eventtarget: EventTarget::new_inherited(), eventtarget: EventTarget::new_inherited(),
device: Dom::from_ref(device), device: Dom::from_ref(device),
uuid: uuid, uuid,
is_primary: is_primary, is_primary,
instance_id: instance_id, instance_id,
} }
} }

View file

@ -24,7 +24,7 @@ pub struct BluetoothUUID {
} }
//https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx //https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx
const BLUETOOTH_ASSIGNED_SERVICES: &'static [(&'static str, u32)] = &[ const BLUETOOTH_ASSIGNED_SERVICES: &[(&str, u32)] = &[
("org.bluetooth.service.alert_notification", 0x1811_u32), ("org.bluetooth.service.alert_notification", 0x1811_u32),
("org.bluetooth.service.automation_io", 0x1815_u32), ("org.bluetooth.service.automation_io", 0x1815_u32),
("org.bluetooth.service.battery_service", 0x180f_u32), ("org.bluetooth.service.battery_service", 0x180f_u32),
@ -75,7 +75,7 @@ const BLUETOOTH_ASSIGNED_SERVICES: &'static [(&'static str, u32)] = &[
]; ];
//https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx //https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx
const BLUETOOTH_ASSIGNED_CHARCTERISTICS: &'static [(&'static str, u32)] = &[ const BLUETOOTH_ASSIGNED_CHARCTERISTICS: &[(&str, u32)] = &[
( (
"org.bluetooth.characteristic.aerobic_heart_rate_lower_limit", "org.bluetooth.characteristic.aerobic_heart_rate_lower_limit",
0x2a7e_u32, 0x2a7e_u32,
@ -562,12 +562,11 @@ const BLUETOOTH_ASSIGNED_DESCRIPTORS: &'static [(&'static str, u32)] = &[
("org.bluetooth.descriptor.time_trigger_setting", 0x290e_u32), ("org.bluetooth.descriptor.time_trigger_setting", 0x290e_u32),
]; ];
const BASE_UUID: &'static str = "-0000-1000-8000-00805f9b34fb"; const BASE_UUID: &str = "-0000-1000-8000-00805f9b34fb";
const SERVICE_PREFIX: &'static str = "org.bluetooth.service"; const SERVICE_PREFIX: &str = "org.bluetooth.service";
const CHARACTERISTIC_PREFIX: &'static str = "org.bluetooth.characteristic"; const CHARACTERISTIC_PREFIX: &str = "org.bluetooth.characteristic";
const DESCRIPTOR_PREFIX: &'static str = "org.bluetooth.descriptor"; const DESCRIPTOR_PREFIX: &str = "org.bluetooth.descriptor";
const VALID_UUID_REGEX: &'static str = const VALID_UUID_REGEX: &str = "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
// https://cs.chromium.org/chromium/src/third_party/WebKit/Source/modules/bluetooth/BluetoothUUID.cpp?l=314 // https://cs.chromium.org/chromium/src/third_party/WebKit/Source/modules/bluetooth/BluetoothUUID.cpp?l=314
const UUID_ERROR_MESSAGE: &'static str = "It must be a valid UUID alias (e.g. 0x1234), \ const UUID_ERROR_MESSAGE: &'static str = "It must be a valid UUID alias (e.g. 0x1234), \
UUID (lowercase hex characters e.g. '00001234-0000-1000-8000-00805f9b34fb'),\nor recognized standard name from"; UUID (lowercase hex characters e.g. '00001234-0000-1000-8000-00805f9b34fb'),\nor recognized standard name from";

View file

@ -39,11 +39,11 @@ impl CanvasPattern {
CanvasPattern { CanvasPattern {
reflector_: Reflector::new(), reflector_: Reflector::new(),
surface_data: surface_data, surface_data,
surface_size, surface_size,
repeat_x: x, repeat_x: x,
repeat_y: y, repeat_y: y,
origin_clean: origin_clean, origin_clean,
} }
} }
pub fn new( pub fn new(

View file

@ -32,7 +32,7 @@ impl Client {
Client { Client {
reflector_: Reflector::new(), reflector_: Reflector::new(),
active_worker: Default::default(), active_worker: Default::default(),
url: url, url,
frame_type: FrameType::None, frame_type: FrameType::None,
id: Uuid::new_v4(), id: Uuid::new_v4(),
} }

View file

@ -30,9 +30,9 @@ impl CloseEvent {
pub fn new_inherited(was_clean: bool, code: u16, reason: DOMString) -> CloseEvent { pub fn new_inherited(was_clean: bool, code: u16, reason: DOMString) -> CloseEvent {
CloseEvent { CloseEvent {
event: Event::new_inherited(), event: Event::new_inherited(),
was_clean: was_clean, was_clean,
code: code, code,
reason: reason, reason,
} }
} }

View file

@ -299,13 +299,13 @@ impl ImageCacheListener for HTMLVideoElement {
ImageResponse::Loaded(image, url) => { ImageResponse::Loaded(image, url) => {
debug!("Loaded poster image for video element: {:?}", url); debug!("Loaded poster image for video element: {:?}", url);
self.htmlmediaelement.process_poster_image_loaded(image); self.htmlmediaelement.process_poster_image_loaded(image);
LoadBlocker::terminate(&mut *self.load_blocker.borrow_mut()); LoadBlocker::terminate(&mut self.load_blocker.borrow_mut());
}, },
ImageResponse::MetadataLoaded(..) => {}, ImageResponse::MetadataLoaded(..) => {},
// The image cache may have loaded a placeholder for an invalid poster url // The image cache may have loaded a placeholder for an invalid poster url
ImageResponse::PlaceholderLoaded(..) | ImageResponse::None => { ImageResponse::PlaceholderLoaded(..) | ImageResponse::None => {
// A failed load should unblock the document load. // A failed load should unblock the document load.
LoadBlocker::terminate(&mut *self.load_blocker.borrow_mut()); LoadBlocker::terminate(&mut self.load_blocker.borrow_mut());
}, },
} }
} }

View file

@ -114,8 +114,8 @@ impl MediaFragmentParser {
} }
} else { } else {
let mut iterator = fragment.split(','); let mut iterator = fragment.split(',');
let start = parse_hms(iterator.next().ok_or_else(|| ())?)?; let start = parse_hms(iterator.next().ok_or(())?)?;
let end = parse_hms(iterator.next().ok_or_else(|| ())?)?; let end = parse_hms(iterator.next().ok_or(())?)?;
if iterator.next().is_some() || start >= end { if iterator.next().is_some() || start >= end {
return Err(()); return Err(());
@ -150,8 +150,8 @@ impl MediaFragmentParser {
.flat_map(|s| parse_hms(&s.time().to_string())) .flat_map(|s| parse_hms(&s.time().to_string()))
.collect(); .collect();
let end = hms.pop().ok_or_else(|| ())?; let end = hms.pop().ok_or(())?;
let start = hms.pop().ok_or_else(|| ())?; let start = hms.pop().ok_or(())?;
if !hms.is_empty() || start >= end { if !hms.is_empty() || start >= end {
return Err(()); return Err(());
@ -168,10 +168,10 @@ impl MediaFragmentParser {
let mut clipping = SpatialClipping { let mut clipping = SpatialClipping {
region: None, region: None,
x: queue.pop_front().ok_or_else(|| ())?, x: queue.pop_front().ok_or(())?,
y: queue.pop_front().ok_or_else(|| ())?, y: queue.pop_front().ok_or(())?,
width: queue.pop_front().ok_or_else(|| ())?, width: queue.pop_front().ok_or(())?,
height: queue.pop_front().ok_or_else(|| ())?, height: queue.pop_front().ok_or(())?,
}; };
if !queue.is_empty() { if !queue.is_empty() {
@ -209,10 +209,7 @@ impl From<&ServoUrl> for MediaFragmentParser {
// 5.1.1 Processing name-value components. // 5.1.1 Processing name-value components.
fn decode_octets(bytes: &[u8]) -> Vec<(Cow<str>, Cow<str>)> { fn decode_octets(bytes: &[u8]) -> Vec<(Cow<str>, Cow<str>)> {
form_urlencoded::parse(bytes) form_urlencoded::parse(bytes)
.filter(|(key, _)| match key.as_bytes() { .filter(|(key, _)| matches!(key.as_bytes(), b"t" | b"track" | b"id" | b"xywh"))
b"t" | b"track" | b"id" | b"xywh" => true,
_ => false,
})
.collect() .collect()
} }
@ -239,10 +236,7 @@ fn split_url(s: &str) -> (&str, &str) {
} }
fn is_byte_number(byte: u8) -> bool { fn is_byte_number(byte: u8) -> bool {
match byte { matches!(byte, 48..=57)
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 => true,
_ => false,
}
} }
fn split_prefix(s: &str) -> (Option<&str>, &str) { fn split_prefix(s: &str) -> (Option<&str>, &str) {
@ -320,13 +314,13 @@ fn parse_hms(s: &str) -> Result<f64, ()> {
}, },
2 => hms_to_seconds( 2 => hms_to_seconds(
0, 0,
parse_npt_minute(vec.pop_front().ok_or_else(|| ())?)?, parse_npt_minute(vec.pop_front().ok_or(())?)?,
parse_npt_seconds(vec.pop_front().ok_or_else(|| ())?)?, parse_npt_seconds(vec.pop_front().ok_or(())?)?,
), ),
3 => hms_to_seconds( 3 => hms_to_seconds(
vec.pop_front().ok_or_else(|| ())?.parse().map_err(|_| ())?, vec.pop_front().ok_or_else(|| ())?.parse().map_err(|_| ())?,
parse_npt_minute(vec.pop_front().ok_or_else(|| ())?)?, parse_npt_minute(vec.pop_front().ok_or(())?)?,
parse_npt_seconds(vec.pop_front().ok_or_else(|| ())?)?, parse_npt_seconds(vec.pop_front().ok_or(())?)?,
), ),
_ => return Err(()), _ => return Err(()),
}; };