mirror of
https://github.com/servo/servo.git
synced 2025-09-30 00:29:14 +01:00
clippy: Fix a variety of warnings in components/script/dom (#31894)
This commit is contained in:
parent
4a68243f65
commit
b0196ad373
10 changed files with 45 additions and 43 deletions
|
@ -76,8 +76,16 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// Represents values that can be rooted through a stable address that will
|
||||
/// `StableTraceObject` represents values that can be rooted through a stable address that will
|
||||
/// not change for their whole lifetime.
|
||||
/// It is an unsafe trait that requires implementors to ensure certain safety guarantees.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// Implementors of this trait must ensure that the `trace` method correctly accounts for all
|
||||
/// owned and referenced objects, so that the garbage collector can accurately determine which
|
||||
/// objects are still in use. Failing to adhere to this contract may result in undefined behavior,
|
||||
/// such as use-after-free errors.
|
||||
pub unsafe trait StableTraceObject {
|
||||
/// Returns a stable trace object which address won't change for the whole
|
||||
/// lifetime of the value.
|
||||
|
@ -267,10 +275,7 @@ impl RootCollection {
|
|||
unsafe fn unroot(&self, object: *const dyn JSTraceable) {
|
||||
assert_in_script();
|
||||
let roots = &mut *self.roots.get();
|
||||
match roots
|
||||
.iter()
|
||||
.rposition(|r| *r as *const () == object as *const ())
|
||||
{
|
||||
match roots.iter().rposition(|r| std::ptr::eq(*r, object)) {
|
||||
Some(idx) => {
|
||||
roots.remove(idx);
|
||||
},
|
||||
|
@ -486,7 +491,7 @@ impl<T> Eq for Dom<T> {}
|
|||
|
||||
impl<T> PartialEq for LayoutDom<'_, T> {
|
||||
fn eq(&self, other: &Self) -> bool {
|
||||
self.value as *const T == other.value as *const T
|
||||
std::ptr::eq(self.value, other.value)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ impl ByteString {
|
|||
self.0.len()
|
||||
}
|
||||
|
||||
/// Checks if the ByteString is empty.
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.0.is_empty()
|
||||
}
|
||||
|
||||
/// Returns `self` with A–Z replaced by a–z.
|
||||
pub fn to_lower(&self) -> ByteString {
|
||||
ByteString::new(self.0.to_ascii_lowercase())
|
||||
|
@ -365,7 +370,7 @@ impl DOMString {
|
|||
let (year_int, month_int) = parse_month_component(value)?;
|
||||
|
||||
// Step 4
|
||||
if value.split("-").nth(2).is_some() {
|
||||
if value.split('-').nth(2).is_some() {
|
||||
return None;
|
||||
}
|
||||
// Step 5
|
||||
|
@ -443,7 +448,7 @@ impl DOMString {
|
|||
if !(
|
||||
// A valid number is the same as what rust considers to be valid,
|
||||
// except for +1., NaN, and Infinity.
|
||||
val.is_infinite() || val.is_nan() || input.ends_with(".") || input.starts_with('+')
|
||||
val.is_infinite() || val.is_nan() || input.ends_with('.') || input.starts_with('+')
|
||||
) {
|
||||
return Some(val);
|
||||
}
|
||||
|
@ -677,7 +682,7 @@ fn parse_month_component(value: &str) -> Option<(i32, u32)> {
|
|||
|
||||
// Step 4, 5
|
||||
let month_int = month.parse::<u32>().ok()?;
|
||||
if month.len() != 2 || month_int > 12 || month_int < 1 {
|
||||
if month.len() != 2 || !(1..=12).contains(&month_int) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
@ -169,12 +169,14 @@ unsafe extern "C" fn read_transfer_callback(
|
|||
let sc_holder = &mut *(closure as *mut StructuredDataHolder);
|
||||
let in_realm_proof = AlreadyInRealm::assert_for_cx(SafeJSContext::from_ptr(cx));
|
||||
let owner = GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof));
|
||||
if let Ok(_) = <MessagePort as Transferable>::transfer_receive(
|
||||
if <MessagePort as Transferable>::transfer_receive(
|
||||
&owner,
|
||||
sc_holder,
|
||||
extra_data,
|
||||
return_object,
|
||||
) {
|
||||
)
|
||||
.is_ok()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ pub unsafe fn get_array_index_from_id(_cx: *mut JSContext, id: HandleId) -> Opti
|
|||
let first_char = char::decode_utf16(chars.iter().cloned())
|
||||
.next()
|
||||
.map_or('\0', |r| r.unwrap_or('\0'));
|
||||
if first_char < 'a' || first_char > 'z' {
|
||||
if !('a'..='z').contains(&first_char) {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
|
@ -90,8 +90,7 @@ pub enum XMLName {
|
|||
/// for details.
|
||||
pub fn xml_name_type(name: &str) -> XMLName {
|
||||
fn is_valid_start(c: char) -> bool {
|
||||
match c {
|
||||
':' |
|
||||
matches!(c, ':' |
|
||||
'A'..='Z' |
|
||||
'_' |
|
||||
'a'..='z' |
|
||||
|
@ -106,9 +105,7 @@ pub fn xml_name_type(name: &str) -> XMLName {
|
|||
'\u{3001}'..='\u{D7FF}' |
|
||||
'\u{F900}'..='\u{FDCF}' |
|
||||
'\u{FDF0}'..='\u{FFFD}' |
|
||||
'\u{10000}'..='\u{EFFFF}' => true,
|
||||
_ => false,
|
||||
}
|
||||
'\u{10000}'..='\u{EFFFF}')
|
||||
}
|
||||
|
||||
fn is_valid_continuation(c: char) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue