Fix some Clippy lints.

This commit is contained in:
Teymour Aldridge 2022-08-04 00:13:36 +08:00
parent c23adde5a3
commit 3e5cd8815d
14 changed files with 37 additions and 43 deletions

View file

@ -8,10 +8,9 @@ use std::cell::RefCell;
use std::collections::HashMap; use std::collections::HashMap;
use std::string::String; use std::string::String;
const EXCLUDE_READS: &'static str = "exclude-reads"; const EXCLUDE_READS: &str = "exclude-reads";
const EXCLUDE_WRITES: &'static str = "exclude-writes"; const EXCLUDE_WRITES: &str = "exclude-writes";
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}";
thread_local!(pub static BLUETOOTH_BLOCKLIST: RefCell<BluetoothBlocklist> = thread_local!(pub static BLUETOOTH_BLOCKLIST: RefCell<BluetoothBlocklist> =
RefCell::new(BluetoothBlocklist(parse_blocklist()))); RefCell::new(BluetoothBlocklist(parse_blocklist())));
@ -108,5 +107,5 @@ fn parse_blocklist() -> Option<HashMap<String, Blocklist>> {
result.insert(uuid.to_string(), exclude_type); result.insert(uuid.to_string(), exclude_type);
} }
// Step 5 // Step 5
return Some(result); Some(result)
} }

View file

@ -44,16 +44,16 @@ impl BluetoothScanfilter {
service_data: Option<ServiceData>, service_data: Option<ServiceData>,
) -> BluetoothScanfilter { ) -> BluetoothScanfilter {
BluetoothScanfilter { BluetoothScanfilter {
name: name, name,
name_prefix: name_prefix, name_prefix,
services: ServiceUUIDSequence::new(services), services: ServiceUUIDSequence::new(services),
manufacturer_data: manufacturer_data, manufacturer_data: manufacturer_data,
service_data: service_data, service_data,
} }
} }
pub fn get_name(&self) -> Option<&str> { pub fn get_name(&self) -> Option<&str> {
self.name.as_ref().map(|s| s.as_str()) self.name.as_deref()
} }
pub fn get_name_prefix(&self) -> &str { pub fn get_name_prefix(&self) -> &str {

View file

@ -432,7 +432,7 @@ fn print_debug_usage(app: &str) -> ! {
"Emit native OS signposts for profile events (currently macOS only)", "Emit native OS signposts for profile events (currently macOS only)",
); );
println!(""); println!();
process::exit(0) process::exit(0)
} }

View file

@ -68,7 +68,7 @@ impl Build {
self.path_stack.push(field.name.clone()); self.path_stack.push(field.name.clone());
if let FieldType::NewTypeDef(new_def) = &field.field_type { if let FieldType::NewTypeDef(new_def) = &field.field_type {
self.walk(&new_def)?; self.walk(new_def)?;
} else { } else {
let pref_name = let pref_name =
self.pref_name(field, &self.path_stack[..self.path_stack.len() - 1]); self.pref_name(field, &self.path_stack[..self.path_stack.len() - 1]);
@ -154,7 +154,7 @@ impl Build {
} }
}, },
FieldType::Existing(type_name) => { FieldType::Existing(type_name) => {
let pref_name = self.pref_name(field, &path_stack); let pref_name = self.pref_name(field, path_stack);
let attributes = field.get_attributes(&pref_name); let attributes = field.get_attributes(&pref_name);
quote! { quote! {
#attributes #attributes

View file

@ -334,7 +334,7 @@ pub enum NetworkEvent {
impl TimelineMarker { impl TimelineMarker {
pub fn start(name: String) -> StartedTimelineMarker { pub fn start(name: String) -> StartedTimelineMarker {
StartedTimelineMarker { StartedTimelineMarker {
name: name, name,
start_time: PreciseTime::now(), start_time: PreciseTime::now(),
start_stack: None, start_stack: None,
} }

View file

@ -36,12 +36,11 @@ mod platform {
#[inline] #[inline]
pub unsafe fn alloc(size: usize, align: usize) -> *mut u8 { pub unsafe fn alloc(size: usize, align: usize) -> *mut u8 {
let ptr = if align <= MIN_ALIGN { if align <= MIN_ALIGN {
libc::malloc(size) as *mut u8 libc::malloc(size) as *mut u8
} else { } else {
aligned_malloc(size, align) aligned_malloc(size, align)
}; }
ptr
} }
#[inline] #[inline]

View file

@ -49,6 +49,7 @@ impl<T: 'static> Shared<T> {
} }
} }
#[allow(clippy::mut_from_ref)]
pub unsafe fn as_mut(&self) -> &mut T { pub unsafe fn as_mut(&self) -> &mut T {
&mut *self.ptr.as_ptr() &mut *self.ptr.as_ptr()
} }

View file

@ -202,7 +202,7 @@ impl SafeHash {
// effectively reducing the hashes by one bit. // effectively reducing the hashes by one bit.
// //
// Truncate hash to fit in `HashUint`. // Truncate hash to fit in `HashUint`.
let hash_bits = size_of::<HashUint>() * 8; let hash_bits = HashUint::BITS;
SafeHash { SafeHash {
hash: (1 << (hash_bits - 1)) | (hash as HashUint), hash: (1 << (hash_bits - 1)) | (hash as HashUint),
} }
@ -243,7 +243,7 @@ impl<K, V> RawBucket<K, V> {
self.hash_start.offset(self.idx as isize) self.hash_start.offset(self.idx as isize)
} }
unsafe fn pair(&self) -> *mut (K, V) { unsafe fn pair(&self) -> *mut (K, V) {
self.pair_start.offset(self.idx as isize) as *mut (K, V) self.pair_start.add(self.idx) as *mut (K, V)
} }
unsafe fn hash_pair(&self) -> (*mut HashUint, *mut (K, V)) { unsafe fn hash_pair(&self) -> (*mut HashUint, *mut (K, V)) {
(self.hash(), self.pair()) (self.hash(), self.pair())
@ -824,7 +824,7 @@ impl<K, V> RawTable<K, V> {
unsafe { unsafe {
RawBucket { RawBucket {
hash_start: buffer as *mut HashUint, hash_start: buffer as *mut HashUint,
pair_start: buffer.offset(pairs_offset as isize) as *const (K, V), pair_start: buffer.add(pairs_offset) as *const (K, V),
idx: index, idx: index,
_marker: marker::PhantomData, _marker: marker::PhantomData,
} }

View file

@ -637,7 +637,7 @@ impl fmt::Debug for HangProfile {
write!(fmt, "HangProfile backtrace:")?; write!(fmt, "HangProfile backtrace:")?;
if self.backtrace.len() == 0 { if self.backtrace.is_empty() {
write!(fmt, "backtrace failed to resolve")?; write!(fmt, "backtrace failed to resolve")?;
return Ok(()); return Ok(());
} }

View file

@ -57,7 +57,7 @@ impl RelativePos {
pub fn from_opts(start: Option<i64>, end: Option<i64>) -> RelativePos { pub fn from_opts(start: Option<i64>, end: Option<i64>) -> RelativePos {
RelativePos { RelativePos {
start: start.unwrap_or(0), start: start.unwrap_or(0),
end: end, end,
} }
} }

View file

@ -226,7 +226,7 @@ impl Response {
/// Convert to a filtered response, of type `filter_type`. /// Convert to a filtered response, of type `filter_type`.
/// Do not use with type Error or Default /// Do not use with type Error or Default
#[cfg_attr(rustfmt, rustfmt_skip)] #[rustfmt::skip]
pub fn to_filtered(self, filter_type: ResponseType) -> Response { pub fn to_filtered(self, filter_type: ResponseType) -> Response {
match filter_type { match filter_type {
ResponseType::Default | ResponseType::Default |

View file

@ -286,21 +286,21 @@ impl<'tcx> LateLintPass<'tcx> for UnrootedPass {
} }
} }
if !in_new_function { if !in_new_function &&
if is_unrooted_ty(&self.symbols, cx, sig.output().skip_binder(), false) { is_unrooted_ty(&self.symbols, cx, sig.output().skip_binder(), false)
cx.lint(UNROOTED_MUST_ROOT, |lint| { {
lint.build("Type must be rooted") cx.lint(UNROOTED_MUST_ROOT, |lint| {
.set_span(decl.output.span()) lint.build("Type must be rooted")
.emit() .set_span(decl.output.span())
}) .emit()
} })
} }
} }
let mut visitor = FnDefVisitor { let mut visitor = FnDefVisitor {
symbols: &self.symbols, symbols: &self.symbols,
cx: cx, cx,
in_new_function: in_new_function, in_new_function,
}; };
visit::walk_expr(&mut visitor, &body.value); visit::walk_expr(&mut visitor, &body.value);
} }
@ -331,7 +331,7 @@ impl<'a, 'tcx> visit::Visitor<'tcx> for FnDefVisitor<'a, 'tcx> {
match expr.kind { match expr.kind {
// Trait casts from #[unrooted_must_root_lint::must_root] types are not allowed // Trait casts from #[unrooted_must_root_lint::must_root] types are not allowed
ExprKind::Cast(ref subexpr, _) => require_rooted(cx, self.in_new_function, &*subexpr), ExprKind::Cast(subexpr, _) => require_rooted(cx, self.in_new_function, &subexpr),
// This catches assignments... the main point of this would be to catch mutable // This catches assignments... the main point of this would be to catch mutable
// references to `JS<T>`. // references to `JS<T>`.
// FIXME: Enable this? Triggers on certain kinds of uses of DomRefCell. // FIXME: Enable this? Triggers on certain kinds of uses of DomRefCell.
@ -362,7 +362,7 @@ impl<'a, 'tcx> visit::Visitor<'tcx> for FnDefVisitor<'a, 'tcx> {
hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, ..) | hir::PatKind::Binding(hir::BindingAnnotation::Unannotated, ..) |
hir::PatKind::Binding(hir::BindingAnnotation::Mutable, ..) => { hir::PatKind::Binding(hir::BindingAnnotation::Mutable, ..) => {
let ty = cx.typeck_results().pat_ty(pat); let ty = cx.typeck_results().pat_ty(pat);
if is_unrooted_ty(&self.symbols, cx, ty, self.in_new_function) { if is_unrooted_ty(self.symbols, cx, ty, self.in_new_function) {
cx.lint(UNROOTED_MUST_ROOT, |lint| { cx.lint(UNROOTED_MUST_ROOT, |lint| {
lint.build(&format!("Expression of type {:?} must be rooted", ty)) lint.build(&format!("Expression of type {:?} must be rooted", ty))
.set_span(pat.span) .set_span(pat.span)

View file

@ -831,6 +831,7 @@ impl<H, T> Arc<HeaderSlice<H, [T]>> {
} }
#[inline] #[inline]
#[allow(clippy::uninit_vec)]
unsafe fn allocate_buffer<W>(size: usize) -> *mut u8 { unsafe fn allocate_buffer<W>(size: usize) -> *mut u8 {
// We use Vec because the underlying allocation machinery isn't // We use Vec because the underlying allocation machinery isn't
// available in stable Rust. To avoid alignment issues, we allocate // available in stable Rust. To avoid alignment issues, we allocate
@ -1101,9 +1102,7 @@ impl<T> Clone for RawOffsetArc<T> {
impl<T> Drop for RawOffsetArc<T> { impl<T> Drop for RawOffsetArc<T> {
fn drop(&mut self) { fn drop(&mut self) {
let _ = Arc::from_raw_offset(RawOffsetArc { let _ = Arc::from_raw_offset(RawOffsetArc { ptr: self.ptr });
ptr: self.ptr.clone(),
});
} }
} }
@ -1117,10 +1116,6 @@ impl<T: PartialEq> PartialEq for RawOffsetArc<T> {
fn eq(&self, other: &RawOffsetArc<T>) -> bool { fn eq(&self, other: &RawOffsetArc<T>) -> bool {
*(*self) == *(*other) *(*self) == *(*other)
} }
fn ne(&self, other: &RawOffsetArc<T>) -> bool {
*(*self) != *(*other)
}
} }
impl<T> RawOffsetArc<T> { impl<T> RawOffsetArc<T> {
@ -1252,7 +1247,7 @@ impl<'a, T> ArcBorrow<'a, T> {
/// Compare two `ArcBorrow`s via pointer equality. Will only return /// Compare two `ArcBorrow`s via pointer equality. Will only return
/// true if they come from the same allocation /// true if they come from the same allocation
pub fn ptr_eq(this: &Self, other: &Self) -> bool { pub fn ptr_eq(this: &Self, other: &Self) -> bool {
this.0 as *const T == other.0 as *const T std::ptr::eq(this.0, other.0)
} }
/// Temporarily converts |self| into a bonafide Arc and exposes it to the /// Temporarily converts |self| into a bonafide Arc and exposes it to the

View file

@ -123,7 +123,7 @@ fn derive_variant_fields_expr(
let mut iter = bindings let mut iter = bindings
.iter() .iter()
.filter_map(|binding| { .filter_map(|binding| {
let attrs = cg::parse_field_attrs::<CssFieldAttrs>(&binding.ast()); let attrs = cg::parse_field_attrs::<CssFieldAttrs>(binding.ast());
if attrs.skip { if attrs.skip {
return None; return None;
} }