Skip to content

Commit 762e677

Browse files
committed
Update Error matching code
This is mostly cosmetic change.
1 parent 5b5f1e4 commit 762e677

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

src/error.rs

+29-29
Original file line numberDiff line numberDiff line change
@@ -205,17 +205,17 @@ pub type Result<T> = StdResult<T, Error>;
205205
#[cfg(not(tarpaulin_include))]
206206
impl fmt::Display for Error {
207207
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
208-
match *self {
209-
Error::SyntaxError { ref message, .. } => write!(fmt, "syntax error: {message}"),
210-
Error::RuntimeError(ref msg) => write!(fmt, "runtime error: {msg}"),
211-
Error::MemoryError(ref msg) => {
208+
match self {
209+
Error::SyntaxError { message, .. } => write!(fmt, "syntax error: {message}"),
210+
Error::RuntimeError(msg) => write!(fmt, "runtime error: {msg}"),
211+
Error::MemoryError(msg) => {
212212
write!(fmt, "memory error: {msg}")
213213
}
214214
#[cfg(any(feature = "lua53", feature = "lua52"))]
215-
Error::GarbageCollectorError(ref msg) => {
215+
Error::GarbageCollectorError(msg) => {
216216
write!(fmt, "garbage collector error: {msg}")
217217
}
218-
Error::SafetyError(ref msg) => {
218+
Error::SafetyError(msg) => {
219219
write!(fmt, "safety error: {msg}")
220220
},
221221
Error::MemoryLimitNotAvailable => {
@@ -234,7 +234,7 @@ impl fmt::Display for Error {
234234
fmt,
235235
"too many arguments to Function::bind"
236236
),
237-
Error::BadArgument { ref to, pos, ref name, ref cause } => {
237+
Error::BadArgument { to, pos, name, cause } => {
238238
if let Some(name) = name {
239239
write!(fmt, "bad argument `{name}`")?;
240240
} else {
@@ -245,40 +245,40 @@ impl fmt::Display for Error {
245245
}
246246
write!(fmt, ": {cause}")
247247
},
248-
Error::ToLuaConversionError { from, to, ref message } => {
248+
Error::ToLuaConversionError { from, to, message } => {
249249
write!(fmt, "error converting {from} to Lua {to}")?;
250-
match *message {
250+
match message {
251251
None => Ok(()),
252-
Some(ref message) => write!(fmt, " ({message})"),
252+
Some(message) => write!(fmt, " ({message})"),
253253
}
254254
}
255-
Error::FromLuaConversionError { from, to, ref message } => {
255+
Error::FromLuaConversionError { from, to, message } => {
256256
write!(fmt, "error converting Lua {from} to {to}")?;
257-
match *message {
257+
match message {
258258
None => Ok(()),
259-
Some(ref message) => write!(fmt, " ({message})"),
259+
Some(message) => write!(fmt, " ({message})"),
260260
}
261261
}
262262
Error::CoroutineUnresumable => write!(fmt, "coroutine is non-resumable"),
263263
Error::UserDataTypeMismatch => write!(fmt, "userdata is not expected type"),
264264
Error::UserDataDestructed => write!(fmt, "userdata has been destructed"),
265265
Error::UserDataBorrowError => write!(fmt, "error borrowing userdata"),
266266
Error::UserDataBorrowMutError => write!(fmt, "error mutably borrowing userdata"),
267-
Error::MetaMethodRestricted(ref method) => write!(fmt, "metamethod {method} is restricted"),
268-
Error::MetaMethodTypeError { ref method, type_name, ref message } => {
267+
Error::MetaMethodRestricted(method) => write!(fmt, "metamethod {method} is restricted"),
268+
Error::MetaMethodTypeError { method, type_name, message } => {
269269
write!(fmt, "metamethod {method} has unsupported type {type_name}")?;
270-
match *message {
270+
match message {
271271
None => Ok(()),
272-
Some(ref message) => write!(fmt, " ({message})"),
272+
Some(message) => write!(fmt, " ({message})"),
273273
}
274274
}
275275
Error::MismatchedRegistryKey => {
276276
write!(fmt, "RegistryKey used from different Lua state")
277277
}
278-
Error::CallbackError { ref cause, ref traceback } => {
278+
Error::CallbackError { cause, traceback } => {
279279
// Trace errors down to the root
280280
let (mut cause, mut full_traceback) = (cause, None);
281-
while let Error::CallbackError { cause: ref cause2, traceback: ref traceback2 } = **cause {
281+
while let Error::CallbackError { cause: cause2, traceback: traceback2 } = &**cause {
282282
cause = cause2;
283283
full_traceback = Some(traceback2);
284284
}
@@ -302,15 +302,15 @@ impl fmt::Display for Error {
302302
write!(fmt, "previously resumed panic returned again")
303303
}
304304
#[cfg(feature = "serialize")]
305-
Error::SerializeError(ref err) => {
305+
Error::SerializeError(err) => {
306306
write!(fmt, "serialize error: {err}")
307307
},
308308
#[cfg(feature = "serialize")]
309-
Error::DeserializeError(ref err) => {
309+
Error::DeserializeError(err) => {
310310
write!(fmt, "deserialize error: {err}")
311311
},
312-
Error::ExternalError(ref err) => write!(fmt, "{err}"),
313-
Error::WithContext { ref context, ref cause } => {
312+
Error::ExternalError(err) => write!(fmt, "{err}"),
313+
Error::WithContext { context, cause } => {
314314
writeln!(fmt, "{context}")?;
315315
write!(fmt, "{cause}")
316316
}
@@ -320,15 +320,15 @@ impl fmt::Display for Error {
320320

321321
impl StdError for Error {
322322
fn source(&self) -> Option<&(dyn StdError + 'static)> {
323-
match *self {
323+
match self {
324324
// An error type with a source error should either return that error via source or
325325
// include that source's error message in its own Display output, but never both.
326326
// https://blog.rust-lang.org/inside-rust/2021/07/01/What-the-error-handling-project-group-is-working-towards.html
327327
// Given that we include source to fmt::Display implementation for `CallbackError`, this call
328328
// returns nothing.
329329
Error::CallbackError { .. } => None,
330-
Error::ExternalError(ref err) => err.source(),
331-
Error::WithContext { ref cause, .. } => match cause.as_ref() {
330+
Error::ExternalError(err) => err.source(),
331+
Error::WithContext { cause, .. } => match cause.as_ref() {
332332
Error::ExternalError(err) => err.source(),
333333
_ => None,
334334
},
@@ -374,15 +374,15 @@ impl Error {
374374
}
375375
}
376376

377-
pub(crate) fn from_lua_conversion<'a>(
377+
pub(crate) fn from_lua_conversion(
378378
from: &'static str,
379379
to: &'static str,
380-
message: impl Into<Option<&'a str>>,
380+
message: impl Into<Option<String>>,
381381
) -> Self {
382382
Error::FromLuaConversionError {
383383
from,
384384
to,
385-
message: message.into().map(|s| s.into()),
385+
message: message.into(),
386386
}
387387
}
388388
}

0 commit comments

Comments
 (0)