Skip to content

Commit

Permalink
Fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
wks committed Apr 15, 2024
1 parent 2da71a0 commit 03fb6d4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/util/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,14 @@ impl ObjectReference {
NonZeroUsize::new(addr.0).map(ObjectReference)
}

/// Like `from_raw_address`, but assume `addr` is not zero.
/// Like `from_raw_address`, but assume `addr` is not zero. This can be used to elide a check
/// against zero for performance-critical code.
///
/// # Safety
///
/// This method assumes `addr` is not zero. It should only be used in cases where we know at
/// compile time that the input cannot be zero. For example, if we compute the address by
/// adding a positive offset to a non-zero address, we know the result must not be zero.
pub unsafe fn from_raw_address_unchecked(addr: Address) -> ObjectReference {
debug_assert!(!addr.is_zero());
ObjectReference(NonZeroUsize::new_unchecked(addr.0))
Expand Down
8 changes: 2 additions & 6 deletions src/util/metadata/vo_bit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ pub fn is_vo_bit_set<VM: VMBinding>(object: ObjectReference) -> bool {
/// Check if an address can be turned directly into an object reference using the VO bit.
/// If so, return `Some(object)`. Otherwise return `None`.
pub fn is_vo_bit_set_for_addr<VM: VMBinding>(address: Address) -> Option<ObjectReference> {
let Some(potential_object) = ObjectReference::from_raw_address(address) else {
return None;
};
let potential_object = ObjectReference::from_raw_address(address)?;

let addr = potential_object.to_address::<VM>();

Expand All @@ -126,9 +124,7 @@ pub fn is_vo_bit_set_for_addr<VM: VMBinding>(address: Address) -> Option<ObjectR
///
/// This is unsafe: check the comment on `side_metadata::load`
pub unsafe fn is_vo_bit_set_unsafe<VM: VMBinding>(address: Address) -> Option<ObjectReference> {
let Some(potential_object) = ObjectReference::from_raw_address(address) else {
return None;
};
let potential_object = ObjectReference::from_raw_address(address)?;

let addr = potential_object.to_address::<VM>();

Expand Down

0 comments on commit 03fb6d4

Please sign in to comment.