Skip to content

Commit 7bccc8c

Browse files
committed
Clippy
1 parent 114b78f commit 7bccc8c

39 files changed

+904
-872
lines changed

rmp-serde/src/bytes.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
/// Hacky serializer that only allows `u8`
1+
//! Hacky serializer that only allows `u8`
22
3-
use std::fmt;
43
use serde::ser::Impossible;
54
use serde::Serialize;
5+
use std::fmt;
66

77
pub(crate) struct OnlyBytes;
88
pub(crate) struct Nope;

rmp-serde/src/config.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ pub struct StructMapConfig<C>(C);
124124
impl<C> StructMapConfig<C> {
125125
/// Creates a `StructMapConfig` inheriting unchanged configuration options from the given configuration.
126126
#[inline]
127-
pub fn new(inner: C) -> Self {
128-
StructMapConfig(inner)
127+
pub const fn new(inner: C) -> Self {
128+
Self(inner)
129129
}
130130
}
131131

@@ -156,8 +156,8 @@ pub struct StructTupleConfig<C>(C);
156156
impl<C> StructTupleConfig<C> {
157157
/// Creates a `StructTupleConfig` inheriting unchanged configuration options from the given configuration.
158158
#[inline]
159-
pub fn new(inner: C) -> Self {
160-
StructTupleConfig(inner)
159+
pub const fn new(inner: C) -> Self {
160+
Self(inner)
161161
}
162162
}
163163

@@ -188,7 +188,7 @@ pub struct HumanReadableConfig<C>(C);
188188
impl<C> HumanReadableConfig<C> {
189189
/// Creates a `HumanReadableConfig` inheriting unchanged configuration options from the given configuration.
190190
#[inline]
191-
pub fn new(inner: C) -> Self {
191+
pub const fn new(inner: C) -> Self {
192192
Self(inner)
193193
}
194194
}
@@ -220,7 +220,7 @@ pub struct BinaryConfig<C>(C);
220220
impl<C> BinaryConfig<C> {
221221
/// Creates a `BinaryConfig` inheriting unchanged configuration options from the given configuration.
222222
#[inline(always)]
223-
pub fn new(inner: C) -> Self {
223+
pub const fn new(inner: C) -> Self {
224224
Self(inner)
225225
}
226226
}

rmp-serde/src/decode.rs

+58-60
Original file line numberDiff line numberDiff line change
@@ -68,104 +68,104 @@ impl error::Error for Error {
6868
#[cold]
6969
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
7070
match *self {
71-
Error::TypeMismatch(..) => None,
72-
Error::InvalidMarkerRead(ref err) => Some(err),
73-
Error::InvalidDataRead(ref err) => Some(err),
74-
Error::LengthMismatch(..) => None,
75-
Error::OutOfRange => None,
76-
Error::Uncategorized(..) => None,
77-
Error::Syntax(..) => None,
78-
Error::Utf8Error(ref err) => Some(err),
79-
Error::DepthLimitExceeded => None,
71+
Self::TypeMismatch(..) => None,
72+
Self::InvalidMarkerRead(ref err) => Some(err),
73+
Self::InvalidDataRead(ref err) => Some(err),
74+
Self::LengthMismatch(..) => None,
75+
Self::OutOfRange => None,
76+
Self::Uncategorized(..) => None,
77+
Self::Syntax(..) => None,
78+
Self::Utf8Error(ref err) => Some(err),
79+
Self::DepthLimitExceeded => None,
8080
}
8181
}
8282
}
8383

8484
impl de::Error for Error {
8585
#[cold]
8686
fn custom<T: Display>(msg: T) -> Self {
87-
Error::Syntax(msg.to_string())
87+
Self::Syntax(msg.to_string())
8888
}
8989
}
9090

9191
impl Display for Error {
9292
#[cold]
9393
fn fmt(&self, fmt: &mut Formatter<'_>) -> Result<(), fmt::Error> {
9494
match *self {
95-
Error::InvalidMarkerRead(ref err) => write!(fmt, "IO error while reading marker: {err}"),
96-
Error::InvalidDataRead(ref err) => write!(fmt, "IO error while reading data: {err}"),
97-
Error::TypeMismatch(ref actual_marker) => {
95+
Self::InvalidMarkerRead(ref err) => write!(fmt, "IO error while reading marker: {err}"),
96+
Self::InvalidDataRead(ref err) => write!(fmt, "IO error while reading data: {err}"),
97+
Self::TypeMismatch(ref actual_marker) => {
9898
write!(fmt, "wrong msgpack marker {actual_marker:?}")
9999
}
100-
Error::OutOfRange => fmt.write_str("numeric cast found out of range"),
101-
Error::LengthMismatch(expected_length) => write!(
100+
Self::OutOfRange => fmt.write_str("numeric cast found out of range"),
101+
Self::LengthMismatch(expected_length) => write!(
102102
fmt,
103103
"array had incorrect length, expected {expected_length}"
104104
),
105-
Error::Uncategorized(ref msg) => write!(fmt, "uncategorized error: {msg}"),
106-
Error::Syntax(ref msg) => fmt.write_str(msg),
107-
Error::Utf8Error(ref err) => write!(fmt, "string found to be invalid utf8: {err}"),
108-
Error::DepthLimitExceeded => fmt.write_str("depth limit exceeded"),
105+
Self::Uncategorized(ref msg) => write!(fmt, "uncategorized error: {msg}"),
106+
Self::Syntax(ref msg) => fmt.write_str(msg),
107+
Self::Utf8Error(ref err) => write!(fmt, "string found to be invalid utf8: {err}"),
108+
Self::DepthLimitExceeded => fmt.write_str("depth limit exceeded"),
109109
}
110110
}
111111
}
112112

113113
impl From<MarkerReadError> for Error {
114114
#[cold]
115-
fn from(err: MarkerReadError) -> Error {
115+
fn from(err: MarkerReadError) -> Self {
116116
match err {
117-
MarkerReadError(err) => Error::InvalidMarkerRead(err),
117+
MarkerReadError(err) => Self::InvalidMarkerRead(err),
118118
}
119119
}
120120
}
121121

122122
impl From<Utf8Error> for Error {
123123
#[cold]
124-
fn from(err: Utf8Error) -> Error {
125-
Error::Utf8Error(err)
124+
fn from(err: Utf8Error) -> Self {
125+
Self::Utf8Error(err)
126126
}
127127
}
128128

129129
impl From<ValueReadError> for Error {
130130
#[cold]
131-
fn from(err: ValueReadError) -> Error {
131+
fn from(err: ValueReadError) -> Self {
132132
match err {
133-
ValueReadError::TypeMismatch(marker) => Error::TypeMismatch(marker),
134-
ValueReadError::InvalidMarkerRead(err) => Error::InvalidMarkerRead(err),
135-
ValueReadError::InvalidDataRead(err) => Error::InvalidDataRead(err),
133+
ValueReadError::TypeMismatch(marker) => Self::TypeMismatch(marker),
134+
ValueReadError::InvalidMarkerRead(err) => Self::InvalidMarkerRead(err),
135+
ValueReadError::InvalidDataRead(err) => Self::InvalidDataRead(err),
136136
}
137137
}
138138
}
139139

140140
impl From<NumValueReadError> for Error {
141141
#[cold]
142-
fn from(err: NumValueReadError) -> Error {
142+
fn from(err: NumValueReadError) -> Self {
143143
match err {
144-
NumValueReadError::TypeMismatch(marker) => Error::TypeMismatch(marker),
145-
NumValueReadError::InvalidMarkerRead(err) => Error::InvalidMarkerRead(err),
146-
NumValueReadError::InvalidDataRead(err) => Error::InvalidDataRead(err),
147-
NumValueReadError::OutOfRange => Error::OutOfRange,
144+
NumValueReadError::TypeMismatch(marker) => Self::TypeMismatch(marker),
145+
NumValueReadError::InvalidMarkerRead(err) => Self::InvalidMarkerRead(err),
146+
NumValueReadError::InvalidDataRead(err) => Self::InvalidDataRead(err),
147+
NumValueReadError::OutOfRange => Self::OutOfRange,
148148
}
149149
}
150150
}
151151

152-
impl<'a> From<DecodeStringError<'a>> for Error {
152+
impl From<DecodeStringError<'_>> for Error {
153153
#[cold]
154-
fn from(err: DecodeStringError<'_>) -> Error {
154+
fn from(err: DecodeStringError<'_>) -> Self {
155155
match err {
156-
DecodeStringError::InvalidMarkerRead(err) => Error::InvalidMarkerRead(err),
157-
DecodeStringError::InvalidDataRead(err) => Error::InvalidDataRead(err),
158-
DecodeStringError::TypeMismatch(marker) => Error::TypeMismatch(marker),
159-
DecodeStringError::BufferSizeTooSmall(..) => Error::Uncategorized("BufferSizeTooSmall".to_string()),
160-
DecodeStringError::InvalidUtf8(..) => Error::Uncategorized("InvalidUtf8".to_string()),
156+
DecodeStringError::InvalidMarkerRead(err) => Self::InvalidMarkerRead(err),
157+
DecodeStringError::InvalidDataRead(err) => Self::InvalidDataRead(err),
158+
DecodeStringError::TypeMismatch(marker) => Self::TypeMismatch(marker),
159+
DecodeStringError::BufferSizeTooSmall(..) => Self::Uncategorized("BufferSizeTooSmall".to_string()),
160+
DecodeStringError::InvalidUtf8(..) => Self::Uncategorized("InvalidUtf8".to_string()),
161161
}
162162
}
163163
}
164164

165165
impl From<TryFromIntError> for Error {
166166
#[cold]
167167
fn from(_: TryFromIntError) -> Self {
168-
Error::OutOfRange
168+
Self::OutOfRange
169169
}
170170
}
171171

@@ -246,7 +246,7 @@ impl<R: Read, C: SerializerConfig> Deserializer<R, C> {
246246
/// versions of `rmp-serde`.
247247
#[inline]
248248
pub fn with_human_readable(self) -> Deserializer<R, HumanReadableConfig<C>> {
249-
let Deserializer { rd, _config: _, is_human_readable: _, marker, depth } = self;
249+
let Self { rd, _config: _, is_human_readable: _, marker, depth } = self;
250250
Deserializer {
251251
rd,
252252
is_human_readable: true,
@@ -263,7 +263,7 @@ impl<R: Read, C: SerializerConfig> Deserializer<R, C> {
263263
/// representation.
264264
#[inline]
265265
pub fn with_binary(self) -> Deserializer<R, BinaryConfig<C>> {
266-
let Deserializer { rd, _config: _, is_human_readable: _, marker, depth } = self;
266+
let Self { rd, _config: _, is_human_readable: _, marker, depth } = self;
267267
Deserializer {
268268
rd,
269269
is_human_readable: false,
@@ -331,9 +331,7 @@ fn read_i128_marker<'de, R: ReadSlice<'de>>(marker: Marker, rd: &mut R) -> Resul
331331
let len = read_u8(&mut *rd)?;
332332
read_128_buf(rd, len)?
333333
},
334-
Marker::FixArray(len) => {
335-
read_128_buf(rd, len)?
336-
},
334+
Marker::FixArray(len) => read_128_buf(rd, len)?,
337335
marker => return Err(Error::TypeMismatch(marker)),
338336
})
339337
}
@@ -428,7 +426,7 @@ struct ExtDeserializer<'a, R, C> {
428426
}
429427

430428
impl<'de, 'a, R: ReadSlice<'de> + 'a, C: SerializerConfig> ExtDeserializer<'a, R, C> {
431-
fn new(d: &'a mut Deserializer<R, C>, len: u32) -> Self {
429+
const fn new(d: &'a mut Deserializer<R, C>, len: u32) -> Self {
432430
ExtDeserializer {
433431
rd: &mut d.rd,
434432
_config: d._config,
@@ -551,7 +549,7 @@ impl<'de, R: ReadSlice<'de>, C: SerializerConfig> Deserializer<R, C> {
551549
Marker::FixStr(len) => Ok(len.into()),
552550
Marker::Str8 => read_u8(&mut self.rd).map(u32::from),
553551
Marker::Str16 => read_u16(&mut self.rd).map(u32::from),
554-
Marker::Str32 => read_u32(&mut self.rd).map(u32::from),
552+
Marker::Str32 => read_u32(&mut self.rd),
555553
_ => return Err(Error::TypeMismatch(Marker::Reserved)),
556554
}?;
557555
read_str_data(&mut self.rd, len, visitor)
@@ -598,7 +596,7 @@ impl<'de, R: ReadSlice<'de>, C: SerializerConfig> Deserializer<R, C> {
598596
let len = match marker {
599597
Marker::Bin8 => read_u8(&mut self.rd).map(u32::from),
600598
Marker::Bin16 => read_u16(&mut self.rd).map(u32::from),
601-
Marker::Bin32 => read_u32(&mut self.rd).map(u32::from),
599+
Marker::Bin32 => read_u32(&mut self.rd),
602600
_ => return Err(Error::TypeMismatch(Marker::Reserved)),
603601
}?;
604602
match read_bin_data(&mut self.rd, len)? {
@@ -625,7 +623,7 @@ impl<'de, R: ReadSlice<'de>, C: SerializerConfig> Deserializer<R, C> {
625623
}
626624
}
627625

628-
impl<'de, 'a, R: ReadSlice<'de>, C: SerializerConfig> serde::Deserializer<'de> for &'a mut Deserializer<R, C> {
626+
impl<'de, R: ReadSlice<'de>, C: SerializerConfig> serde::Deserializer<'de> for &mut Deserializer<R, C> {
629627
type Error = Error;
630628

631629
#[inline(always)]
@@ -821,7 +819,7 @@ struct SeqAccess<'a, R, C> {
821819

822820
impl<'a, R: 'a, C> SeqAccess<'a, R, C> {
823821
#[inline]
824-
fn new(de: &'a mut Deserializer<R, C>, len: u32) -> Self {
822+
const fn new(de: &'a mut Deserializer<R, C>, len: u32) -> Self {
825823
SeqAccess { de, left: len }
826824
}
827825
}
@@ -854,7 +852,7 @@ struct MapAccess<'a, R, C> {
854852

855853
impl<'a, R: 'a, C> MapAccess<'a, R, C> {
856854
#[inline]
857-
fn new(de: &'a mut Deserializer<R, C>, len: u32) -> Self {
855+
const fn new(de: &'a mut Deserializer<R, C>, len: u32) -> Self {
858856
MapAccess { de, left: len }
859857
}
860858
}
@@ -892,13 +890,13 @@ struct UnitVariantAccess<'a, R: 'a, C> {
892890
}
893891

894892
impl<'a, R: 'a, C> UnitVariantAccess<'a, R, C> {
895-
pub fn new(de: &'a mut Deserializer<R, C>) -> Self {
893+
pub const fn new(de: &'a mut Deserializer<R, C>) -> Self {
896894
UnitVariantAccess { de }
897895
}
898896
}
899897

900-
impl<'de, 'a, R: ReadSlice<'de>, C: SerializerConfig> de::EnumAccess<'de>
901-
for UnitVariantAccess<'a, R, C>
898+
impl<'de, R: ReadSlice<'de>, C: SerializerConfig> de::EnumAccess<'de>
899+
for UnitVariantAccess<'_, R, C>
902900
{
903901
type Error = Error;
904902
type Variant = Self;
@@ -962,12 +960,12 @@ struct VariantAccess<'a, R, C> {
962960
}
963961

964962
impl<'a, R: 'a, C> VariantAccess<'a, R, C> {
965-
pub fn new(de: &'a mut Deserializer<R, C>) -> Self {
963+
pub const fn new(de: &'a mut Deserializer<R, C>) -> Self {
966964
VariantAccess { de }
967965
}
968966
}
969967

970-
impl<'de, 'a, R: ReadSlice<'de>, C: SerializerConfig> de::EnumAccess<'de> for VariantAccess<'a, R, C> {
968+
impl<'de, R: ReadSlice<'de>, C: SerializerConfig> de::EnumAccess<'de> for VariantAccess<'_, R, C> {
971969
type Error = Error;
972970
type Variant = Self;
973971

@@ -979,7 +977,7 @@ impl<'de, 'a, R: ReadSlice<'de>, C: SerializerConfig> de::EnumAccess<'de> for Va
979977
}
980978
}
981979

982-
impl<'de, 'a, R: ReadSlice<'de>, C: SerializerConfig> de::VariantAccess<'de> for VariantAccess<'a, R, C> {
980+
impl<'de, R: ReadSlice<'de>, C: SerializerConfig> de::VariantAccess<'de> for VariantAccess<'_, R, C> {
983981
type Error = Error;
984982

985983
#[inline]
@@ -1037,7 +1035,7 @@ pub struct ReadReader<R: Read> {
10371035
impl<R: Read> ReadReader<R> {
10381036
#[inline]
10391037
fn new(rd: R) -> Self {
1040-
ReadReader {
1038+
Self {
10411039
rd,
10421040
buf: Vec::with_capacity(128),
10431041
}
@@ -1079,7 +1077,7 @@ pub struct ReadRefReader<'a, R: ?Sized> {
10791077
impl<'a, T> ReadRefReader<'a, T> {
10801078
/// Returns the part that hasn't been consumed yet
10811079
#[must_use]
1082-
pub fn remaining_slice(&self) -> &'a [u8] {
1080+
pub const fn remaining_slice(&self) -> &'a [u8] {
10831081
self.buf
10841082
}
10851083
}
@@ -1094,7 +1092,7 @@ impl<'a, T: AsRef<[u8]> + ?Sized> ReadRefReader<'a, T> {
10941092
}
10951093
}
10961094

1097-
impl<'a, T: AsRef<[u8]> + ?Sized> Read for ReadRefReader<'a, T> {
1095+
impl<T: AsRef<[u8]> + ?Sized> Read for ReadRefReader<'_, T> {
10981096
#[inline]
10991097
fn read(&mut self, buf: &mut [u8]) -> Result<usize, io::Error> {
11001098
self.buf.read(buf)

0 commit comments

Comments
 (0)