Skip to content

Commit

Permalink
Add value field to ErrorKind::UnexpectedValue (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
baszalmstra authored Dec 16, 2024
1 parent d841c78 commit c4e31ba
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
3 changes: 1 addition & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ rustflags = [
"-Wclippy::match_wild_err_arm",
"-Wclippy::match_wildcard_for_single_variants",
"-Wclippy::mem_forget",
"-Wclippy::mismatched_target_os",
"-Wclippy::missing_enforced_import_renames",
"-Wclippy::mut_mut",
"-Wclippy::mutex_integer",
Expand Down Expand Up @@ -76,7 +75,7 @@ rustflags = [
"-Wnonstandard_style",
"-Wrust_2018_idioms",
# END - Embark standard lints v6 for Rust 1.55+
"-Dmissing_docs",
"-Dunexpected_cfgs",
]

[target.'cfg(target_env = "musl")']
Expand Down
4 changes: 2 additions & 2 deletions toml-span/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct Ctx<'de, 'b> {
//array: bool,
}

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

impl<'a> E<'a> {
impl E<'_> {
#[allow(dead_code)]
fn type_name(&self) -> &'static str {
match *self {
Expand Down
6 changes: 4 additions & 2 deletions toml-span/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ pub enum ErrorKind {
UnexpectedValue {
/// The list of values that could have been used, eg. typically enum variants
expected: &'static [&'static str],
/// The actual value that was found.
value: Option<String>,
},
}

Expand Down Expand Up @@ -225,7 +227,7 @@ impl Display for Error {
ErrorKind::Deprecated { old, new } => {
write!(f, "field '{old}' is deprecated, '{new}' has replaced it")?;
}
ErrorKind::UnexpectedValue { expected } => write!(f, "expected '{expected:?}'")?,
ErrorKind::UnexpectedValue { expected, .. } => write!(f, "expected '{expected:?}'")?,
}

// if !self.key.is_empty() {
Expand Down Expand Up @@ -328,7 +330,7 @@ impl Error {
.with_labels(vec![
Label::primary(fid, self.span).with_message("deprecated field")
]),
ErrorKind::UnexpectedValue { expected } => diag
ErrorKind::UnexpectedValue { expected, .. } => diag
.with_message(format!("expected '{expected:?}'"))
.with_labels(vec![
Label::primary(fid, self.span).with_message("unexpected value")
Expand Down
2 changes: 1 addition & 1 deletion toml-span/src/impl_serde.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{
};
use serde::ser::{SerializeMap, SerializeSeq};

impl<'de> serde::Serialize for Value<'de> {
impl serde::Serialize for Value<'_> {
fn serialize<S>(&self, ser: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
Expand Down
1 change: 1 addition & 0 deletions toml-span/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![doc = include_str!("../README.md")]
#![deny(missing_docs)]

pub mod de;
pub mod de_helpers;
Expand Down
4 changes: 2 additions & 2 deletions toml-span/src/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ impl<'a> Tokenizer<'a> {
}
}

impl<'a> Iterator for CrlfFold<'a> {
impl Iterator for CrlfFold<'_> {
type Item = (usize, char);

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

impl<'a> Token<'a> {
impl Token<'_> {
pub fn describe(&self) -> &'static str {
match *self {
Token::Keylike(_) => "an identifier",
Expand Down
16 changes: 8 additions & 8 deletions toml-span/src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<'de> AsRef<ValueInner<'de>> for Value<'de> {
}
}

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

impl<'de> std::borrow::Borrow<str> for Key<'de> {
impl std::borrow::Borrow<str> for Key<'_> {
fn borrow(&self) -> &str {
self.name.as_ref()
}
}

impl<'de> fmt::Debug for Key<'de> {
impl fmt::Debug for Key<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.name)
}
}

impl<'de> fmt::Display for Key<'de> {
impl fmt::Display for Key<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.name)
}
}

impl<'de> Ord for Key<'de> {
impl Ord for Key<'_> {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.name.cmp(&other.name)
}
}

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

impl<'de> PartialEq for Key<'de> {
impl PartialEq for Key<'_> {
fn eq(&self, other: &Self) -> bool {
self.name.eq(&other.name)
}
}

impl<'de> Eq for Key<'de> {}
impl Eq for Key<'_> {}

/// A toml table, always represented as a sorted map.
///
Expand Down

0 comments on commit c4e31ba

Please sign in to comment.