Closed
Description
Code sample
This code sample had an error that I introduced while trying to fix a clippy error.
impl<'a, P> Iterator for NlMessageIter<'a, NlTypeWrapper, P>
where
P: Nl + Debug,
{
type Item = Result<Nlmsghdr<NlTypeWrapper, P>, NlError>;
fn next(&mut self) -> Option<Self::Item> {
if let Some(true) = self.next_is_none {
return None;
}
if self.stored.is_empty() {
match self.socket_ref.recv_all_nl() {
Ok(mut rn) => {
while let Some(item) = rn.pop() {
self.stored.push(item)
}
}
Err(e) => return Some(Err(e)),
}
}
let next = self.stored.pop();
if let Some(ref n) = next {
if self.next_is_none.is_some() && if !n.nl_flags.contains(&NlmF::Multi) {
self.next_is_none = Some(true);
}
if n.nl_type == NlTypeWrapper::Nlmsg(Nlmsg::Done) {
return None;
}
}
next.map(Ok)
}
}
In particular, the line:
if self.next_is_none.is_some() && if !n.nl_flags.contains(&NlmF::Multi) {
has two if
s.
Changes made by rustfmt
This is the diff I received when I ran rustfmt:
diff --git a/src/socket.rs b/src/socket.rs
index 029c27a..c3f562d 100644
--- a/src/socket.rs
+++ b/src/socket.rs
@@ -125,11 +125,7 @@ where
}
let next = self.stored.pop();
if let Some(ref n) = next {
- if self.next_is_none.is_some() && if !n.nl_flags.contains(&NlmF::Multi) {
- self.next_is_none = Some(true);
}
- if n.nl_type == NlTypeWrapper::Nlmsg(Nlmsg::Done) {
- return None;
}
}
next.map(Ok)
Expected behavior
I would hope that rustfmt would throw a syntax error instead of deleting the code. Will rustfmt typically proceed even if there is a syntax error in the code? I don't think I've ever run rustfmt on malformed code before.