From 0134bb73995ebe4c4d2b0501435036f14db5954f Mon Sep 17 00:00:00 2001 From: whitequark Date: Sat, 22 Jun 2019 08:19:39 +0000 Subject: [PATCH] Bump Rust version requirement to 1.27. This allows us to use: (1.26) - impl Trait - autoderef in pattern matching - fixed slice patterns - inclusive ranges (1.27) - dyn Trait - #[must_use] on functions To prepare for edition change, dyn is added where applicable. Other edition changes would require bumping the requirement even higher, and so they are not applied for now. --- README.md | 2 +- examples/utils.rs | 6 +++--- src/phy/pcap_writer.rs | 2 +- src/wire/arp.rs | 2 +- src/wire/ethernet.rs | 2 +- src/wire/icmpv4.rs | 2 +- src/wire/igmp.rs | 2 +- src/wire/ipv4.rs | 2 +- src/wire/ipv6.rs | 2 +- src/wire/ndiscoption.rs | 2 +- src/wire/pretty_print.rs | 6 +++--- src/wire/tcp.rs | 2 +- src/wire/udp.rs | 2 +- 13 files changed, 17 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 80d833b..8db76ba 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ include complicated compile-time computations, such as macro or type tricks, eve at cost of performance degradation. _smoltcp_ does not need heap allocation *at all*, is [extensively documented][docs], -and compiles on stable Rust 1.25 and later. +and compiles on stable Rust 1.27 and later. _smoltcp_ achieves [~Gbps of throughput](#examplesbenchmarkrs) when tested against the Linux TCP stack in loopback mode. diff --git a/examples/utils.rs b/examples/utils.rs index a816125..31d18c2 100644 --- a/examples/utils.rs +++ b/examples/utils.rs @@ -106,7 +106,7 @@ pub fn add_middleware_options(opts: &mut Options, _free: &mut Vec<&str>) { } pub fn parse_middleware_options(matches: &mut Matches, device: D, loopback: bool) - -> FaultInjector>>> + -> FaultInjector>>> where D: for<'a> Device<'a> { let drop_chance = matches.opt_str("drop-chance").map(|s| u8::from_str(&s).unwrap()) @@ -122,7 +122,7 @@ pub fn parse_middleware_options(matches: &mut Matches, device: D, loopback: b let shaping_interval = matches.opt_str("shaping-interval").map(|s| u64::from_str(&s).unwrap()) .unwrap_or(0); - let pcap_writer: Box; + let pcap_writer: Box; if let Some(pcap_filename) = matches.opt_str("pcap") { pcap_writer = Box::new(File::create(pcap_filename).expect("cannot open file")) } else { @@ -131,7 +131,7 @@ pub fn parse_middleware_options(matches: &mut Matches, device: D, loopback: b let seed = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().subsec_nanos(); - let device = PcapWriter::new(device, Rc::new(RefCell::new(pcap_writer)) as Rc, + let device = PcapWriter::new(device, Rc::new(RefCell::new(pcap_writer)) as Rc, if loopback { PcapMode::TxOnly } else { PcapMode::Both }, PcapLinkType::Ethernet); let device = EthernetTracer::new(device, |_timestamp, _printer| { diff --git a/src/phy/pcap_writer.rs b/src/phy/pcap_writer.rs index 49f32f5..53d7559 100644 --- a/src/phy/pcap_writer.rs +++ b/src/phy/pcap_writer.rs @@ -85,7 +85,7 @@ pub trait PcapSink { } } -impl> PcapSink for T { +impl> PcapSink for T { fn write(&self, data: &[u8]) { self.as_ref().write(data) } diff --git a/src/wire/arp.rs b/src/wire/arp.rs index b6fc5ae..7e66d1d 100644 --- a/src/wire/arp.rs +++ b/src/wire/arp.rs @@ -359,7 +359,7 @@ impl fmt::Display for Repr { use super::pretty_print::{PrettyPrint, PrettyIndent}; impl> PrettyPrint for Packet { - fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, + fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter, indent: &mut PrettyIndent) -> fmt::Result { match Packet::new_checked(buffer) { Err(err) => write!(f, "{}({})", indent, err), diff --git a/src/wire/ethernet.rs b/src/wire/ethernet.rs index 073aa68..6847b62 100644 --- a/src/wire/ethernet.rs +++ b/src/wire/ethernet.rs @@ -212,7 +212,7 @@ impl> fmt::Display for Frame { use super::pretty_print::{PrettyPrint, PrettyIndent}; impl> PrettyPrint for Frame { - fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, + fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter, indent: &mut PrettyIndent) -> fmt::Result { let frame = match Frame::new_checked(buffer) { Err(err) => return write!(f, "{}({})", indent, err), diff --git a/src/wire/icmpv4.rs b/src/wire/icmpv4.rs index 1a2cb6c..a066bfd 100644 --- a/src/wire/icmpv4.rs +++ b/src/wire/icmpv4.rs @@ -534,7 +534,7 @@ impl<'a> fmt::Display for Repr<'a> { use super::pretty_print::{PrettyPrint, PrettyIndent}; impl> PrettyPrint for Packet { - fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, + fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter, indent: &mut PrettyIndent) -> fmt::Result { let packet = match Packet::new_checked(buffer) { Err(err) => return write!(f, "{}({})", indent, err), diff --git a/src/wire/igmp.rs b/src/wire/igmp.rs index 53c5d20..49440a0 100644 --- a/src/wire/igmp.rs +++ b/src/wire/igmp.rs @@ -358,7 +358,7 @@ impl<'a> fmt::Display for Repr { use super::pretty_print::{PrettyIndent, PrettyPrint}; impl> PrettyPrint for Packet { - fn pretty_print(buffer: &AsRef<[u8]>, + fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter, indent: &mut PrettyIndent) -> fmt::Result { diff --git a/src/wire/ipv4.rs b/src/wire/ipv4.rs index 95a8958..c2360cb 100644 --- a/src/wire/ipv4.rs +++ b/src/wire/ipv4.rs @@ -665,7 +665,7 @@ impl fmt::Display for Repr { use super::pretty_print::{PrettyPrint, PrettyIndent}; impl> PrettyPrint for Packet { - fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, + fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter, indent: &mut PrettyIndent) -> fmt::Result { use wire::ip::checksum::format_checksum; diff --git a/src/wire/ipv6.rs b/src/wire/ipv6.rs index eed0de6..065b239 100644 --- a/src/wire/ipv6.rs +++ b/src/wire/ipv6.rs @@ -652,7 +652,7 @@ use super::pretty_print::{PrettyPrint, PrettyIndent}; // TODO: This is very similar to the implementation for IPv4. Make // a way to have less copy and pasted code here. impl> PrettyPrint for Packet { - fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, + fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter, indent: &mut PrettyIndent) -> fmt::Result { let (ip_repr, payload) = match Packet::new_checked(buffer) { Err(err) => return write!(f, "{}({})", indent, err), diff --git a/src/wire/ndiscoption.rs b/src/wire/ndiscoption.rs index 5de0773..5180331 100644 --- a/src/wire/ndiscoption.rs +++ b/src/wire/ndiscoption.rs @@ -590,7 +590,7 @@ impl<'a> fmt::Display for Repr<'a> { use super::pretty_print::{PrettyPrint, PrettyIndent}; impl> PrettyPrint for NdiscOption { - fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, + fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter, indent: &mut PrettyIndent) -> fmt::Result { match NdiscOption::new_checked(buffer) { Err(err) => return write!(f, "{}({})", indent, err), diff --git a/src/wire/pretty_print.rs b/src/wire/pretty_print.rs index 630f1f5..94bf7c6 100644 --- a/src/wire/pretty_print.rs +++ b/src/wire/pretty_print.rs @@ -71,20 +71,20 @@ pub trait PrettyPrint { /// /// `pretty_print` accepts a buffer and not a packet wrapper because the packet might /// be truncated, and so it might not be possible to create the packet wrapper. - fn pretty_print(buffer: &AsRef<[u8]>, fmt: &mut fmt::Formatter, + fn pretty_print(buffer: &dyn AsRef<[u8]>, fmt: &mut fmt::Formatter, indent: &mut PrettyIndent) -> fmt::Result; } /// Wrapper for using a `PrettyPrint` where a `Display` is expected. pub struct PrettyPrinter<'a, T: PrettyPrint> { prefix: &'static str, - buffer: &'a AsRef<[u8]>, + buffer: &'a dyn AsRef<[u8]>, phantom: PhantomData } impl<'a, T: PrettyPrint> PrettyPrinter<'a, T> { /// Format the listing with the recorded parameters when Display::fmt is called. - pub fn new(prefix: &'static str, buffer: &'a AsRef<[u8]>) -> PrettyPrinter<'a, T> { + pub fn new(prefix: &'static str, buffer: &'a dyn AsRef<[u8]>) -> PrettyPrinter<'a, T> { PrettyPrinter { prefix: prefix, buffer: buffer, diff --git a/src/wire/tcp.rs b/src/wire/tcp.rs index c239729..1626d31 100644 --- a/src/wire/tcp.rs +++ b/src/wire/tcp.rs @@ -1012,7 +1012,7 @@ impl<'a> fmt::Display for Repr<'a> { use super::pretty_print::{PrettyPrint, PrettyIndent}; impl> PrettyPrint for Packet { - fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, + fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter, indent: &mut PrettyIndent) -> fmt::Result { match Packet::new_checked(buffer) { Err(err) => write!(f, "{}({})", indent, err), diff --git a/src/wire/udp.rs b/src/wire/udp.rs index 94bbe98..b309f63 100644 --- a/src/wire/udp.rs +++ b/src/wire/udp.rs @@ -275,7 +275,7 @@ impl<'a> fmt::Display for Repr<'a> { use super::pretty_print::{PrettyPrint, PrettyIndent}; impl> PrettyPrint for Packet { - fn pretty_print(buffer: &AsRef<[u8]>, f: &mut fmt::Formatter, + fn pretty_print(buffer: &dyn AsRef<[u8]>, f: &mut fmt::Formatter, indent: &mut PrettyIndent) -> fmt::Result { match Packet::new_checked(buffer) { Err(err) => write!(f, "{}({})", indent, err),