Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clippy: Fix some warnings in components/script #31735

Merged
merged 7 commits into from Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 11 additions & 13 deletions components/script/dom/bluetooth.rs
Expand Up @@ -44,25 +44,23 @@ use std::rc::Rc;
use std::str::FromStr;
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:";
const FILTER_EMPTY_ERROR: &'static str =
const FILTER_EMPTY_ERROR: &str =
"'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 MANUFACTURER_DATA_ERROR: &'static str =
const FILTER_ERROR: &str = "A filter must restrict the devices in some way.";
const MANUFACTURER_DATA_ERROR: &str =
"'manufacturerData', if present, must be non-empty to filter devices.";
const MASK_LENGTH_ERROR: &'static str =
"`mask`, if present, must have the same length as `dataPrefix`.";
const MASK_LENGTH_ERROR: &str = "`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.
const MAX_DEVICE_NAME_LENGTH: usize = 248;
const NAME_PREFIX_ERROR: &'static 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 SERVICE_DATA_ERROR: &'static str =
"'serviceData', if present, must be non-empty to filter devices.";
const SERVICE_ERROR: &'static str = "'services', if present, must contain at least one service.";
const OPTIONS_ERROR: &'static str = "Fields of 'options' conflict with each other.
const NAME_PREFIX_ERROR: &str = "'namePrefix', if present, must be nonempty.";
const NAME_TOO_LONG_ERROR: &str = "A device name can't be longer than 248 bytes.";
const SERVICE_DATA_ERROR: &str = "'serviceData', if present, must be non-empty to filter devices.";
const SERVICE_ERROR: &str = "'services', if present, must contain at least one service.";
const OPTIONS_ERROR: &str = "Fields of 'options' conflict with each other.
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";

#[derive(JSTraceable, MallocSizeOf)]
Expand Down
8 changes: 4 additions & 4 deletions components/script/dom/bluetoothadvertisingevent.rs
Expand Up @@ -43,10 +43,10 @@ impl BluetoothAdvertisingEvent {
BluetoothAdvertisingEvent {
event: Event::new_inherited(),
device: Dom::from_ref(device),
name: name,
appearance: appearance,
tx_power: tx_power,
rssi: rssi,
name,
appearance,
tx_power,
rssi,
}
}

Expand Down
18 changes: 9 additions & 9 deletions components/script/dom/bluetoothcharacteristicproperties.rs
Expand Up @@ -39,15 +39,15 @@ impl BluetoothCharacteristicProperties {
) -> BluetoothCharacteristicProperties {
BluetoothCharacteristicProperties {
reflector_: Reflector::new(),
broadcast: broadcast,
read: read,
write_without_response: write_without_response,
write: write,
notify: notify,
indicate: indicate,
authenticated_signed_writes: authenticated_signed_writes,
reliable_write: reliable_write,
writable_auxiliaries: writable_auxiliaries,
broadcast,
read,
write_without_response,
write,
notify,
indicate,
authenticated_signed_writes,
reliable_write,
writable_auxiliaries,
}
}

Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/bluetoothdevice.rs
Expand Up @@ -57,8 +57,8 @@ impl BluetoothDevice {
) -> BluetoothDevice {
BluetoothDevice {
eventtarget: EventTarget::new_inherited(),
id: id,
name: name,
id,
name,
gatt: Default::default(),
context: Dom::from_ref(context),
attribute_instance_map: (
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/bluetoothremotegattcharacteristic.rs
Expand Up @@ -56,10 +56,10 @@ impl BluetoothRemoteGATTCharacteristic {
BluetoothRemoteGATTCharacteristic {
eventtarget: EventTarget::new_inherited(),
service: Dom::from_ref(service),
uuid: uuid,
uuid,
properties: Dom::from_ref(properties),
value: DomRefCell::new(None),
instance_id: instance_id,
instance_id,
}
}

Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/bluetoothremotegattservice.rs
Expand Up @@ -40,9 +40,9 @@ impl BluetoothRemoteGATTService {
BluetoothRemoteGATTService {
eventtarget: EventTarget::new_inherited(),
device: Dom::from_ref(device),
uuid: uuid,
is_primary: is_primary,
instance_id: instance_id,
uuid,
is_primary,
instance_id,
}
}

Expand Down
15 changes: 7 additions & 8 deletions components/script/dom/bluetoothuuid.rs
Expand Up @@ -24,7 +24,7 @@ pub struct BluetoothUUID {
}

//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.automation_io", 0x1815_u32),
("org.bluetooth.service.battery_service", 0x180f_u32),
Expand Down Expand Up @@ -75,7 +75,7 @@ const BLUETOOTH_ASSIGNED_SERVICES: &'static [(&'static str, u32)] = &[
];

//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",
0x2a7e_u32,
Expand Down Expand Up @@ -562,12 +562,11 @@ const BLUETOOTH_ASSIGNED_DESCRIPTORS: &'static [(&'static str, u32)] = &[
("org.bluetooth.descriptor.time_trigger_setting", 0x290e_u32),
];

const BASE_UUID: &'static str = "-0000-1000-8000-00805f9b34fb";
const SERVICE_PREFIX: &'static str = "org.bluetooth.service";
const CHARACTERISTIC_PREFIX: &'static str = "org.bluetooth.characteristic";
const DESCRIPTOR_PREFIX: &'static str = "org.bluetooth.descriptor";
const VALID_UUID_REGEX: &'static str =
"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
const BASE_UUID: &str = "-0000-1000-8000-00805f9b34fb";
const SERVICE_PREFIX: &str = "org.bluetooth.service";
const CHARACTERISTIC_PREFIX: &str = "org.bluetooth.characteristic";
const DESCRIPTOR_PREFIX: &str = "org.bluetooth.descriptor";
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}$";
// 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), \
UUID (lowercase hex characters e.g. '00001234-0000-1000-8000-00805f9b34fb'),\nor recognized standard name from";
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/canvaspattern.rs
Expand Up @@ -39,11 +39,11 @@ impl CanvasPattern {

CanvasPattern {
reflector_: Reflector::new(),
surface_data: surface_data,
surface_data,
surface_size,
repeat_x: x,
repeat_y: y,
origin_clean: origin_clean,
origin_clean,
}
}
pub fn new(
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/client.rs
Expand Up @@ -32,7 +32,7 @@ impl Client {
Client {
reflector_: Reflector::new(),
active_worker: Default::default(),
url: url,
url,
frame_type: FrameType::None,
id: Uuid::new_v4(),
}
Expand Down
6 changes: 3 additions & 3 deletions components/script/dom/closeevent.rs
Expand Up @@ -30,9 +30,9 @@ impl CloseEvent {
pub fn new_inherited(was_clean: bool, code: u16, reason: DOMString) -> CloseEvent {
CloseEvent {
event: Event::new_inherited(),
was_clean: was_clean,
code: code,
reason: reason,
was_clean,
code,
reason,
}
}

Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/htmlvideoelement.rs
Expand Up @@ -299,13 +299,13 @@ impl ImageCacheListener for HTMLVideoElement {
ImageResponse::Loaded(image, url) => {
debug!("Loaded poster image for video element: {:?}", url);
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(..) => {},
// The image cache may have loaded a placeholder for an invalid poster url
ImageResponse::PlaceholderLoaded(..) | ImageResponse::None => {
// A failed load should unblock the document load.
LoadBlocker::terminate(&mut *self.load_blocker.borrow_mut());
LoadBlocker::terminate(&mut self.load_blocker.borrow_mut());
},
}
}
Expand Down
34 changes: 14 additions & 20 deletions components/script/dom/mediafragmentparser.rs
Expand Up @@ -114,8 +114,8 @@ impl MediaFragmentParser {
}
} else {
let mut iterator = fragment.split(',');
let start = parse_hms(iterator.next().ok_or_else(|| ())?)?;
let end = parse_hms(iterator.next().ok_or_else(|| ())?)?;
let start = parse_hms(iterator.next().ok_or(())?)?;
let end = parse_hms(iterator.next().ok_or(())?)?;

if iterator.next().is_some() || start >= end {
return Err(());
Expand Down Expand Up @@ -150,8 +150,8 @@ impl MediaFragmentParser {
.flat_map(|s| parse_hms(&s.time().to_string()))
.collect();

let end = hms.pop().ok_or_else(|| ())?;
let start = hms.pop().ok_or_else(|| ())?;
let end = hms.pop().ok_or(())?;
let start = hms.pop().ok_or(())?;

if !hms.is_empty() || start >= end {
return Err(());
Expand All @@ -168,10 +168,10 @@ impl MediaFragmentParser {

let mut clipping = SpatialClipping {
region: None,
x: queue.pop_front().ok_or_else(|| ())?,
y: queue.pop_front().ok_or_else(|| ())?,
width: queue.pop_front().ok_or_else(|| ())?,
height: queue.pop_front().ok_or_else(|| ())?,
x: queue.pop_front().ok_or(())?,
y: queue.pop_front().ok_or(())?,
width: queue.pop_front().ok_or(())?,
height: queue.pop_front().ok_or(())?,
};

if !queue.is_empty() {
Expand Down Expand Up @@ -209,10 +209,7 @@ impl From<&ServoUrl> for MediaFragmentParser {
// 5.1.1 Processing name-value components.
fn decode_octets(bytes: &[u8]) -> Vec<(Cow<str>, Cow<str>)> {
form_urlencoded::parse(bytes)
.filter(|(key, _)| match key.as_bytes() {
b"t" | b"track" | b"id" | b"xywh" => true,
_ => false,
})
.filter(|(key, _)| matches!(key.as_bytes(), b"t" | b"track" | b"id" | b"xywh"))
.collect()
}

Expand All @@ -239,10 +236,7 @@ fn split_url(s: &str) -> (&str, &str) {
}

fn is_byte_number(byte: u8) -> bool {
match byte {
48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 => true,
_ => false,
}
matches!(byte, 48..=57)
}

fn split_prefix(s: &str) -> (Option<&str>, &str) {
Expand Down Expand Up @@ -320,13 +314,13 @@ fn parse_hms(s: &str) -> Result<f64, ()> {
},
2 => hms_to_seconds(
0,
parse_npt_minute(vec.pop_front().ok_or_else(|| ())?)?,
parse_npt_seconds(vec.pop_front().ok_or_else(|| ())?)?,
parse_npt_minute(vec.pop_front().ok_or(())?)?,
parse_npt_seconds(vec.pop_front().ok_or(())?)?,
),
3 => hms_to_seconds(
vec.pop_front().ok_or_else(|| ())?.parse().map_err(|_| ())?,
parse_npt_minute(vec.pop_front().ok_or_else(|| ())?)?,
parse_npt_seconds(vec.pop_front().ok_or_else(|| ())?)?,
parse_npt_minute(vec.pop_front().ok_or(())?)?,
parse_npt_seconds(vec.pop_front().ok_or(())?)?,
),
_ => return Err(()),
};
Expand Down