Skip to content

Commit

Permalink
Fix cargo clippy (#1145)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets authored Jun 14, 2024
1 parent 8160b01 commit 7adad94
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 18 deletions.
6 changes: 3 additions & 3 deletions commons/zenoh-buffers/src/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Writer for &mut [u8] {
// SAFETY: this doesn't compile with simple assignment because the compiler
// doesn't believe that the subslice has the same lifetime as the original slice,
// so we transmute to assure it that it does.
*self = unsafe { mem::transmute(lhs) };
*self = unsafe { mem::transmute::<&mut [u8], &mut [u8]>(lhs) };

// SAFETY: this operation is safe since we check if len is non-zero.
Ok(unsafe { NonZeroUsize::new_unchecked(len) })
Expand All @@ -98,7 +98,7 @@ impl Writer for &mut [u8] {
// SAFETY: this doesn't compile with simple assignment because the compiler
// doesn't believe that the subslice has the same lifetime as the original slice,
// so we transmute to assure it that it does.
*self = unsafe { mem::transmute(lhs) };
*self = unsafe { mem::transmute::<&mut [u8], &mut [u8]>(lhs) };

Ok(())
}
Expand All @@ -122,7 +122,7 @@ impl Writer for &mut [u8] {
// SAFETY: this doesn't compile with simple assignment because the compiler
// doesn't believe that the subslice has the same lifetime as the original slice,
// so we transmute to assure it that it does.
*self = unsafe { mem::transmute(s) };
*self = unsafe { mem::transmute::<&mut [u8], &mut [u8]>(s) };

NonZeroUsize::new(len).ok_or(DidntWrite)
}
Expand Down
6 changes: 5 additions & 1 deletion commons/zenoh-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,11 @@ impl PluginsConfig {
for next in split {
match remove_from {
Value::Object(o) => match o.get_mut(current) {
Some(v) => unsafe { remove_from = std::mem::transmute(v) },
Some(v) => {
remove_from = unsafe {
std::mem::transmute::<&mut serde_json::Value, &mut serde_json::Value>(v)
}
}
None => bail!("{:?} has no {} property", o, current),
},
Value::Array(a) => {
Expand Down
28 changes: 22 additions & 6 deletions commons/zenoh-keyexpr/src/keyexpr_tree/arc_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,11 @@ where
}
// tags{ketree.arc.node.mut}
fn node_mut(&'a self, token: &'a mut Token, at: &keyexpr) -> Option<Self::NodeMut> {
self.node(unsafe { core::mem::transmute(&*token) }, at)
.map(|(node, _)| (node, token))
self.node(
unsafe { core::mem::transmute::<&Token, &Token>(&*token) },
at,
)
.map(|(node, _)| (node, token))
}
// tags{ketree.arc.node.or_create}
fn node_or_create(&'a self, token: &'a mut Token, at: &keyexpr) -> Self::NodeMut {
Expand Down Expand Up @@ -236,7 +239,9 @@ where
fn tree_iter_mut(&'a self, token: &'a mut Token) -> Self::TreeIterMut {
let inner = ketree_borrow(&self.inner, token);
TokenPacker {
iter: TreeIter::new(unsafe { core::mem::transmute(&inner.children) }),
iter: TreeIter::new(unsafe {
core::mem::transmute::<&Children::Assoc, &Children::Assoc>(&inner.children)
}),
token,
}
}
Expand Down Expand Up @@ -288,7 +293,12 @@ where
let inner = ketree_borrow(&self.inner, token);
if inner.wildness.get() || key.is_wild() {
IterOrOption::Iter(TokenPacker {
iter: Intersection::new(unsafe { core::mem::transmute(&inner.children) }, key),
iter: Intersection::new(
unsafe {
core::mem::transmute::<&Children::Assoc, &Children::Assoc>(&inner.children)
},
key,
),
token,
})
} else {
Expand Down Expand Up @@ -340,7 +350,10 @@ where
if inner.wildness.get() || key.is_wild() {
unsafe {
IterOrOption::Iter(TokenPacker {
iter: Inclusion::new(core::mem::transmute(&inner.children), key),
iter: Inclusion::new(
core::mem::transmute::<&Children::Assoc, &Children::Assoc>(&inner.children),
key,
),
token,
})
}
Expand Down Expand Up @@ -393,7 +406,10 @@ where
if inner.wildness.get() || key.is_wild() {
unsafe {
IterOrOption::Iter(TokenPacker {
iter: Includer::new(core::mem::transmute(&inner.children), key),
iter: Includer::new(
core::mem::transmute::<&Children::Assoc, &Children::Assoc>(&inner.children),
key,
),
token,
})
}
Expand Down
2 changes: 1 addition & 1 deletion commons/zenoh-keyexpr/src/keyexpr_tree/box_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ where
if !node.children.is_empty() {
node.weight.take()
} else {
let chunk = unsafe { core::mem::transmute::<_, &keyexpr>(node.chunk()) };
let chunk = unsafe { core::mem::transmute::<&keyexpr, &keyexpr>(node.chunk()) };
match node.parent {
None => &mut self.children,
Some(parent) => unsafe { &mut (*parent.as_ptr()).children },
Expand Down
6 changes: 4 additions & 2 deletions commons/zenoh-keyexpr/src/keyexpr_tree/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ pub trait IKeyExprTree<'a, Weight> {
Self::TreeIterItem: AsNode<Box<Self::Node>>,
{
self.tree_iter().filter_map(|node| {
unsafe { core::mem::transmute::<_, Option<&Weight>>(node.as_node().weight()) }
.map(|w| (node.as_node().keyexpr(), w))
unsafe {
core::mem::transmute::<Option<&Weight>, Option<&Weight>>(node.as_node().weight())
}
.map(|w| (node.as_node().keyexpr(), w))
})
}

Expand Down
20 changes: 15 additions & 5 deletions commons/zenoh-protocol/src/core/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl TryFrom<u8> for KnownEncoding {
type Error = ZError;
fn try_from(value: u8) -> Result<Self, Self::Error> {
if value < consts::MIMES.len() as u8 + 1 {
Ok(unsafe { mem::transmute(value) })
Ok(unsafe { mem::transmute::<u8, KnownEncoding>(value) })
} else {
Err(zerror!("Unknown encoding"))
}
Expand Down Expand Up @@ -213,9 +213,14 @@ impl From<&'static str> for Encoding {
for (i, v) in consts::MIMES.iter().enumerate().skip(1) {
if let Some(suffix) = s.strip_prefix(v) {
if suffix.is_empty() {
return Encoding::Exact(unsafe { mem::transmute(i as u8) });
return Encoding::Exact(unsafe {
mem::transmute::<u8, KnownEncoding>(i as u8)
});
} else {
return Encoding::WithSuffix(unsafe { mem::transmute(i as u8) }, suffix.into());
return Encoding::WithSuffix(
unsafe { mem::transmute::<u8, KnownEncoding>(i as u8) },
suffix.into(),
);
}
}
}
Expand All @@ -233,9 +238,14 @@ impl From<String> for Encoding {
if s.starts_with(v) {
s.replace_range(..v.len(), "");
if s.is_empty() {
return Encoding::Exact(unsafe { mem::transmute(i as u8) });
return Encoding::Exact(unsafe {
mem::transmute::<u8, KnownEncoding>(i as u8)
});
} else {
return Encoding::WithSuffix(unsafe { mem::transmute(i as u8) }, s.into());
return Encoding::WithSuffix(
unsafe { mem::transmute::<u8, KnownEncoding>(i as u8) },
s.into(),
);
}
}
}
Expand Down

0 comments on commit 7adad94

Please sign in to comment.