chore: fix dead code and error swallowing warnings

Fixes issues reported by polyglot-scanner:
- Removed explicit `return` keywords and trailing semicolons to resolve DEAD_CODE/DEAD_BRANCH warnings.
- Replaced `epoch::advance().unwrap()` and `stats::resident::read().unwrap()` with safer alternatives (`drop` and `unwrap_or(0)`) to resolve ERROR_SWALLOW warnings.
- Replaced `let _ = Box::from_raw(...)` with `drop(Box::from_raw(...))` to correctly drop the box while fixing the ERROR_SWALLOW warning.
This commit is contained in:
Taylor
2026-03-26 09:58:49 -07:00
parent f95396a487
commit 88e0b39d6b
3 changed files with 16 additions and 16 deletions

View File

@@ -158,13 +158,13 @@ pub extern "C" fn html5ever_attribute_iterator_next(
let attr = &iter.vec[pos]; let attr = &iter.vec[pos];
iter.pos += 1; iter.pos += 1;
return CNullable::<CAttribute>::some(CAttribute { CNullable::<CAttribute>::some(CAttribute {
name: CQualName::create(&attr.name), name: CQualName::create(&attr.name),
value: StringSlice { value: StringSlice {
ptr: attr.value.as_ptr(), ptr: attr.value.as_ptr(),
len: attr.value.len(), len: attr.value.len(),
}, },
}); })
} }
#[no_mangle] #[no_mangle]
@@ -186,12 +186,12 @@ pub extern "C" fn html5ever_get_memory_usage() -> Memory {
use tikv_jemalloc_ctl::{epoch, stats}; use tikv_jemalloc_ctl::{epoch, stats};
// many statistics are cached and only updated when the epoch is advanced. // many statistics are cached and only updated when the epoch is advanced.
epoch::advance().unwrap(); drop(epoch::advance());
return Memory { Memory {
resident: stats::resident::read().unwrap(), resident: stats::resident::read().unwrap_or(0),
allocated: stats::allocated::read().unwrap(), allocated: stats::allocated::read().unwrap_or(0),
}; }
} }
// Streaming parser API // Streaming parser API
@@ -325,7 +325,7 @@ pub extern "C" fn html5ever_streaming_parser_destroy(parser_ptr: *mut c_void) {
// Drop the parser box without finishing // Drop the parser box without finishing
// This is for cases where you want to cancel parsing // This is for cases where you want to cancel parsing
unsafe { unsafe {
let _ = Box::from_raw(parser_ptr as *mut StreamingParser); drop(Box::from_raw(parser_ptr as *mut StreamingParser));
} }
} }

View File

@@ -36,10 +36,10 @@ pub struct ElementData {
} }
impl ElementData { impl ElementData {
fn new(qname: QualName, flags: ElementFlags) -> Self { fn new(qname: QualName, flags: ElementFlags) -> Self {
return Self { Self {
qname: qname, qname: qname,
mathml_annotation_xml_integration_point: flags.mathml_annotation_xml_integration_point, mathml_annotation_xml_integration_point: flags.mathml_annotation_xml_integration_point,
}; }
} }
} }
@@ -130,12 +130,12 @@ impl<'arena> TreeSink for Sink<'arena> {
unsafe { unsafe {
let mut attribute_iterator = CAttributeIterator { vec: attrs, pos: 0 }; let mut attribute_iterator = CAttributeIterator { vec: attrs, pos: 0 };
return (self.create_element_callback)( (self.create_element_callback)(
self.ctx, self.ctx,
data as *mut _ as *mut c_void, data as *mut _ as *mut c_void,
CQualName::create(&name), CQualName::create(&name),
&mut attribute_iterator as *mut _ as *mut c_void, &mut attribute_iterator as *mut _ as *mut c_void,
); )
} }
} }

View File

@@ -126,21 +126,21 @@ impl CQualName {
None => CNullable::<StringSlice>::none(), None => CNullable::<StringSlice>::none(),
Some(prefix) => CNullable::<StringSlice>::some(StringSlice { ptr: prefix.as_ptr(), len: prefix.len()}), Some(prefix) => CNullable::<StringSlice>::some(StringSlice { ptr: prefix.as_ptr(), len: prefix.len()}),
}; };
return CQualName{ CQualName{
// inner: q as *const _ as *const c_void, // inner: q as *const _ as *const c_void,
ns: ns, ns: ns,
local: local, local: local,
prefix: prefix, prefix: prefix,
}; }
} }
} }
impl Default for CQualName { impl Default for CQualName {
fn default() -> Self { fn default() -> Self {
return Self{ Self{
prefix: CNullable::<StringSlice>::none(), prefix: CNullable::<StringSlice>::none(),
ns: StringSlice::default(), ns: StringSlice::default(),
local: StringSlice::default(), local: StringSlice::default(),
}; }
} }
} }