THRIFT-4960 bare trait (dyn) warnings
Client: Rust
Patch: Danny Browning

This closes #1851
diff --git a/lib/rs/src/autogen.rs b/lib/rs/src/autogen.rs
index 54d4080..6806a08 100644
--- a/lib/rs/src/autogen.rs
+++ b/lib/rs/src/autogen.rs
@@ -29,10 +29,10 @@
 pub trait TThriftClient {
     /// Returns the input protocol used to read serialized Thrift messages
     /// from the Thrift server.
-    fn i_prot_mut(&mut self) -> &mut TInputProtocol;
+    fn i_prot_mut(&mut self) -> &mut dyn TInputProtocol;
     /// Returns the output protocol used to write serialized Thrift messages
     /// to the Thrift server.
-    fn o_prot_mut(&mut self) -> &mut TOutputProtocol;
+    fn o_prot_mut(&mut self) -> &mut dyn TOutputProtocol;
     /// Returns the sequence number of the last message written to the Thrift
     /// server. Returns `0` if no messages have been written. Sequence
     /// numbers should *never* be negative, and this method returns an `i32`
diff --git a/lib/rs/src/errors.rs b/lib/rs/src/errors.rs
index 13be1ee..68cdc9c 100644
--- a/lib/rs/src/errors.rs
+++ b/lib/rs/src/errors.rs
@@ -188,7 +188,7 @@
     /// functions are automatically returned as an `ApplicationError`.
     Application(ApplicationError),
     /// IDL-defined exception structs.
-    User(Box<error::Error + Sync + Send>),
+    User(Box<dyn error::Error + Sync + Send>),
 }
 
 impl Error {
@@ -196,7 +196,7 @@
     ///
     /// Application code **should never** call this method directly.
     pub fn read_application_error_from_in_protocol(
-        i: &mut TInputProtocol,
+        i: &mut dyn TInputProtocol,
     ) -> ::Result<ApplicationError> {
         let mut message = "general remote error".to_owned();
         let mut kind = ApplicationErrorKind::Unknown;
@@ -247,7 +247,7 @@
     /// Application code **should never** call this method directly.
     pub fn write_application_error_to_out_protocol(
         e: &ApplicationError,
-        o: &mut TOutputProtocol,
+        o: &mut dyn TOutputProtocol,
     ) -> ::Result<()> {
         o.write_struct_begin(&TStructIdentifier {
             name: "TApplicationException".to_owned(),
diff --git a/lib/rs/src/lib.rs b/lib/rs/src/lib.rs
index a36ec99..cdd60f0 100644
--- a/lib/rs/src/lib.rs
+++ b/lib/rs/src/lib.rs
@@ -47,6 +47,7 @@
 
 #![crate_type = "lib"]
 #![doc(test(attr(allow(unused_variables), deny(warnings))))]
+#![deny(bare_trait_objects)]
 
 extern crate byteorder;
 extern crate ordered_float;
diff --git a/lib/rs/src/protocol/binary.rs b/lib/rs/src/protocol/binary.rs
index 0920fc4..2069cf9 100644
--- a/lib/rs/src/protocol/binary.rs
+++ b/lib/rs/src/protocol/binary.rs
@@ -249,7 +249,7 @@
 }
 
 impl TInputProtocolFactory for TBinaryInputProtocolFactory {
-    fn create(&self, transport: Box<TReadTransport + Send>) -> Box<TInputProtocol + Send> {
+    fn create(&self, transport: Box<dyn TReadTransport + Send>) -> Box<dyn TInputProtocol + Send> {
         Box::new(TBinaryInputProtocol::new(transport, true))
     }
 }
@@ -453,7 +453,7 @@
 }
 
 impl TOutputProtocolFactory for TBinaryOutputProtocolFactory {
-    fn create(&self, transport: Box<TWriteTransport + Send>) -> Box<TOutputProtocol + Send> {
+    fn create(&self, transport: Box<dyn TWriteTransport + Send>) -> Box<dyn TOutputProtocol + Send> {
         Box::new(TBinaryOutputProtocol::new(transport, true))
     }
 }
diff --git a/lib/rs/src/protocol/compact.rs b/lib/rs/src/protocol/compact.rs
index 334e820..1750bc4 100644
--- a/lib/rs/src/protocol/compact.rs
+++ b/lib/rs/src/protocol/compact.rs
@@ -322,7 +322,7 @@
 }
 
 impl TInputProtocolFactory for TCompactInputProtocolFactory {
-    fn create(&self, transport: Box<TReadTransport + Send>) -> Box<TInputProtocol + Send> {
+    fn create(&self, transport: Box<dyn TReadTransport + Send>) -> Box<dyn TInputProtocol + Send> {
         Box::new(TCompactInputProtocol::new(transport))
     }
 }
@@ -593,7 +593,7 @@
 }
 
 impl TOutputProtocolFactory for TCompactOutputProtocolFactory {
-    fn create(&self, transport: Box<TWriteTransport + Send>) -> Box<TOutputProtocol + Send> {
+    fn create(&self, transport: Box<dyn TWriteTransport + Send>) -> Box<dyn TOutputProtocol + Send> {
         Box::new(TCompactOutputProtocol::new(transport))
     }
 }
diff --git a/lib/rs/src/protocol/mod.rs b/lib/rs/src/protocol/mod.rs
index 1ab1658..2d8513f 100644
--- a/lib/rs/src/protocol/mod.rs
+++ b/lib/rs/src/protocol/mod.rs
@@ -546,14 +546,14 @@
 /// ```
 pub trait TInputProtocolFactory {
     // Create a `TInputProtocol` that reads bytes from `transport`.
-    fn create(&self, transport: Box<TReadTransport + Send>) -> Box<TInputProtocol + Send>;
+    fn create(&self, transport: Box<dyn TReadTransport + Send>) -> Box<dyn TInputProtocol + Send>;
 }
 
 impl<T> TInputProtocolFactory for Box<T>
 where
     T: TInputProtocolFactory + ?Sized,
 {
-    fn create(&self, transport: Box<TReadTransport + Send>) -> Box<TInputProtocol + Send> {
+    fn create(&self, transport: Box<dyn TReadTransport + Send>) -> Box<dyn TInputProtocol + Send> {
         (**self).create(transport)
     }
 }
@@ -577,14 +577,14 @@
 /// ```
 pub trait TOutputProtocolFactory {
     /// Create a `TOutputProtocol` that writes bytes to `transport`.
-    fn create(&self, transport: Box<TWriteTransport + Send>) -> Box<TOutputProtocol + Send>;
+    fn create(&self, transport: Box<dyn TWriteTransport + Send>) -> Box<dyn TOutputProtocol + Send>;
 }
 
 impl<T> TOutputProtocolFactory for Box<T>
 where
     T: TOutputProtocolFactory + ?Sized,
 {
-    fn create(&self, transport: Box<TWriteTransport + Send>) -> Box<TOutputProtocol + Send> {
+    fn create(&self, transport: Box<dyn TWriteTransport + Send>) -> Box<dyn TOutputProtocol + Send> {
         (**self).create(transport)
     }
 }
@@ -926,29 +926,29 @@
 
     #[test]
     fn must_create_usable_input_protocol_from_concrete_input_protocol() {
-        let r: Box<TReadTransport> = Box::new(Cursor::new([0, 1, 2]));
+        let r: Box<dyn TReadTransport> = Box::new(Cursor::new([0, 1, 2]));
         let mut t = TCompactInputProtocol::new(r);
         takes_input_protocol(&mut t)
     }
 
     #[test]
     fn must_create_usable_input_protocol_from_boxed_input() {
-        let r: Box<TReadTransport> = Box::new(Cursor::new([0, 1, 2]));
-        let mut t: Box<TInputProtocol> = Box::new(TCompactInputProtocol::new(r));
+        let r: Box<dyn TReadTransport> = Box::new(Cursor::new([0, 1, 2]));
+        let mut t: Box<dyn TInputProtocol> = Box::new(TCompactInputProtocol::new(r));
         takes_input_protocol(&mut t)
     }
 
     #[test]
     fn must_create_usable_output_protocol_from_concrete_output_protocol() {
-        let w: Box<TWriteTransport> = Box::new(vec![0u8; 10]);
+        let w: Box<dyn TWriteTransport> = Box::new(vec![0u8; 10]);
         let mut t = TCompactOutputProtocol::new(w);
         takes_output_protocol(&mut t)
     }
 
     #[test]
     fn must_create_usable_output_protocol_from_boxed_output() {
-        let w: Box<TWriteTransport> = Box::new(vec![0u8; 10]);
-        let mut t: Box<TOutputProtocol> = Box::new(TCompactOutputProtocol::new(w));
+        let w: Box<dyn TWriteTransport> = Box::new(vec![0u8; 10]);
+        let mut t: Box<dyn TOutputProtocol> = Box::new(TCompactOutputProtocol::new(w));
         takes_output_protocol(&mut t)
     }
 
diff --git a/lib/rs/src/protocol/stored.rs b/lib/rs/src/protocol/stored.rs
index 4fe465f..faa5128 100644
--- a/lib/rs/src/protocol/stored.rs
+++ b/lib/rs/src/protocol/stored.rs
@@ -79,7 +79,7 @@
 /// ```
 // FIXME: implement Debug
 pub struct TStoredInputProtocol<'a> {
-    inner: &'a mut TInputProtocol,
+    inner: &'a mut dyn TInputProtocol,
     message_ident: Option<TMessageIdentifier>,
 }
 
@@ -90,7 +90,7 @@
     /// with service name stripped - that will be passed to
     /// `wrapped.read_message_begin(...)`.
     pub fn new(
-        wrapped: &mut TInputProtocol,
+        wrapped: &mut dyn TInputProtocol,
         message_ident: TMessageIdentifier,
     ) -> TStoredInputProtocol {
         TStoredInputProtocol {
diff --git a/lib/rs/src/server/mod.rs b/lib/rs/src/server/mod.rs
index 3d42891..b719d1b 100644
--- a/lib/rs/src/server/mod.rs
+++ b/lib/rs/src/server/mod.rs
@@ -91,7 +91,7 @@
     /// the response to `o`.
     ///
     /// Returns `()` if the handler was executed; `Err` otherwise.
-    fn process(&self, i: &mut TInputProtocol, o: &mut TOutputProtocol) -> ::Result<()>;
+    fn process(&self, i: &mut dyn TInputProtocol, o: &mut dyn TOutputProtocol) -> ::Result<()>;
 }
 
 /// Convenience function used in generated `TProcessor` implementations to
@@ -99,7 +99,7 @@
 pub fn handle_process_result(
     msg_ident: &TMessageIdentifier,
     res: ::Result<()>,
-    o_prot: &mut TOutputProtocol,
+    o_prot: &mut dyn TOutputProtocol,
 ) -> ::Result<()> {
     if let Err(e) = res {
         let e = match e {
diff --git a/lib/rs/src/server/multiplexed.rs b/lib/rs/src/server/multiplexed.rs
index e433794..3f9bc78 100644
--- a/lib/rs/src/server/multiplexed.rs
+++ b/lib/rs/src/server/multiplexed.rs
@@ -27,7 +27,7 @@
 
 const MISSING_SEPARATOR_AND_NO_DEFAULT: &'static str =
     "missing service separator and no default processor set";
-type ThreadSafeProcessor = Box<TProcessor + Send + Sync>;
+type ThreadSafeProcessor = Box<dyn TProcessor + Send + Sync>;
 
 /// A `TProcessor` that can demux service calls to multiple underlying
 /// Thrift services.
@@ -74,7 +74,7 @@
     pub fn register<S: Into<String>>(
         &mut self,
         service_name: S,
-        processor: Box<TProcessor + Send + Sync>,
+        processor: Box<dyn TProcessor + Send + Sync>,
         as_default: bool,
     ) -> ::Result<()> {
         let mut stored = self.stored.lock().unwrap();
@@ -103,8 +103,8 @@
     fn process_message(
         &self,
         msg_ident: &TMessageIdentifier,
-        i_prot: &mut TInputProtocol,
-        o_prot: &mut TOutputProtocol,
+        i_prot: &mut dyn TInputProtocol,
+        o_prot: &mut dyn TOutputProtocol,
     ) -> ::Result<()> {
         let (svc_name, svc_call) = split_ident_name(&msg_ident.name);
         debug!("routing svc_name {:?} svc_call {}", &svc_name, &svc_call);
@@ -134,7 +134,7 @@
 }
 
 impl TProcessor for TMultiplexedProcessor {
-    fn process(&self, i_prot: &mut TInputProtocol, o_prot: &mut TOutputProtocol) -> ::Result<()> {
+    fn process(&self, i_prot: &mut dyn TInputProtocol, o_prot: &mut dyn TOutputProtocol) -> ::Result<()> {
         let msg_ident = i_prot.read_message_begin()?;
 
         debug!("process incoming msg id:{:?}", &msg_ident);
@@ -259,7 +259,7 @@
     }
 
     impl TProcessor for Service {
-        fn process(&self, _: &mut TInputProtocol, _: &mut TOutputProtocol) -> ::Result<()> {
+        fn process(&self, _: &mut dyn TInputProtocol, _: &mut dyn TOutputProtocol) -> ::Result<()> {
             let res = self
                 .invoked
                 .compare_and_swap(false, true, Ordering::Relaxed);
diff --git a/lib/rs/src/server/threaded.rs b/lib/rs/src/server/threaded.rs
index e15a25a..8f8c082 100644
--- a/lib/rs/src/server/threaded.rs
+++ b/lib/rs/src/server/threaded.rs
@@ -194,7 +194,7 @@
     fn new_protocols_for_connection(
         &mut self,
         stream: TcpStream,
-    ) -> ::Result<(Box<TInputProtocol + Send>, Box<TOutputProtocol + Send>)> {
+    ) -> ::Result<(Box<dyn TInputProtocol + Send>, Box<dyn TOutputProtocol + Send>)> {
         // create the shared tcp stream
         let channel = TTcpChannel::with_stream(stream);
 
@@ -216,8 +216,8 @@
 
 fn handle_incoming_connection<PRC>(
     processor: Arc<PRC>,
-    i_prot: Box<TInputProtocol>,
-    o_prot: Box<TOutputProtocol>,
+    i_prot: Box<dyn TInputProtocol>,
+    o_prot: Box<dyn TOutputProtocol>,
 ) where
     PRC: TProcessor,
 {
diff --git a/lib/rs/src/transport/buffered.rs b/lib/rs/src/transport/buffered.rs
index 87cfeff..b33eb4f 100644
--- a/lib/rs/src/transport/buffered.rs
+++ b/lib/rs/src/transport/buffered.rs
@@ -139,7 +139,7 @@
 
 impl TReadTransportFactory for TBufferedReadTransportFactory {
     /// Create a `TBufferedReadTransport`.
-    fn create(&self, channel: Box<Read + Send>) -> Box<TReadTransport + Send> {
+    fn create(&self, channel: Box<dyn Read + Send>) -> Box<dyn TReadTransport + Send> {
         Box::new(TBufferedReadTransport::new(channel))
     }
 }
@@ -254,7 +254,7 @@
 
 impl TWriteTransportFactory for TBufferedWriteTransportFactory {
     /// Create a `TBufferedWriteTransport`.
-    fn create(&self, channel: Box<Write + Send>) -> Box<TWriteTransport + Send> {
+    fn create(&self, channel: Box<dyn Write + Send>) -> Box<dyn TWriteTransport + Send> {
         Box::new(TBufferedWriteTransport::new(channel))
     }
 }
diff --git a/lib/rs/src/transport/framed.rs b/lib/rs/src/transport/framed.rs
index a009307..98ad1bb 100644
--- a/lib/rs/src/transport/framed.rs
+++ b/lib/rs/src/transport/framed.rs
@@ -121,7 +121,7 @@
 
 impl TReadTransportFactory for TFramedReadTransportFactory {
     /// Create a `TFramedReadTransport`.
-    fn create(&self, channel: Box<Read + Send>) -> Box<TReadTransport + Send> {
+    fn create(&self, channel: Box<dyn Read + Send>) -> Box<dyn TReadTransport + Send> {
         Box::new(TFramedReadTransport::new(channel))
     }
 }
@@ -231,7 +231,7 @@
 
 impl TWriteTransportFactory for TFramedWriteTransportFactory {
     /// Create a `TFramedWriteTransport`.
-    fn create(&self, channel: Box<Write + Send>) -> Box<TWriteTransport + Send> {
+    fn create(&self, channel: Box<dyn Write + Send>) -> Box<dyn TWriteTransport + Send> {
         Box::new(TFramedWriteTransport::new(channel))
     }
 }
diff --git a/lib/rs/src/transport/mod.rs b/lib/rs/src/transport/mod.rs
index a623350..32c0799 100644
--- a/lib/rs/src/transport/mod.rs
+++ b/lib/rs/src/transport/mod.rs
@@ -64,7 +64,7 @@
 /// accepted client connections.
 pub trait TReadTransportFactory {
     /// Create a `TTransport` that wraps a channel over which bytes are to be read.
-    fn create(&self, channel: Box<Read + Send>) -> Box<TReadTransport + Send>;
+    fn create(&self, channel: Box<dyn Read + Send>) -> Box<dyn TReadTransport + Send>;
 }
 
 /// Identifies a transport used by `TOutputProtocol` to send bytes.
@@ -74,7 +74,7 @@
 /// accepted client connections.
 pub trait TWriteTransportFactory {
     /// Create a `TTransport` that wraps a channel over which bytes are to be sent.
-    fn create(&self, channel: Box<Write + Send>) -> Box<TWriteTransport + Send>;
+    fn create(&self, channel: Box<dyn Write + Send>) -> Box<dyn TWriteTransport + Send>;
 }
 
 impl<T> TReadTransport for T where T: Read {}
@@ -87,7 +87,7 @@
 where
     T: TReadTransportFactory + ?Sized,
 {
-    fn create(&self, channel: Box<Read + Send>) -> Box<TReadTransport + Send> {
+    fn create(&self, channel: Box<dyn Read + Send>) -> Box<dyn TReadTransport + Send> {
         (**self).create(channel)
     }
 }
@@ -96,7 +96,7 @@
 where
     T: TWriteTransportFactory + ?Sized,
 {
-    fn create(&self, channel: Box<Write + Send>) -> Box<TWriteTransport + Send> {
+    fn create(&self, channel: Box<dyn Write + Send>) -> Box<dyn TWriteTransport + Send> {
         (**self).create(channel)
     }
 }
@@ -231,7 +231,7 @@
 
     #[test]
     fn must_create_usable_read_channel_from_boxed_read() {
-        let r: Box<Read> = Box::new(Cursor::new([0, 1, 2]));
+        let r: Box<dyn Read> = Box::new(Cursor::new([0, 1, 2]));
         let _ = TBufferedReadTransport::new(r);
     }
 
@@ -243,7 +243,7 @@
 
     #[test]
     fn must_create_usable_write_channel_from_boxed_write() {
-        let w: Box<Write> = Box::new(vec![0u8; 10]);
+        let w: Box<dyn Write> = Box::new(vec![0u8; 10]);
         let _ = TBufferedWriteTransport::new(w);
     }
 
@@ -257,7 +257,7 @@
     #[test]
     fn must_create_usable_read_transport_from_boxed_read() {
         let r = Cursor::new([0, 1, 2]);
-        let mut t: Box<TReadTransport> = Box::new(TBufferedReadTransport::new(r));
+        let mut t: Box<dyn TReadTransport> = Box::new(TBufferedReadTransport::new(r));
         takes_read_transport(&mut t)
     }
 
@@ -271,7 +271,7 @@
     #[test]
     fn must_create_usable_write_transport_from_boxed_write() {
         let w = vec![0u8; 10];
-        let mut t: Box<TWriteTransport> = Box::new(TBufferedWriteTransport::new(w));
+        let mut t: Box<dyn TWriteTransport> = Box::new(TBufferedWriteTransport::new(w));
         takes_write_transport(&mut t)
     }