Skip to content

Commit 7adad94

Browse files
authored
Fix cargo clippy (#1145)
1 parent 8160b01 commit 7adad94

File tree

6 files changed

+50
-18
lines changed

6 files changed

+50
-18
lines changed

commons/zenoh-buffers/src/slice.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl Writer for &mut [u8] {
7676
// SAFETY: this doesn't compile with simple assignment because the compiler
7777
// doesn't believe that the subslice has the same lifetime as the original slice,
7878
// so we transmute to assure it that it does.
79-
*self = unsafe { mem::transmute(lhs) };
79+
*self = unsafe { mem::transmute::<&mut [u8], &mut [u8]>(lhs) };
8080

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

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

127127
NonZeroUsize::new(len).ok_or(DidntWrite)
128128
}

commons/zenoh-config/src/lib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,11 @@ impl PluginsConfig {
10861086
for next in split {
10871087
match remove_from {
10881088
Value::Object(o) => match o.get_mut(current) {
1089-
Some(v) => unsafe { remove_from = std::mem::transmute(v) },
1089+
Some(v) => {
1090+
remove_from = unsafe {
1091+
std::mem::transmute::<&mut serde_json::Value, &mut serde_json::Value>(v)
1092+
}
1093+
}
10901094
None => bail!("{:?} has no {} property", o, current),
10911095
},
10921096
Value::Array(a) => {

commons/zenoh-keyexpr/src/keyexpr_tree/arc_tree.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,11 @@ where
159159
}
160160
// tags{ketree.arc.node.mut}
161161
fn node_mut(&'a self, token: &'a mut Token, at: &keyexpr) -> Option<Self::NodeMut> {
162-
self.node(unsafe { core::mem::transmute(&*token) }, at)
163-
.map(|(node, _)| (node, token))
162+
self.node(
163+
unsafe { core::mem::transmute::<&Token, &Token>(&*token) },
164+
at,
165+
)
166+
.map(|(node, _)| (node, token))
164167
}
165168
// tags{ketree.arc.node.or_create}
166169
fn node_or_create(&'a self, token: &'a mut Token, at: &keyexpr) -> Self::NodeMut {
@@ -236,7 +239,9 @@ where
236239
fn tree_iter_mut(&'a self, token: &'a mut Token) -> Self::TreeIterMut {
237240
let inner = ketree_borrow(&self.inner, token);
238241
TokenPacker {
239-
iter: TreeIter::new(unsafe { core::mem::transmute(&inner.children) }),
242+
iter: TreeIter::new(unsafe {
243+
core::mem::transmute::<&Children::Assoc, &Children::Assoc>(&inner.children)
244+
}),
240245
token,
241246
}
242247
}
@@ -288,7 +293,12 @@ where
288293
let inner = ketree_borrow(&self.inner, token);
289294
if inner.wildness.get() || key.is_wild() {
290295
IterOrOption::Iter(TokenPacker {
291-
iter: Intersection::new(unsafe { core::mem::transmute(&inner.children) }, key),
296+
iter: Intersection::new(
297+
unsafe {
298+
core::mem::transmute::<&Children::Assoc, &Children::Assoc>(&inner.children)
299+
},
300+
key,
301+
),
292302
token,
293303
})
294304
} else {
@@ -340,7 +350,10 @@ where
340350
if inner.wildness.get() || key.is_wild() {
341351
unsafe {
342352
IterOrOption::Iter(TokenPacker {
343-
iter: Inclusion::new(core::mem::transmute(&inner.children), key),
353+
iter: Inclusion::new(
354+
core::mem::transmute::<&Children::Assoc, &Children::Assoc>(&inner.children),
355+
key,
356+
),
344357
token,
345358
})
346359
}
@@ -393,7 +406,10 @@ where
393406
if inner.wildness.get() || key.is_wild() {
394407
unsafe {
395408
IterOrOption::Iter(TokenPacker {
396-
iter: Includer::new(core::mem::transmute(&inner.children), key),
409+
iter: Includer::new(
410+
core::mem::transmute::<&Children::Assoc, &Children::Assoc>(&inner.children),
411+
key,
412+
),
397413
token,
398414
})
399415
}

commons/zenoh-keyexpr/src/keyexpr_tree/box_tree.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ where
157157
if !node.children.is_empty() {
158158
node.weight.take()
159159
} else {
160-
let chunk = unsafe { core::mem::transmute::<_, &keyexpr>(node.chunk()) };
160+
let chunk = unsafe { core::mem::transmute::<&keyexpr, &keyexpr>(node.chunk()) };
161161
match node.parent {
162162
None => &mut self.children,
163163
Some(parent) => unsafe { &mut (*parent.as_ptr()).children },

commons/zenoh-keyexpr/src/keyexpr_tree/traits/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,10 @@ pub trait IKeyExprTree<'a, Weight> {
5454
Self::TreeIterItem: AsNode<Box<Self::Node>>,
5555
{
5656
self.tree_iter().filter_map(|node| {
57-
unsafe { core::mem::transmute::<_, Option<&Weight>>(node.as_node().weight()) }
58-
.map(|w| (node.as_node().keyexpr(), w))
57+
unsafe {
58+
core::mem::transmute::<Option<&Weight>, Option<&Weight>>(node.as_node().weight())
59+
}
60+
.map(|w| (node.as_node().keyexpr(), w))
5961
})
6062
}
6163

commons/zenoh-protocol/src/core/encoding.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl TryFrom<u8> for KnownEncoding {
8989
type Error = ZError;
9090
fn try_from(value: u8) -> Result<Self, Self::Error> {
9191
if value < consts::MIMES.len() as u8 + 1 {
92-
Ok(unsafe { mem::transmute(value) })
92+
Ok(unsafe { mem::transmute::<u8, KnownEncoding>(value) })
9393
} else {
9494
Err(zerror!("Unknown encoding"))
9595
}
@@ -213,9 +213,14 @@ impl From<&'static str> for Encoding {
213213
for (i, v) in consts::MIMES.iter().enumerate().skip(1) {
214214
if let Some(suffix) = s.strip_prefix(v) {
215215
if suffix.is_empty() {
216-
return Encoding::Exact(unsafe { mem::transmute(i as u8) });
216+
return Encoding::Exact(unsafe {
217+
mem::transmute::<u8, KnownEncoding>(i as u8)
218+
});
217219
} else {
218-
return Encoding::WithSuffix(unsafe { mem::transmute(i as u8) }, suffix.into());
220+
return Encoding::WithSuffix(
221+
unsafe { mem::transmute::<u8, KnownEncoding>(i as u8) },
222+
suffix.into(),
223+
);
219224
}
220225
}
221226
}
@@ -233,9 +238,14 @@ impl From<String> for Encoding {
233238
if s.starts_with(v) {
234239
s.replace_range(..v.len(), "");
235240
if s.is_empty() {
236-
return Encoding::Exact(unsafe { mem::transmute(i as u8) });
241+
return Encoding::Exact(unsafe {
242+
mem::transmute::<u8, KnownEncoding>(i as u8)
243+
});
237244
} else {
238-
return Encoding::WithSuffix(unsafe { mem::transmute(i as u8) }, s.into());
245+
return Encoding::WithSuffix(
246+
unsafe { mem::transmute::<u8, KnownEncoding>(i as u8) },
247+
s.into(),
248+
);
239249
}
240250
}
241251
}

0 commit comments

Comments
 (0)