Skip to content

Commit 94c609c

Browse files
committed
Transition libserialize to 2018 edition
1 parent b139669 commit 94c609c

File tree

7 files changed

+42
-41
lines changed

7 files changed

+42
-41
lines changed

src/libserialize/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
authors = ["The Rust Project Developers"]
33
name = "serialize"
44
version = "0.0.0"
5+
edition = "2018"
56

67
[lib]
78
name = "serialize"

src/libserialize/collection_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use std::hash::{Hash, BuildHasher};
44

5-
use {Decodable, Encodable, Decoder, Encoder};
5+
use crate::{Decodable, Encodable, Decoder, Encoder};
66
use std::collections::{LinkedList, VecDeque, BTreeMap, BTreeSet, HashMap, HashSet};
77
use std::rc::Rc;
88
use std::sync::Arc;

src/libserialize/hex.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub enum FromHexError {
6060
}
6161

6262
impl fmt::Display for FromHexError {
63-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
63+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
6464
match *self {
6565
InvalidHexCharacter(ch, idx) =>
6666
write!(f, "Invalid character '{}' at position {}", ch, idx),
@@ -146,7 +146,7 @@ impl FromHex for str {
146146
mod tests {
147147
extern crate test;
148148
use self::test::Bencher;
149-
use hex::{FromHex, ToHex};
149+
use crate::hex::{FromHex, ToHex};
150150

151151
#[test]
152152
pub fn test_to_hex() {

src/libserialize/json.rs

+30-30
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ use std::string;
201201
use std::{char, f64, fmt, str};
202202
use std;
203203

204-
use Encodable;
204+
use crate::Encodable;
205205

206206
/// Represents a json value
207207
#[derive(Clone, PartialEq, PartialOrd, Debug)]
@@ -221,8 +221,8 @@ pub type Object = BTreeMap<string::String, Json>;
221221

222222
pub struct PrettyJson<'a> { inner: &'a Json }
223223

224-
pub struct AsJson<'a, T: 'a> { inner: &'a T }
225-
pub struct AsPrettyJson<'a, T: 'a> { inner: &'a T, indent: Option<usize> }
224+
pub struct AsJson<'a, T> { inner: &'a T }
225+
pub struct AsPrettyJson<'a, T> { inner: &'a T, indent: Option<usize> }
226226

227227
/// The errors that can arise while parsing a JSON stream.
228228
#[derive(Clone, Copy, PartialEq, Debug)]
@@ -295,18 +295,18 @@ pub fn error_str(error: ErrorCode) -> &'static str {
295295
}
296296

297297
/// Shortcut function to decode a JSON `&str` into an object
298-
pub fn decode<T: ::Decodable>(s: &str) -> DecodeResult<T> {
298+
pub fn decode<T: crate::Decodable>(s: &str) -> DecodeResult<T> {
299299
let json = match from_str(s) {
300300
Ok(x) => x,
301301
Err(e) => return Err(ParseError(e))
302302
};
303303

304304
let mut decoder = Decoder::new(json);
305-
::Decodable::decode(&mut decoder)
305+
crate::Decodable::decode(&mut decoder)
306306
}
307307

308308
/// Shortcut function to encode a `T` into a JSON `String`
309-
pub fn encode<T: ::Encodable>(object: &T) -> Result<string::String, EncoderError> {
309+
pub fn encode<T: crate::Encodable>(object: &T) -> Result<string::String, EncoderError> {
310310
let mut s = String::new();
311311
{
312312
let mut encoder = Encoder::new(&mut s);
@@ -316,7 +316,7 @@ pub fn encode<T: ::Encodable>(object: &T) -> Result<string::String, EncoderError
316316
}
317317

318318
impl fmt::Display for ErrorCode {
319-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
319+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
320320
error_str(*self).fmt(f)
321321
}
322322
}
@@ -326,14 +326,14 @@ fn io_error_to_error(io: io::Error) -> ParserError {
326326
}
327327

328328
impl fmt::Display for ParserError {
329-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
329+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
330330
// FIXME this should be a nicer error
331331
fmt::Debug::fmt(self, f)
332332
}
333333
}
334334

335335
impl fmt::Display for DecoderError {
336-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
336+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
337337
// FIXME this should be a nicer error
338338
fmt::Debug::fmt(self, f)
339339
}
@@ -344,7 +344,7 @@ impl std::error::Error for DecoderError {
344344
}
345345

346346
impl fmt::Display for EncoderError {
347-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
347+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
348348
// FIXME this should be a nicer error
349349
fmt::Debug::fmt(self, f)
350350
}
@@ -477,7 +477,7 @@ macro_rules! emit_enquoted_if_mapkey {
477477
})
478478
}
479479

480-
impl<'a> ::Encoder for Encoder<'a> {
480+
impl<'a> crate::Encoder for Encoder<'a> {
481481
type Error = EncoderError;
482482

483483
fn emit_unit(&mut self) -> EncodeResult {
@@ -727,7 +727,7 @@ impl<'a> PrettyEncoder<'a> {
727727
}
728728
}
729729

730-
impl<'a> ::Encoder for PrettyEncoder<'a> {
730+
impl<'a> crate::Encoder for PrettyEncoder<'a> {
731731
type Error = EncoderError;
732732

733733
fn emit_unit(&mut self) -> EncodeResult {
@@ -997,7 +997,7 @@ impl<'a> ::Encoder for PrettyEncoder<'a> {
997997
}
998998

999999
impl Encodable for Json {
1000-
fn encode<E: ::Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
1000+
fn encode<E: crate::Encoder>(&self, e: &mut E) -> Result<(), E::Error> {
10011001
match *self {
10021002
Json::I64(v) => v.encode(e),
10031003
Json::U64(v) => v.encode(e),
@@ -1013,20 +1013,20 @@ impl Encodable for Json {
10131013

10141014
/// Create an `AsJson` wrapper which can be used to print a value as JSON
10151015
/// on-the-fly via `write!`
1016-
pub fn as_json<T>(t: &T) -> AsJson<T> {
1016+
pub fn as_json<T>(t: &T) -> AsJson<'_, T> {
10171017
AsJson { inner: t }
10181018
}
10191019

10201020
/// Create an `AsPrettyJson` wrapper which can be used to print a value as JSON
10211021
/// on-the-fly via `write!`
1022-
pub fn as_pretty_json<T>(t: &T) -> AsPrettyJson<T> {
1022+
pub fn as_pretty_json<T>(t: &T) -> AsPrettyJson<'_, T> {
10231023
AsPrettyJson { inner: t, indent: None }
10241024
}
10251025

10261026
impl Json {
10271027
/// Borrow this json object as a pretty object to generate a pretty
10281028
/// representation for it via `Display`.
1029-
pub fn pretty(&self) -> PrettyJson {
1029+
pub fn pretty(&self) -> PrettyJson<'_> {
10301030
PrettyJson { inner: self }
10311031
}
10321032

@@ -1300,7 +1300,7 @@ impl Stack {
13001300
/// Provides access to the StackElement at a given index.
13011301
/// lower indices are at the bottom of the stack while higher indices are
13021302
/// at the top.
1303-
pub fn get(&self, idx: usize) -> StackElement {
1303+
pub fn get(&self, idx: usize) -> StackElement<'_> {
13041304
match self.stack[idx] {
13051305
InternalIndex(i) => StackElement::Index(i),
13061306
InternalKey(start, size) => {
@@ -1311,8 +1311,8 @@ impl Stack {
13111311
}
13121312
}
13131313

1314-
/// Compares this stack with an array of StackElements.
1315-
pub fn is_equal_to(&self, rhs: &[StackElement]) -> bool {
1314+
/// Compares this stack with an array of StackElement<'_>s.
1315+
pub fn is_equal_to(&self, rhs: &[StackElement<'_>]) -> bool {
13161316
if self.stack.len() != rhs.len() { return false; }
13171317
for (i, r) in rhs.iter().enumerate() {
13181318
if self.get(i) != *r { return false; }
@@ -1322,7 +1322,7 @@ impl Stack {
13221322

13231323
/// Returns true if the bottom-most elements of this stack are the same as
13241324
/// the ones passed as parameter.
1325-
pub fn starts_with(&self, rhs: &[StackElement]) -> bool {
1325+
pub fn starts_with(&self, rhs: &[StackElement<'_>]) -> bool {
13261326
if self.stack.len() < rhs.len() { return false; }
13271327
for (i, r) in rhs.iter().enumerate() {
13281328
if self.get(i) != *r { return false; }
@@ -1332,7 +1332,7 @@ impl Stack {
13321332

13331333
/// Returns true if the top-most elements of this stack are the same as
13341334
/// the ones passed as parameter.
1335-
pub fn ends_with(&self, rhs: &[StackElement]) -> bool {
1335+
pub fn ends_with(&self, rhs: &[StackElement<'_>]) -> bool {
13361336
if self.stack.len() < rhs.len() { return false; }
13371337
let offset = self.stack.len() - rhs.len();
13381338
for (i, r) in rhs.iter().enumerate() {
@@ -1342,7 +1342,7 @@ impl Stack {
13421342
}
13431343

13441344
/// Returns the top-most element (if any).
1345-
pub fn top(&self) -> Option<StackElement> {
1345+
pub fn top(&self) -> Option<StackElement<'_>> {
13461346
match self.stack.last() {
13471347
None => None,
13481348
Some(&InternalIndex(i)) => Some(StackElement::Index(i)),
@@ -2115,7 +2115,7 @@ macro_rules! read_primitive {
21152115
}
21162116
}
21172117

2118-
impl ::Decoder for Decoder {
2118+
impl crate::Decoder for Decoder {
21192119
type Error = DecoderError;
21202120

21212121
fn read_nil(&mut self) -> DecodeResult<()> {
@@ -2172,7 +2172,7 @@ impl ::Decoder for Decoder {
21722172
Err(ExpectedError("single character string".to_owned(), s.to_string()))
21732173
}
21742174

2175-
fn read_str(&mut self) -> DecodeResult<Cow<str>> {
2175+
fn read_str(&mut self) -> DecodeResult<Cow<'_, str>> {
21762176
expect!(self.pop(), String).map(Cow::Owned)
21772177
}
21782178

@@ -2518,7 +2518,7 @@ impl<'a, 'b> fmt::Write for FormatShim<'a, 'b> {
25182518

25192519
impl fmt::Display for Json {
25202520
/// Encodes a json value into a string
2521-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2521+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25222522
let mut shim = FormatShim { inner: f };
25232523
let mut encoder = Encoder::new(&mut shim);
25242524
match self.encode(&mut encoder) {
@@ -2530,7 +2530,7 @@ impl fmt::Display for Json {
25302530

25312531
impl<'a> fmt::Display for PrettyJson<'a> {
25322532
/// Encodes a json value into a string
2533-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2533+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25342534
let mut shim = FormatShim { inner: f };
25352535
let mut encoder = PrettyEncoder::new(&mut shim);
25362536
match self.inner.encode(&mut encoder) {
@@ -2542,7 +2542,7 @@ impl<'a> fmt::Display for PrettyJson<'a> {
25422542

25432543
impl<'a, T: Encodable> fmt::Display for AsJson<'a, T> {
25442544
/// Encodes a json value into a string
2545-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2545+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25462546
let mut shim = FormatShim { inner: f };
25472547
let mut encoder = Encoder::new(&mut shim);
25482548
match self.inner.encode(&mut encoder) {
@@ -2562,7 +2562,7 @@ impl<'a, T> AsPrettyJson<'a, T> {
25622562

25632563
impl<'a, T: Encodable> fmt::Display for AsPrettyJson<'a, T> {
25642564
/// Encodes a json value into a string
2565-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
2565+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
25662566
let mut shim = FormatShim { inner: f };
25672567
let mut encoder = PrettyEncoder::new(&mut shim);
25682568
if let Some(n) = self.indent {
@@ -2587,7 +2587,7 @@ mod tests {
25872587
extern crate test;
25882588
use self::Animal::*;
25892589
use self::test::Bencher;
2590-
use {Encodable, Decodable};
2590+
use crate::{Encodable, Decodable};
25912591
use super::Json::*;
25922592
use super::ErrorCode::*;
25932593
use super::ParserError::*;
@@ -3515,7 +3515,7 @@ mod tests {
35153515
#[test]
35163516
fn test_hashmap_with_enum_key() {
35173517
use std::collections::HashMap;
3518-
use json;
3518+
use crate::json;
35193519
#[derive(RustcEncodable, Eq, Hash, PartialEq, RustcDecodable, Debug)]
35203520
enum Enum {
35213521
Foo,

src/libserialize/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ Core encoding and decoding interfaces.
1010
html_playground_url = "https://play.rust-lang.org/",
1111
test(attr(allow(unused_variables), deny(warnings))))]
1212

13+
#![deny(rust_2018_idioms)]
14+
1315
#![feature(box_syntax)]
1416
#![feature(core_intrinsics)]
1517
#![feature(specialization)]
@@ -22,8 +24,6 @@ pub use self::serialize::{Decoder, Encoder, Decodable, Encodable};
2224
pub use self::serialize::{SpecializationError, SpecializedEncoder, SpecializedDecoder};
2325
pub use self::serialize::{UseSpecializedEncodable, UseSpecializedDecodable};
2426

25-
extern crate smallvec;
26-
2727
mod serialize;
2828
mod collection_impls;
2929

@@ -34,5 +34,5 @@ pub mod opaque;
3434
pub mod leb128;
3535

3636
mod rustc_serialize {
37-
pub use serialize::*;
37+
pub use crate::serialize::*;
3838
}

src/libserialize/opaque.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use leb128::{self, read_signed_leb128, write_signed_leb128};
1+
use crate::leb128::{self, read_signed_leb128, write_signed_leb128};
22
use std::borrow::Cow;
3-
use serialize;
3+
use crate::serialize;
44

55
// -----------------------------------------------------------------------------
66
// Encoder
@@ -312,7 +312,7 @@ impl<'a> serialize::Decoder for Decoder<'a> {
312312
}
313313

314314
#[inline]
315-
fn read_str(&mut self) -> Result<Cow<str>, Self::Error> {
315+
fn read_str(&mut self) -> Result<Cow<'_, str>, Self::Error> {
316316
let len = self.read_usize()?;
317317
let s = ::std::str::from_utf8(&self.data[self.position..self.position + len]).unwrap();
318318
self.position += len;
@@ -328,7 +328,7 @@ impl<'a> serialize::Decoder for Decoder<'a> {
328328

329329
#[cfg(test)]
330330
mod tests {
331-
use serialize::{Encodable, Decodable};
331+
use crate::serialize::{Encodable, Decodable};
332332
use std::fmt::Debug;
333333
use super::{Encoder, Decoder};
334334

src/libserialize/serialize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ pub trait Decoder {
175175
fn read_f64(&mut self) -> Result<f64, Self::Error>;
176176
fn read_f32(&mut self) -> Result<f32, Self::Error>;
177177
fn read_char(&mut self) -> Result<char, Self::Error>;
178-
fn read_str(&mut self) -> Result<Cow<str>, Self::Error>;
178+
fn read_str(&mut self) -> Result<Cow<'_, str>, Self::Error>;
179179

180180
// Compound types:
181181
fn read_enum<T, F>(&mut self, _name: &str, f: F) -> Result<T, Self::Error>

0 commit comments

Comments
 (0)