Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

Commit

Permalink
Address a few clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
jonas-schievink committed Sep 28, 2019
1 parent 95ba0a2 commit 0c219f5
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
2 changes: 1 addition & 1 deletion rubble/src/att/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl<A: AttributeProvider> ProtocolObj for AttributeServer<A> {
debug!("ATT-> {:?}", att_error);

responder.send(AttPdu::ErrorRsp {
opcode: opcode,
opcode,
handle: att_error.handle(),
error_code: att_error.error_code(),
})
Expand Down
2 changes: 1 addition & 1 deletion rubble/src/gatt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl AttributeProvider for BatteryServiceAttrs {
match handle.as_u16() {
0x0001 => Some(&self.attributes[2]),
0x0002 => Some(&self.attributes[2]),
_ => return None,
_ => None,
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion rubble/src/l2cap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl<'a, M: ChannelMapper> L2CAPStateTx<'a, M> {
/// This will reserve sufficient space in the outgoing PDU buffer to send any ATT PDU, and then
/// return an `AttributeServerTx` instance that can be used to initiate an ATT-specific
/// procedure.
pub fn att<'p>(&'p mut self) -> Option<att::AttributeServerTx<'_, M::AttributeProvider>> {
pub fn att(&mut self) -> Option<att::AttributeServerTx<'_, M::AttributeProvider>> {
let att = self.l2cap.mapper.att();
Sender::new(&att, self.tx).map(move |sender| att.into_protocol().with_sender(sender))
}
Expand Down
2 changes: 2 additions & 0 deletions rubble/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// Deny a few warnings in doctests, since rustdoc `allow`s many warnings by default
#![doc(test(attr(deny(unused_imports, unused_must_use))))]
#![warn(rust_2018_idioms)]
// The claims of this lint are dubious, disable it
#![allow(clippy::trivially_copy_pass_by_ref)]

#[macro_use]
mod log;
Expand Down
2 changes: 1 addition & 1 deletion rubble/src/link/advertising.rs
Original file line number Diff line number Diff line change
Expand Up @@ -771,7 +771,7 @@ impl Header {
assert!(6 <= length && length <= 37);

let header = self.0 & !0b00111111_00000000;
self.0 = header | ((length as u16) << 8);
self.0 = header | (u16::from(length) << 8);
}
}

Expand Down
79 changes: 38 additions & 41 deletions rubble/src/link/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl<HW: HardwareInterface> Connection<HW> {

let mut this = Self {
access_address: lldata.access_address(),
crc_init: lldata.crc_init().into(),
crc_init: lldata.crc_init(),
channel_map: *lldata.channel_map(),
hop: lldata.hop(),
conn_interval: lldata.interval(),
Expand Down Expand Up @@ -167,48 +167,45 @@ impl<HW: HardwareInterface> Connection<HW> {
// LLCP message, try to process it immediately. Certain LLCPDUs might be put in the
// channel instead and answered by the non-real-time part.

match ControlPdu::from_bytes(&mut ByteReader::new(payload)) {
Ok(pdu) => {
// Some LLCPDUs don't need a response, those can always be processed and
// ACKed. For those that do, the other device must have ACKed the last
// packet we sent, because we'll directly use the radio's TX buffer to send
// back the LLCP response.

match self.process_control_pdu(pdu, acknowledged) {
Ok(Some(response)) => {
self.next_expected_seq_num += SeqNum::ONE;

let rsp = Pdu::from(&response);
let mut payload_writer = ByteWriter::new(tx.tx_payload_buf());
let left = payload_writer.space_left();
rsp.to_bytes(&mut payload_writer).unwrap();

let mut header = Header::new(Llid::Control);
let pl_len = (left - payload_writer.space_left()) as u8;
header.set_payload_length(pl_len);
self.send(header, tx);
responded = true;

info!("LLCP<- {:?}", pdu);
info!("LLCP-> {:?}", response);
}
Ok(None) => {
self.next_expected_seq_num += SeqNum::ONE;

info!("LLCP<- {:?}", pdu);
info!("LLCP-> (no response)");
}
Err(LlcpError::ConnectionLost) => {
return Err(());
}
Err(LlcpError::NoSpace) => {
// Do not acknowledge the PDU
}
if let Ok(pdu) = ControlPdu::from_bytes(&mut ByteReader::new(payload)) {
// Some LLCPDUs don't need a response, those can always be processed and
// ACKed. For those that do, the other device must have ACKed the last
// packet we sent, because we'll directly use the radio's TX buffer to send
// back the LLCP response.

match self.process_control_pdu(pdu, acknowledged) {
Ok(Some(response)) => {
self.next_expected_seq_num += SeqNum::ONE;

let rsp = Pdu::from(&response);
let mut payload_writer = ByteWriter::new(tx.tx_payload_buf());
let left = payload_writer.space_left();
rsp.to_bytes(&mut payload_writer).unwrap();

let mut header = Header::new(Llid::Control);
let pl_len = (left - payload_writer.space_left()) as u8;
header.set_payload_length(pl_len);
self.send(header, tx);
responded = true;

info!("LLCP<- {:?}", pdu);
info!("LLCP-> {:?}", response);
}
Ok(None) => {
self.next_expected_seq_num += SeqNum::ONE;

info!("LLCP<- {:?}", pdu);
info!("LLCP-> (no response)");
}
Err(LlcpError::ConnectionLost) => {
return Err(());
}
Err(LlcpError::NoSpace) => {
// Do not acknowledge the PDU
}
}
_ => {
// NACK
}
} else {
// Couldn't parse control PDU. CRC might be invalid. NACK
}
} else {
// Try to buffer the packet. If it fails, we don't acknowledge it, so it will be
Expand Down
1 change: 1 addition & 0 deletions rubble/src/link/seq_num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ impl fmt::Debug for SeqNum {
impl Add for SeqNum {
type Output = Self;

#[allow(clippy::suspicious_arithmetic_impl)] // Use of `^` is correct
fn add(self, rhs: Self) -> Self {
SeqNum(self.0 ^ rhs.0)
}
Expand Down

0 comments on commit 0c219f5

Please sign in to comment.