Upgrade rust/crates/protobuf to 2.18.1

Test: make
Change-Id: I5b915568dd8c388d36820424b8c7986dfd33af3b
diff --git a/src/buf_read_iter.rs b/src/buf_read_iter.rs
index 149a2ea..8b4dbf5 100644
--- a/src/buf_read_iter.rs
+++ b/src/buf_read_iter.rs
@@ -29,8 +29,8 @@
 
 /// Hold all possible combinations of input source
 enum InputSource<'a> {
-    BufRead(&'a mut BufRead),
-    Read(BufReader<&'a mut Read>),
+    BufRead(&'a mut dyn BufRead),
+    Read(BufReader<&'a mut dyn Read>),
     Slice(&'a [u8]),
     #[cfg(feature = "bytes")]
     Bytes(&'a Bytes),
diff --git a/src/error.rs b/src/error.rs
index 9e5a7e1..3f06909 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -112,7 +112,7 @@
         }
     }
 
-    fn cause(&self) -> Option<&Error> {
+    fn cause(&self) -> Option<&dyn Error> {
         match self {
             &ProtobufError::IoError(ref e) => Some(e),
             &ProtobufError::Utf8(ref e) => Some(e),
diff --git a/src/lib.rs b/src/lib.rs
index 8233e07..f8d1089 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,8 +2,6 @@
 
 #![deny(missing_docs)]
 #![deny(broken_intra_doc_links)]
-// Because we need compat with Rust 1.26
-#![allow(bare_trait_objects)]
 
 #[cfg(feature = "bytes")]
 extern crate bytes;
diff --git a/src/message.rs b/src/message.rs
index 1b1f39f..2f1a1e7 100644
--- a/src/message.rs
+++ b/src/message.rs
@@ -97,7 +97,7 @@
     }
 
     /// Write the message to the writer.
-    fn write_to_writer(&self, w: &mut Write) -> ProtobufResult<()> {
+    fn write_to_writer(&self, w: &mut dyn Write) -> ProtobufResult<()> {
         w.with_coded_output_stream(|os| self.write_to(os))
     }
 
@@ -126,7 +126,7 @@
 
     /// Write the message to the writer, prepend the message with message length
     /// encoded as varint.
-    fn write_length_delimited_to_writer(&self, w: &mut Write) -> ProtobufResult<()> {
+    fn write_length_delimited_to_writer(&self, w: &mut dyn Write) -> ProtobufResult<()> {
         w.with_coded_output_stream(|os| self.write_length_delimited_to(os))
     }
 
@@ -147,15 +147,15 @@
     }
 
     /// View self as `Any`.
-    fn as_any(&self) -> &Any;
+    fn as_any(&self) -> &dyn Any;
 
     /// View self as mutable `Any`.
-    fn as_any_mut(&mut self) -> &mut Any {
+    fn as_any_mut(&mut self) -> &mut dyn Any {
         panic!()
     }
 
     /// Convert boxed self to boxed `Any`.
-    fn into_any(self: Box<Self>) -> Box<Any> {
+    fn into_any(self: Box<Self>) -> Box<dyn Any> {
         panic!()
     }
 
@@ -209,7 +209,7 @@
         Self: Sized;
 }
 
-pub fn message_down_cast<'a, M: Message + 'a>(m: &'a Message) -> &'a M {
+pub fn message_down_cast<'a, M: Message + 'a>(m: &'a dyn Message) -> &'a M {
     m.as_any().downcast_ref::<M>().unwrap()
 }
 
@@ -223,7 +223,7 @@
 
 /// Parse message from reader.
 /// Parse stops on EOF or when error encountered.
-pub fn parse_from_reader<M: Message>(reader: &mut Read) -> ProtobufResult<M> {
+pub fn parse_from_reader<M: Message>(reader: &mut dyn Read) -> ProtobufResult<M> {
     reader.with_coded_input_stream(|is| parse_from::<M>(is))
 }
 
@@ -254,7 +254,7 @@
 ///
 /// This function is deprecated and will be removed in the next major release.
 #[deprecated]
-pub fn parse_length_delimited_from_reader<M: Message>(r: &mut Read) -> ProtobufResult<M> {
+pub fn parse_length_delimited_from_reader<M: Message>(r: &mut dyn Read) -> ProtobufResult<M> {
     // TODO: wrong: we may read length first, and then read exact number of bytes needed
     r.with_coded_input_stream(|is| is.read_message::<M>())
 }
diff --git a/src/reflect/map.rs b/src/reflect/map.rs
index 9f03123..c6aff60 100644
--- a/src/reflect/map.rs
+++ b/src/reflect/map.rs
@@ -26,7 +26,7 @@
 }
 
 trait ReflectMapIterTrait<'a> {
-    fn next(&mut self) -> Option<(&'a ProtobufValue, &'a ProtobufValue)>;
+    fn next(&mut self) -> Option<(&'a dyn ProtobufValue, &'a dyn ProtobufValue)>;
 }
 
 struct ReflectMapIterImpl<'a, K: Eq + Hash + 'static, V: 'static> {
@@ -36,29 +36,29 @@
 impl<'a, K: ProtobufValue + Eq + Hash + 'static, V: ProtobufValue + 'static> ReflectMapIterTrait<'a>
     for ReflectMapIterImpl<'a, K, V>
 {
-    fn next(&mut self) -> Option<(&'a ProtobufValue, &'a ProtobufValue)> {
+    fn next(&mut self) -> Option<(&'a dyn ProtobufValue, &'a dyn ProtobufValue)> {
         match self.iter.next() {
-            Some((k, v)) => Some((k as &ProtobufValue, v as &ProtobufValue)),
+            Some((k, v)) => Some((k as &dyn ProtobufValue, v as &dyn ProtobufValue)),
             None => None,
         }
     }
 }
 
 pub struct ReflectMapIter<'a> {
-    imp: Box<ReflectMapIterTrait<'a> + 'a>,
+    imp: Box<dyn ReflectMapIterTrait<'a> + 'a>,
 }
 
 impl<'a> Iterator for ReflectMapIter<'a> {
-    type Item = (&'a ProtobufValue, &'a ProtobufValue);
+    type Item = (&'a dyn ProtobufValue, &'a dyn ProtobufValue);
 
-    fn next(&mut self) -> Option<(&'a ProtobufValue, &'a ProtobufValue)> {
+    fn next(&mut self) -> Option<(&'a dyn ProtobufValue, &'a dyn ProtobufValue)> {
         self.imp.next()
     }
 }
 
-impl<'a> IntoIterator for &'a ReflectMap {
+impl<'a> IntoIterator for &'a dyn ReflectMap {
     type IntoIter = ReflectMapIter<'a>;
-    type Item = (&'a ProtobufValue, &'a ProtobufValue);
+    type Item = (&'a dyn ProtobufValue, &'a dyn ProtobufValue);
 
     fn into_iter(self) -> Self::IntoIter {
         self.reflect_iter()
diff --git a/src/reflect/optional.rs b/src/reflect/optional.rs
index ba6cbaf..f81f973 100644
--- a/src/reflect/optional.rs
+++ b/src/reflect/optional.rs
@@ -5,17 +5,17 @@
 use crate::singular::*;
 
 pub trait ReflectOptional: 'static {
-    fn to_option(&self) -> Option<&ProtobufValue>;
+    fn to_option(&self) -> Option<&dyn ProtobufValue>;
 
-    fn set_value(&mut self, value: &ProtobufValue);
+    fn set_value(&mut self, value: &dyn ProtobufValue);
 }
 
 impl<V: ProtobufValue + Clone + 'static> ReflectOptional for Option<V> {
-    fn to_option(&self) -> Option<&ProtobufValue> {
-        self.as_ref().map(|v| v as &ProtobufValue)
+    fn to_option(&self) -> Option<&dyn ProtobufValue> {
+        self.as_ref().map(|v| v as &dyn ProtobufValue)
     }
 
-    fn set_value(&mut self, value: &ProtobufValue) {
+    fn set_value(&mut self, value: &dyn ProtobufValue) {
         match value.as_any().downcast_ref::<V>() {
             Some(v) => mem::replace(self, Some(v.clone())),
             None => panic!(),
@@ -24,11 +24,11 @@
 }
 
 impl<V: ProtobufValue + Clone + 'static> ReflectOptional for SingularField<V> {
-    fn to_option(&self) -> Option<&ProtobufValue> {
-        self.as_ref().map(|v| v as &ProtobufValue)
+    fn to_option(&self) -> Option<&dyn ProtobufValue> {
+        self.as_ref().map(|v| v as &dyn ProtobufValue)
     }
 
-    fn set_value(&mut self, value: &ProtobufValue) {
+    fn set_value(&mut self, value: &dyn ProtobufValue) {
         match value.as_any().downcast_ref::<V>() {
             Some(v) => mem::replace(self, SingularField::some(v.clone())),
             None => panic!(),
@@ -37,11 +37,11 @@
 }
 
 impl<V: ProtobufValue + Clone + 'static> ReflectOptional for SingularPtrField<V> {
-    fn to_option(&self) -> Option<&ProtobufValue> {
-        self.as_ref().map(|v| v as &ProtobufValue)
+    fn to_option(&self) -> Option<&dyn ProtobufValue> {
+        self.as_ref().map(|v| v as &dyn ProtobufValue)
     }
 
-    fn set_value(&mut self, value: &ProtobufValue) {
+    fn set_value(&mut self, value: &dyn ProtobufValue) {
         match value.as_any().downcast_ref::<V>() {
             Some(v) => mem::replace(self, SingularPtrField::some(v.clone())),
             None => panic!(),
diff --git a/src/reflect/repeated.rs b/src/reflect/repeated.rs
index 43e265d..be232f4 100644
--- a/src/reflect/repeated.rs
+++ b/src/reflect/repeated.rs
@@ -8,7 +8,7 @@
 pub trait ReflectRepeated: 'static {
     fn reflect_iter(&self) -> ReflectRepeatedIter;
     fn len(&self) -> usize;
-    fn get(&self, index: usize) -> &ProtobufValue;
+    fn get(&self, index: usize) -> &dyn ProtobufValue;
 }
 
 impl<V: ProtobufValue + 'static> ReflectRepeated for Vec<V> {
@@ -22,7 +22,7 @@
         Vec::len(self)
     }
 
-    fn get(&self, index: usize) -> &ProtobufValue {
+    fn get(&self, index: usize) -> &dyn ProtobufValue {
         &self[index]
     }
 }
@@ -39,7 +39,7 @@
         <[_]>::len(self)
     }
 
-    fn get(&self, index: usize) -> &ProtobufValue {
+    fn get(&self, index: usize) -> &dyn ProtobufValue {
         &self[index]
     }
 }
@@ -55,13 +55,13 @@
         RepeatedField::len(self)
     }
 
-    fn get(&self, index: usize) -> &ProtobufValue {
+    fn get(&self, index: usize) -> &dyn ProtobufValue {
         &self[index]
     }
 }
 
 trait ReflectRepeatedIterTrait<'a> {
-    fn next(&mut self) -> Option<&'a ProtobufValue>;
+    fn next(&mut self) -> Option<&'a dyn ProtobufValue>;
 }
 
 struct ReflectRepeatedIterImplSlice<'a, V: ProtobufValue + 'static> {
@@ -71,26 +71,26 @@
 impl<'a, V: ProtobufValue + 'static> ReflectRepeatedIterTrait<'a>
     for ReflectRepeatedIterImplSlice<'a, V>
 {
-    fn next(&mut self) -> Option<&'a ProtobufValue> {
-        self.iter.next().map(|v| v as &ProtobufValue)
+    fn next(&mut self) -> Option<&'a dyn ProtobufValue> {
+        self.iter.next().map(|v| v as &dyn ProtobufValue)
     }
 }
 
 pub struct ReflectRepeatedIter<'a> {
-    imp: Box<ReflectRepeatedIterTrait<'a> + 'a>,
+    imp: Box<dyn ReflectRepeatedIterTrait<'a> + 'a>,
 }
 
 impl<'a> Iterator for ReflectRepeatedIter<'a> {
-    type Item = &'a ProtobufValue;
+    type Item = &'a dyn ProtobufValue;
 
     fn next(&mut self) -> Option<Self::Item> {
         self.imp.next()
     }
 }
 
-impl<'a> IntoIterator for &'a ReflectRepeated {
+impl<'a> IntoIterator for &'a dyn ReflectRepeated {
     type IntoIter = ReflectRepeatedIter<'a>;
-    type Item = &'a ProtobufValue;
+    type Item = &'a dyn ProtobufValue;
 
     fn into_iter(self) -> Self::IntoIter {
         self.reflect_iter()
@@ -110,7 +110,7 @@
 }
 
 pub enum ReflectRepeatedRef<'a> {
-    Generic(&'a ReflectRepeated),
+    Generic(&'a dyn ReflectRepeated),
     U32(&'a [u32]),
     U64(&'a [u64]),
     I32(&'a [i32]),
@@ -120,8 +120,8 @@
     Bool(&'a [bool]),
     String(&'a [String]),
     Bytes(&'a [Vec<u8>]),
-    Enum(Box<ReflectRepeatedEnum<'a> + 'a>),
-    Message(Box<ReflectRepeatedMessage<'a> + 'a>),
+    Enum(Box<dyn ReflectRepeatedEnum<'a> + 'a>),
+    Message(Box<dyn ReflectRepeatedMessage<'a> + 'a>),
 }
 
 impl<'a> ReflectRepeatedRef<'a> {
diff --git a/src/reflect/value.rs b/src/reflect/value.rs
index 2671805..16d5266 100644
--- a/src/reflect/value.rs
+++ b/src/reflect/value.rs
@@ -14,7 +14,7 @@
     fn as_ref(&self) -> ReflectValueRef;
 
     /// Convert to `Any`
-    fn as_any(&self) -> &Any {
+    fn as_any(&self) -> &dyn Any {
         unimplemented!()
     }
 
diff --git a/src/stream.rs b/src/stream.rs
index d503fd7..dc45953 100644
--- a/src/stream.rs
+++ b/src/stream.rs
@@ -48,7 +48,7 @@
     /// Tag occupies 3 bits
     pub const TAG_TYPE_BITS: u32 = 3;
     /// Tag mask
-    pub const TAG_TYPE_MASK: u32 = (1u32 << TAG_TYPE_BITS as usize) - 1;
+    pub const TAG_TYPE_MASK: u32 = (1u32 << TAG_TYPE_BITS) - 1;
     /// Max possible field number
     pub const FIELD_NUMBER_MAX: u32 = 0x1fffffff;
 
@@ -158,14 +158,14 @@
     /// Wrap a `Read`.
     ///
     /// Note resulting `CodedInputStream` is buffered even if `Read` is not.
-    pub fn new(read: &'a mut Read) -> CodedInputStream<'a> {
+    pub fn new(read: &'a mut dyn Read) -> CodedInputStream<'a> {
         CodedInputStream::from_buf_read_iter(BufReadIter::from_read(read))
     }
 
     /// Create from `BufRead`.
     ///
     /// `CodedInputStream` will utilize `BufRead` buffer.
-    pub fn from_buffered_reader(buf_read: &'a mut BufRead) -> CodedInputStream<'a> {
+    pub fn from_buffered_reader(buf_read: &'a mut dyn BufRead) -> CodedInputStream<'a> {
         CodedInputStream::from_buf_read_iter(BufReadIter::from_buf_read(buf_read))
     }
 
@@ -854,7 +854,7 @@
         F: FnOnce(&mut CodedOutputStream) -> ProtobufResult<T>;
 }
 
-impl<'a> WithCodedOutputStream for &'a mut (Write + 'a) {
+impl<'a> WithCodedOutputStream for &'a mut (dyn Write + 'a) {
     fn with_coded_output_stream<T, F>(self, cb: F) -> ProtobufResult<T>
     where
         F: FnOnce(&mut CodedOutputStream) -> ProtobufResult<T>,
@@ -896,7 +896,7 @@
         F: FnOnce(&mut CodedInputStream) -> ProtobufResult<T>;
 }
 
-impl<'a> WithCodedInputStream for &'a mut (Read + 'a) {
+impl<'a> WithCodedInputStream for &'a mut (dyn Read + 'a) {
     fn with_coded_input_stream<T, F>(self, cb: F) -> ProtobufResult<T>
     where
         F: FnOnce(&mut CodedInputStream) -> ProtobufResult<T>,
@@ -908,7 +908,7 @@
     }
 }
 
-impl<'a> WithCodedInputStream for &'a mut (BufRead + 'a) {
+impl<'a> WithCodedInputStream for &'a mut (dyn BufRead + 'a) {
     fn with_coded_input_stream<T, F>(self, cb: F) -> ProtobufResult<T>
     where
         F: FnOnce(&mut CodedInputStream) -> ProtobufResult<T>,
@@ -946,7 +946,7 @@
 }
 
 enum OutputTarget<'a> {
-    Write(&'a mut Write, Vec<u8>),
+    Write(&'a mut dyn Write, Vec<u8>),
     Vec(&'a mut Vec<u8>),
     Bytes,
 }
@@ -964,7 +964,7 @@
     /// Construct from given `Write`.
     ///
     /// `CodedOutputStream` is buffered even if `Write` is not
-    pub fn new(writer: &'a mut Write) -> CodedOutputStream<'a> {
+    pub fn new(writer: &'a mut dyn Write) -> CodedOutputStream<'a> {
         let buffer_len = OUTPUT_STREAM_BUFFER_SIZE;
 
         let mut buffer_storage = Vec::with_capacity(buffer_len);
diff --git a/src/text_format.rs b/src/text_format.rs
index 59bd07a..3cbe13d 100644
--- a/src/text_format.rs
+++ b/src/text_format.rs
@@ -219,7 +219,7 @@
     print_end_field(buf, pretty);
 }
 
-fn print_to_internal(m: &Message, buf: &mut String, pretty: bool, indent: usize) {
+fn print_to_internal(m: &dyn Message, buf: &mut String, pretty: bool, indent: usize) {
     let d = m.descriptor();
     let mut first = true;
     for f in d.fields() {
@@ -266,23 +266,23 @@
 }
 
 /// Text-format
-pub fn print_to(m: &Message, buf: &mut String) {
+pub fn print_to(m: &dyn Message, buf: &mut String) {
     print_to_internal(m, buf, false, 0)
 }
 
-fn print_to_string_internal(m: &Message, pretty: bool) -> String {
+fn print_to_string_internal(m: &dyn Message, pretty: bool) -> String {
     let mut r = String::new();
     print_to_internal(m, &mut r, pretty, 0);
     r.to_string()
 }
 
 /// Text-format
-pub fn print_to_string(m: &Message) -> String {
+pub fn print_to_string(m: &dyn Message) -> String {
     print_to_string_internal(m, false)
 }
 
 /// Text-format to `fmt::Formatter`.
-pub fn fmt(m: &Message, f: &mut fmt::Formatter) -> fmt::Result {
+pub fn fmt(m: &dyn Message, f: &mut fmt::Formatter) -> fmt::Result {
     let pretty = f.alternate();
     f.write_str(&print_to_string_internal(m, pretty))
 }