Skip to content

Commit c4e31ba

Browse files
authored
Add value field to ErrorKind::UnexpectedValue (#9)
1 parent d841c78 commit c4e31ba

File tree

7 files changed

+19
-17
lines changed

7 files changed

+19
-17
lines changed

.cargo/config.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ rustflags = [
4444
"-Wclippy::match_wild_err_arm",
4545
"-Wclippy::match_wildcard_for_single_variants",
4646
"-Wclippy::mem_forget",
47-
"-Wclippy::mismatched_target_os",
4847
"-Wclippy::missing_enforced_import_renames",
4948
"-Wclippy::mut_mut",
5049
"-Wclippy::mutex_integer",
@@ -76,7 +75,7 @@ rustflags = [
7675
"-Wnonstandard_style",
7776
"-Wrust_2018_idioms",
7877
# END - Embark standard lints v6 for Rust 1.55+
79-
"-Dmissing_docs",
78+
"-Dunexpected_cfgs",
8079
]
8180

8281
[target.'cfg(target_env = "musl")']

toml-span/src/de.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct Ctx<'de, 'b> {
6161
//array: bool,
6262
}
6363

64-
impl<'de, 'b> Ctx<'de, 'b> {
64+
impl Ctx<'_, '_> {
6565
#[inline]
6666
fn error(&self, start: usize, end: Option<usize>, kind: ErrorKind) -> Error {
6767
self.de.error(start, end, kind)
@@ -1102,7 +1102,7 @@ enum E<'a> {
11021102
DottedTable(Vec<TablePair<'a>>),
11031103
}
11041104

1105-
impl<'a> E<'a> {
1105+
impl E<'_> {
11061106
#[allow(dead_code)]
11071107
fn type_name(&self) -> &'static str {
11081108
match *self {

toml-span/src/error.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ pub enum ErrorKind {
129129
UnexpectedValue {
130130
/// The list of values that could have been used, eg. typically enum variants
131131
expected: &'static [&'static str],
132+
/// The actual value that was found.
133+
value: Option<String>,
132134
},
133135
}
134136

@@ -225,7 +227,7 @@ impl Display for Error {
225227
ErrorKind::Deprecated { old, new } => {
226228
write!(f, "field '{old}' is deprecated, '{new}' has replaced it")?;
227229
}
228-
ErrorKind::UnexpectedValue { expected } => write!(f, "expected '{expected:?}'")?,
230+
ErrorKind::UnexpectedValue { expected, .. } => write!(f, "expected '{expected:?}'")?,
229231
}
230232

231233
// if !self.key.is_empty() {
@@ -328,7 +330,7 @@ impl Error {
328330
.with_labels(vec![
329331
Label::primary(fid, self.span).with_message("deprecated field")
330332
]),
331-
ErrorKind::UnexpectedValue { expected } => diag
333+
ErrorKind::UnexpectedValue { expected, .. } => diag
332334
.with_message(format!("expected '{expected:?}'"))
333335
.with_labels(vec![
334336
Label::primary(fid, self.span).with_message("unexpected value")

toml-span/src/impl_serde.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
};
99
use serde::ser::{SerializeMap, SerializeSeq};
1010

11-
impl<'de> serde::Serialize for Value<'de> {
11+
impl serde::Serialize for Value<'_> {
1212
fn serialize<S>(&self, ser: S) -> Result<S::Ok, S::Error>
1313
where
1414
S: serde::Serializer,

toml-span/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#![cfg_attr(docsrs, feature(doc_cfg))]
22
#![doc = include_str!("../README.md")]
3+
#![deny(missing_docs)]
34

45
pub mod de;
56
pub mod de_helpers;

toml-span/src/tokens.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl<'a> Tokenizer<'a> {
484484
}
485485
}
486486

487-
impl<'a> Iterator for CrlfFold<'a> {
487+
impl Iterator for CrlfFold<'_> {
488488
type Item = (usize, char);
489489

490490
fn next(&mut self) -> Option<(usize, char)> {
@@ -531,7 +531,7 @@ fn is_keylike(ch: char) -> bool {
531531
ch.is_ascii_alphanumeric() || ch == '-' || ch == '_'
532532
}
533533

534-
impl<'a> Token<'a> {
534+
impl Token<'_> {
535535
pub fn describe(&self) -> &'static str {
536536
match *self {
537537
Token::Keylike(_) => "an identifier",

toml-span/src/value.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ impl<'de> AsRef<ValueInner<'de>> for Value<'de> {
209209
}
210210
}
211211

212-
impl<'de> fmt::Debug for Value<'de> {
212+
impl fmt::Debug for Value<'_> {
213213
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
214214
write!(f, "{:?}", self.value)
215215
}
@@ -225,43 +225,43 @@ pub struct Key<'de> {
225225
pub span: Span,
226226
}
227227

228-
impl<'de> std::borrow::Borrow<str> for Key<'de> {
228+
impl std::borrow::Borrow<str> for Key<'_> {
229229
fn borrow(&self) -> &str {
230230
self.name.as_ref()
231231
}
232232
}
233233

234-
impl<'de> fmt::Debug for Key<'de> {
234+
impl fmt::Debug for Key<'_> {
235235
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
236236
f.write_str(&self.name)
237237
}
238238
}
239239

240-
impl<'de> fmt::Display for Key<'de> {
240+
impl fmt::Display for Key<'_> {
241241
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
242242
f.write_str(&self.name)
243243
}
244244
}
245245

246-
impl<'de> Ord for Key<'de> {
246+
impl Ord for Key<'_> {
247247
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
248248
self.name.cmp(&other.name)
249249
}
250250
}
251251

252-
impl<'de> PartialOrd for Key<'de> {
252+
impl PartialOrd for Key<'_> {
253253
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
254254
Some(self.cmp(other))
255255
}
256256
}
257257

258-
impl<'de> PartialEq for Key<'de> {
258+
impl PartialEq for Key<'_> {
259259
fn eq(&self, other: &Self) -> bool {
260260
self.name.eq(&other.name)
261261
}
262262
}
263263

264-
impl<'de> Eq for Key<'de> {}
264+
impl Eq for Key<'_> {}
265265

266266
/// A toml table, always represented as a sorted map.
267267
///

0 commit comments

Comments
 (0)