Remove redundant field names from structs

These were flagged by `cargo clippy`:

    warning: redundant field names in struct initialization

There are plenty more redundant field names, but I only changed the ones
where the initialization was a single line of code. I still prefer the
redundant style for multi-line initializations (and I'm under the
impression that others agree), so I've also disabled the warning.
This commit is contained in:
Alex Crawford 2020-12-27 11:19:56 -08:00
parent adce62a795
commit e27f6cb564
9 changed files with 17 additions and 26 deletions

View File

@ -1156,11 +1156,7 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
Icmpv6Repr::EchoRequest { ident, seq_no, data } => {
match ip_repr {
IpRepr::Ipv6(ipv6_repr) => {
let icmp_reply_repr = Icmpv6Repr::EchoReply {
ident: ident,
seq_no: seq_no,
data: data
};
let icmp_reply_repr = Icmpv6Repr::EchoReply { ident, seq_no, data };
Ok(self.icmpv6_reply(ipv6_repr, icmp_reply_repr))
},
_ => Err(Error::Unrecognized),
@ -1295,11 +1291,7 @@ impl<'b, 'c, 'e> InterfaceInner<'b, 'c, 'e> {
// Respond to echo requests.
#[cfg(feature = "proto-ipv4")]
Icmpv4Repr::EchoRequest { ident, seq_no, data } => {
let icmp_reply_repr = Icmpv4Repr::EchoReply {
ident: ident,
seq_no: seq_no,
data: data
};
let icmp_reply_repr = Icmpv4Repr::EchoReply { ident, seq_no, data };
match ip_repr {
IpRepr::Ipv4(ipv4_repr) => Ok(self.icmpv4_reply(ipv4_repr, icmp_reply_repr)),
_ => Err(Error::Unrecognized),

View File

@ -91,6 +91,7 @@ compile_error!("at least one socket needs to be enabled"); */
#![allow(clippy::if_same_then_else)]
#![allow(clippy::manual_non_exhaustive)]
#![allow(clippy::match_like_matches_macro)]
#![allow(clippy::redundant_field_names)]
#[cfg(feature = "alloc")]
extern crate alloc;

View File

@ -44,7 +44,7 @@ impl<'a> Device<'a> for Loopback {
fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
self.queue.pop_front().map(move |buffer| {
let rx = RxToken { buffer: buffer };
let rx = RxToken { buffer };
let tx = TxToken { queue: &mut self.queue };
(rx, tx)
})

View File

@ -146,8 +146,8 @@ impl<'a, D, S> Device<'a> for PcapWriter<D, S>
fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
let &mut Self { ref mut lower, ref sink, mode, .. } = self;
lower.receive().map(|(rx_token, tx_token)| {
let rx = RxToken { token: rx_token, sink: sink.clone(), mode: mode };
let tx = TxToken { token: tx_token, sink: sink.clone(), mode: mode };
let rx = RxToken { token: rx_token, sink: sink.clone(), mode };
let tx = TxToken { token: tx_token, sink: sink.clone(), mode };
(rx, tx)
})
}
@ -155,7 +155,7 @@ impl<'a, D, S> Device<'a> for PcapWriter<D, S>
fn transmit(&'a mut self) -> Option<Self::TxToken> {
let &mut Self { ref mut lower, ref sink, mode } = self;
lower.transmit().map(|token| {
TxToken { token, sink: sink.clone(), mode: mode }
TxToken { token, sink: sink.clone(), mode }
})
}
}

View File

@ -52,8 +52,8 @@ impl<'a, D, P> Device<'a> for Tracer<D, P>
fn receive(&'a mut self) -> Option<(Self::RxToken, Self::TxToken)> {
let &mut Self { ref mut inner, writer, .. } = self;
inner.receive().map(|(rx_token, tx_token)| {
let rx = RxToken { token: rx_token, writer: writer };
let tx = TxToken { token: tx_token, writer: writer };
let rx = RxToken { token: rx_token, writer };
let tx = TxToken { token: tx_token, writer };
(rx, tx)
})
}
@ -61,7 +61,7 @@ impl<'a, D, P> Device<'a> for Tracer<D, P>
fn transmit(&'a mut self) -> Option<Self::TxToken> {
let &mut Self { ref mut inner, writer } = self;
inner.transmit().map(|tx_token| {
TxToken { token: tx_token, writer: writer }
TxToken { token: tx_token, writer }
})
}
}

View File

@ -38,9 +38,7 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
pub fn new<SocketsT>(sockets: SocketsT) -> Set<'a, 'b, 'c>
where SocketsT: Into<ManagedSlice<'a, Option<Item<'b, 'c>>>> {
let sockets = sockets.into();
Set {
sockets: sockets
}
Set { sockets }
}
/// Add a socket to the set with the reference count 1, and return its handle.
@ -55,7 +53,7 @@ impl<'a, 'b: 'a, 'c: 'a + 'b> Set<'a, 'b, 'c> {
net_trace!("[{}]: adding", index);
let handle = Handle(index);
socket.meta_mut().handle = handle;
*slot = Some(Item { socket: socket, refs: 1 });
*slot = Some(Item { socket, refs: 1 });
handle
}

View File

@ -408,7 +408,7 @@ impl Endpoint {
/// Create an endpoint address from given address and port.
pub fn new(addr: Address, port: u16) -> Endpoint {
Endpoint { addr: addr, port: port }
Endpoint { addr, port }
}
/// Query whether the endpoint has a specified address and port.
@ -455,13 +455,13 @@ impl fmt::Display for Endpoint {
impl From<u16> for Endpoint {
fn from(port: u16) -> Endpoint {
Endpoint { addr: Address::Unspecified, port: port }
Endpoint { addr: Address::Unspecified, port }
}
}
impl<T: Into<Address>> From<(T, u16)> for Endpoint {
fn from((addr, port): (T, u16)) -> Endpoint {
Endpoint { addr: addr.into(), port: port }
Endpoint { addr: addr.into(), port }
}
}

View File

@ -43,7 +43,7 @@ impl PrettyIndent {
/// Create an indentation state. The entire listing will be indented by the width
/// of `prefix`, and `prefix` will appear at the start of the first line.
pub fn new(prefix: &'static str) -> PrettyIndent {
PrettyIndent { prefix: prefix, level: 0 }
PrettyIndent { prefix, level: 0 }
}
/// Increase indentation level.

View File

@ -629,7 +629,7 @@ impl<'a> TcpOption<'a> {
option = TcpOption::SackRange(sack_ranges);
},
(_, _) =>
option = TcpOption::Unknown { kind: kind, data: data }
option = TcpOption::Unknown { kind, data }
}
}
}