Browse Source

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.
whitequark 5 years ago
parent
commit
83dba8ea31

+ 1 - 1
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.

+ 3 - 3
examples/utils.rs

@@ -106,7 +106,7 @@ pub fn add_middleware_options(opts: &mut Options, _free: &mut Vec<&str>) {
 }
 
 pub fn parse_middleware_options<D>(matches: &mut Matches, device: D, loopback: bool)
-        -> FaultInjector<EthernetTracer<PcapWriter<D, Rc<PcapSink>>>>
+        -> FaultInjector<EthernetTracer<PcapWriter<D, Rc<dyn PcapSink>>>>
     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<D>(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<io::Write>;
+    let pcap_writer: Box<dyn io::Write>;
     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<D>(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<PcapSink>,
+    let device = PcapWriter::new(device, Rc::new(RefCell::new(pcap_writer)) as Rc<dyn PcapSink>,
                                  if loopback { PcapMode::TxOnly } else { PcapMode::Both },
                                  PcapLinkType::Ethernet);
     let device = EthernetTracer::new(device, |_timestamp, _printer| {

+ 1 - 1
src/phy/pcap_writer.rs

@@ -85,7 +85,7 @@ pub trait PcapSink {
     }
 }
 
-impl<T: AsRef<PcapSink>> PcapSink for T {
+impl<T: AsRef<dyn PcapSink>> PcapSink for T {
     fn write(&self, data: &[u8]) {
         self.as_ref().write(data)
     }

+ 1 - 1
src/wire/arp.rs

@@ -359,7 +359,7 @@ impl fmt::Display for Repr {
 use super::pretty_print::{PrettyPrint, PrettyIndent};
 
 impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
-    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),

+ 1 - 1
src/wire/ethernet.rs

@@ -212,7 +212,7 @@ impl<T: AsRef<[u8]>> fmt::Display for Frame<T> {
 use super::pretty_print::{PrettyPrint, PrettyIndent};
 
 impl<T: AsRef<[u8]>> PrettyPrint for Frame<T> {
-    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),

+ 1 - 1
src/wire/icmpv4.rs

@@ -534,7 +534,7 @@ impl<'a> fmt::Display for Repr<'a> {
 use super::pretty_print::{PrettyPrint, PrettyIndent};
 
 impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
-    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),

+ 1 - 1
src/wire/igmp.rs

@@ -358,7 +358,7 @@ impl<'a> fmt::Display for Repr {
 use super::pretty_print::{PrettyIndent, PrettyPrint};
 
 impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
-    fn pretty_print(buffer: &AsRef<[u8]>,
+    fn pretty_print(buffer: &dyn AsRef<[u8]>,
                     f: &mut fmt::Formatter,
                     indent: &mut PrettyIndent)
                     -> fmt::Result {

+ 1 - 1
src/wire/ipv4.rs

@@ -665,7 +665,7 @@ impl fmt::Display for Repr {
 use super::pretty_print::{PrettyPrint, PrettyIndent};
 
 impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
-    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;
 

+ 1 - 1
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<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
-    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),

+ 1 - 1
src/wire/ndiscoption.rs

@@ -590,7 +590,7 @@ impl<'a> fmt::Display for Repr<'a> {
 use super::pretty_print::{PrettyPrint, PrettyIndent};
 
 impl<T: AsRef<[u8]>> PrettyPrint for NdiscOption<T> {
-    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),

+ 3 - 3
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<T>
 }
 
 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,

+ 1 - 1
src/wire/tcp.rs

@@ -1012,7 +1012,7 @@ impl<'a> fmt::Display for Repr<'a> {
 use super::pretty_print::{PrettyPrint, PrettyIndent};
 
 impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
-    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),

+ 1 - 1
src/wire/udp.rs

@@ -275,7 +275,7 @@ impl<'a> fmt::Display for Repr<'a> {
 use super::pretty_print::{PrettyPrint, PrettyIndent};
 
 impl<T: AsRef<[u8]>> PrettyPrint for Packet<T> {
-    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),