summaryrefslogtreecommitdiffstats
path: root/vendor/toml_edit/src
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-06-19 09:26:03 +0000
commit9918693037dce8aa4bb6f08741b6812923486c18 (patch)
tree21d2b40bec7e6a7ea664acee056eb3d08e15a1cf /vendor/toml_edit/src
parentReleasing progress-linux version 1.75.0+dfsg1-5~progress7.99u1. (diff)
downloadrustc-9918693037dce8aa4bb6f08741b6812923486c18.tar.xz
rustc-9918693037dce8aa4bb6f08741b6812923486c18.zip
Merging upstream version 1.76.0+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/toml_edit/src')
-rw-r--r--vendor/toml_edit/src/array.rs7
-rw-r--r--vendor/toml_edit/src/array_of_tables.rs1
-rw-r--r--vendor/toml_edit/src/de/mod.rs3
-rw-r--r--vendor/toml_edit/src/de/value.rs1
-rw-r--r--vendor/toml_edit/src/document.rs4
-rw-r--r--vendor/toml_edit/src/error.rs (renamed from vendor/toml_edit/src/parser/errors.rs)85
-rw-r--r--vendor/toml_edit/src/inline_table.rs5
-rw-r--r--vendor/toml_edit/src/item.rs4
-rw-r--r--vendor/toml_edit/src/key.rs49
-rw-r--r--vendor/toml_edit/src/lib.rs17
-rw-r--r--vendor/toml_edit/src/parser/array.rs2
-rw-r--r--vendor/toml_edit/src/parser/datetime.rs4
-rw-r--r--vendor/toml_edit/src/parser/error.rs87
-rw-r--r--vendor/toml_edit/src/parser/inline_table.rs4
-rw-r--r--vendor/toml_edit/src/parser/key.rs4
-rw-r--r--vendor/toml_edit/src/parser/mod.rs14
-rw-r--r--vendor/toml_edit/src/parser/numbers.rs2
-rw-r--r--vendor/toml_edit/src/parser/state.rs2
-rw-r--r--vendor/toml_edit/src/parser/strings.rs4
-rw-r--r--vendor/toml_edit/src/parser/trivia.rs2
-rw-r--r--vendor/toml_edit/src/parser/value.rs2
-rw-r--r--vendor/toml_edit/src/raw_string.rs2
-rw-r--r--vendor/toml_edit/src/repr.rs20
-rw-r--r--vendor/toml_edit/src/ser/mod.rs3
-rw-r--r--vendor/toml_edit/src/table.rs5
-rw-r--r--vendor/toml_edit/src/value.rs9
-rw-r--r--vendor/toml_edit/src/visit.rs4
-rw-r--r--vendor/toml_edit/src/visit_mut.rs6
28 files changed, 243 insertions, 109 deletions
diff --git a/vendor/toml_edit/src/array.rs b/vendor/toml_edit/src/array.rs
index 97033de58..69e7f3ccb 100644
--- a/vendor/toml_edit/src/array.rs
+++ b/vendor/toml_edit/src/array.rs
@@ -183,9 +183,11 @@ impl Array {
/// # Examples
///
/// ```rust
+ /// # #[cfg(feature = "parse")] {
/// let formatted_value = "'literal'".parse::<toml_edit::Value>().unwrap();
/// let mut arr = toml_edit::Array::new();
/// arr.push_formatted(formatted_value);
+ /// # }
/// ```
pub fn push_formatted(&mut self, v: Value) {
self.values.push(Item::Value(v));
@@ -223,12 +225,14 @@ impl Array {
/// # Examples
///
/// ```rust
+ /// # #[cfg(feature = "parse")] {
/// let mut arr = toml_edit::Array::new();
/// arr.push(1);
/// arr.push("foo");
///
/// let formatted_value = "'start'".parse::<toml_edit::Value>().unwrap();
/// arr.insert_formatted(0, formatted_value);
+ /// # }
/// ```
pub fn insert_formatted(&mut self, index: usize, v: Value) {
self.values.insert(index, Item::Value(v))
@@ -269,12 +273,14 @@ impl Array {
/// # Examples
///
/// ```rust
+ /// # #[cfg(feature = "parse")] {
/// let mut arr = toml_edit::Array::new();
/// arr.push(1);
/// arr.push("foo");
///
/// let formatted_value = "'start'".parse::<toml_edit::Value>().unwrap();
/// arr.replace_formatted(0, formatted_value);
+ /// # }
/// ```
pub fn replace_formatted(&mut self, index: usize, v: Value) -> Value {
match mem::replace(&mut self.values[index], Item::Value(v)) {
@@ -383,6 +389,7 @@ impl Array {
}
}
+#[cfg(feature = "display")]
impl std::fmt::Display for Array {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
crate::encode::Encode::encode(self, f, None, ("", ""))
diff --git a/vendor/toml_edit/src/array_of_tables.rs b/vendor/toml_edit/src/array_of_tables.rs
index c4d719488..2e602a2c5 100644
--- a/vendor/toml_edit/src/array_of_tables.rs
+++ b/vendor/toml_edit/src/array_of_tables.rs
@@ -158,6 +158,7 @@ impl<'s> IntoIterator for &'s ArrayOfTables {
}
}
+#[cfg(feature = "display")]
impl std::fmt::Display for ArrayOfTables {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// HACK: Without the header, we don't really have a proper way of printing this
diff --git a/vendor/toml_edit/src/de/mod.rs b/vendor/toml_edit/src/de/mod.rs
index 09ea12096..9b8a2c7bc 100644
--- a/vendor/toml_edit/src/de/mod.rs
+++ b/vendor/toml_edit/src/de/mod.rs
@@ -87,6 +87,7 @@ impl From<Error> for crate::TomlError {
impl std::error::Error for Error {}
/// Convert a value into `T`.
+#[cfg(feature = "parse")]
pub fn from_str<T>(s: &'_ str) -> Result<T, Error>
where
T: DeserializeOwned,
@@ -96,6 +97,7 @@ where
}
/// Convert a value into `T`.
+#[cfg(feature = "parse")]
pub fn from_slice<T>(s: &'_ [u8]) -> Result<T, Error>
where
T: DeserializeOwned,
@@ -125,6 +127,7 @@ impl Deserializer {
}
}
+#[cfg(feature = "parse")]
impl std::str::FromStr for Deserializer {
type Err = Error;
diff --git a/vendor/toml_edit/src/de/value.rs b/vendor/toml_edit/src/de/value.rs
index d3cf87fc6..ba6ce6db3 100644
--- a/vendor/toml_edit/src/de/value.rs
+++ b/vendor/toml_edit/src/de/value.rs
@@ -241,6 +241,7 @@ impl crate::Item {
}
}
+#[cfg(feature = "parse")]
impl std::str::FromStr for ValueDeserializer {
type Err = Error;
diff --git a/vendor/toml_edit/src/document.rs b/vendor/toml_edit/src/document.rs
index 67dd293dd..f20e61a96 100644
--- a/vendor/toml_edit/src/document.rs
+++ b/vendor/toml_edit/src/document.rs
@@ -1,6 +1,5 @@
use std::str::FromStr;
-use crate::parser;
use crate::table::Iter;
use crate::{Item, RawString, Table};
@@ -78,12 +77,13 @@ impl Default for Document {
}
}
+#[cfg(feature = "parse")]
impl FromStr for Document {
type Err = crate::TomlError;
/// Parses a document from a &str
fn from_str(s: &str) -> Result<Self, Self::Err> {
- let mut d = parser::parse_document(s)?;
+ let mut d = crate::parser::parse_document(s)?;
d.despan();
Ok(d)
}
diff --git a/vendor/toml_edit/src/parser/errors.rs b/vendor/toml_edit/src/error.rs
index 685e9f716..a98301981 100644
--- a/vendor/toml_edit/src/parser/errors.rs
+++ b/vendor/toml_edit/src/error.rs
@@ -1,12 +1,6 @@
use std::error::Error as StdError;
use std::fmt::{Display, Formatter, Result};
-use crate::parser::prelude::*;
-use crate::Key;
-
-use winnow::error::ContextError;
-use winnow::error::ParseError;
-
/// Type representing a TOML parse error
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct TomlError {
@@ -17,7 +11,14 @@ pub struct TomlError {
}
impl TomlError {
- pub(crate) fn new(error: ParseError<Input<'_>, ContextError>, mut original: Input<'_>) -> Self {
+ #[cfg(feature = "parse")]
+ pub(crate) fn new(
+ error: winnow::error::ParseError<
+ crate::parser::prelude::Input<'_>,
+ winnow::error::ContextError,
+ >,
+ mut original: crate::parser::prelude::Input<'_>,
+ ) -> Self {
use winnow::stream::Stream;
let offset = error.offset();
@@ -243,73 +244,3 @@ mod test_translate_position {
assert_eq!(position, (1, 2));
}
}
-
-#[derive(Debug, Clone)]
-pub(crate) enum CustomError {
- DuplicateKey {
- key: String,
- table: Option<Vec<Key>>,
- },
- DottedKeyExtendWrongType {
- key: Vec<Key>,
- actual: &'static str,
- },
- OutOfRange,
- #[cfg_attr(feature = "unbounded", allow(dead_code))]
- RecursionLimitExceeded,
-}
-
-impl CustomError {
- pub(crate) fn duplicate_key(path: &[Key], i: usize) -> Self {
- assert!(i < path.len());
- let key = &path[i];
- let repr = key.display_repr();
- Self::DuplicateKey {
- key: repr.into(),
- table: Some(path[..i].to_vec()),
- }
- }
-
- pub(crate) fn extend_wrong_type(path: &[Key], i: usize, actual: &'static str) -> Self {
- assert!(i < path.len());
- Self::DottedKeyExtendWrongType {
- key: path[..=i].to_vec(),
- actual,
- }
- }
-}
-
-impl StdError for CustomError {
- fn description(&self) -> &'static str {
- "TOML parse error"
- }
-}
-
-impl Display for CustomError {
- fn fmt(&self, f: &mut Formatter<'_>) -> Result {
- match self {
- CustomError::DuplicateKey { key, table } => {
- if let Some(table) = table {
- if table.is_empty() {
- write!(f, "duplicate key `{}` in document root", key)
- } else {
- let path = table.iter().map(|k| k.get()).collect::<Vec<_>>().join(".");
- write!(f, "duplicate key `{}` in table `{}`", key, path)
- }
- } else {
- write!(f, "duplicate key `{}`", key)
- }
- }
- CustomError::DottedKeyExtendWrongType { key, actual } => {
- let path = key.iter().map(|k| k.get()).collect::<Vec<_>>().join(".");
- write!(
- f,
- "dotted key `{}` attempted to extend non-table type ({})",
- path, actual
- )
- }
- CustomError::OutOfRange => write!(f, "value is out of range"),
- CustomError::RecursionLimitExceeded => write!(f, "recursion limit exceeded"),
- }
- }
-}
diff --git a/vendor/toml_edit/src/inline_table.rs b/vendor/toml_edit/src/inline_table.rs
index cbd64adb3..136c1e8f1 100644
--- a/vendor/toml_edit/src/inline_table.rs
+++ b/vendor/toml_edit/src/inline_table.rs
@@ -146,11 +146,15 @@ impl InlineTable {
/// In the document above, tables `target` and `target."x86_64/windows.json"` are implicit.
///
/// ```
+ /// # #[cfg(feature = "parse")] {
+ /// # #[cfg(feature = "display")] {
/// use toml_edit::Document;
/// let mut doc = "[a]\n[a.b]\n".parse::<Document>().expect("invalid toml");
///
/// doc["a"].as_table_mut().unwrap().set_implicit(true);
/// assert_eq!(doc.to_string(), "[a.b]\n");
+ /// # }
+ /// # }
/// ```
pub(crate) fn set_implicit(&mut self, implicit: bool) {
self.implicit = implicit;
@@ -411,6 +415,7 @@ impl InlineTable {
}
}
+#[cfg(feature = "display")]
impl std::fmt::Display for InlineTable {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
crate::encode::Encode::encode(self, f, None, ("", ""))
diff --git a/vendor/toml_edit/src/item.rs b/vendor/toml_edit/src/item.rs
index a14056319..b58806e47 100644
--- a/vendor/toml_edit/src/item.rs
+++ b/vendor/toml_edit/src/item.rs
@@ -329,6 +329,7 @@ impl Clone for Item {
}
}
+#[cfg(feature = "parse")]
impl FromStr for Item {
type Err = crate::TomlError;
@@ -339,6 +340,7 @@ impl FromStr for Item {
}
}
+#[cfg(feature = "display")]
impl std::fmt::Display for Item {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match &self {
@@ -358,6 +360,7 @@ impl std::fmt::Display for Item {
///
/// # Examples
/// ```rust
+/// # #[cfg(feature = "display")] {
/// # use snapbox::assert_eq;
/// # use toml_edit::*;
/// let mut table = Table::default();
@@ -372,6 +375,7 @@ impl std::fmt::Display for Item {
/// key2 = 42
/// key3 = ["hello", '\, world']
/// "#);
+/// # }
/// ```
pub fn value<V: Into<Value>>(v: V) -> Item {
Item::Value(v.into())
diff --git a/vendor/toml_edit/src/key.rs b/vendor/toml_edit/src/key.rs
index c1ee1655c..2f99f7082 100644
--- a/vendor/toml_edit/src/key.rs
+++ b/vendor/toml_edit/src/key.rs
@@ -1,9 +1,6 @@
use std::borrow::Cow;
use std::str::FromStr;
-use crate::encode::{to_string_repr, StringStyle};
-use crate::parser;
-use crate::parser::key::is_unquoted_char;
use crate::repr::{Decor, Repr};
use crate::InternalString;
@@ -49,6 +46,7 @@ impl Key {
/// Parse a TOML key expression
///
/// Unlike `"".parse<Key>()`, this supports dotted keys.
+ #[cfg(feature = "parse")]
pub fn parse(repr: &str) -> Result<Vec<Self>, crate::TomlError> {
Self::try_parse_path(repr)
}
@@ -84,11 +82,13 @@ impl Key {
}
/// Returns the default raw representation.
+ #[cfg(feature = "display")]
pub fn default_repr(&self) -> Repr {
to_key_repr(&self.key)
}
/// Returns a raw representation.
+ #[cfg(feature = "display")]
pub fn display_repr(&self) -> Cow<'_, str> {
self.as_repr()
.and_then(|r| r.as_raw().as_str())
@@ -123,18 +123,20 @@ impl Key {
/// Auto formats the key.
pub fn fmt(&mut self) {
- self.repr = Some(to_key_repr(&self.key));
+ self.repr = None;
self.decor.clear();
}
+ #[cfg(feature = "parse")]
fn try_parse_simple(s: &str) -> Result<Key, crate::TomlError> {
- let mut key = parser::parse_key(s)?;
+ let mut key = crate::parser::parse_key(s)?;
key.despan(s);
Ok(key)
}
+ #[cfg(feature = "parse")]
fn try_parse_path(s: &str) -> Result<Vec<Key>, crate::TomlError> {
- let mut keys = parser::parse_key_path(s)?;
+ let mut keys = crate::parser::parse_key_path(s)?;
for key in &mut keys {
key.despan(s);
}
@@ -209,12 +211,14 @@ impl PartialEq<String> for Key {
}
}
+#[cfg(feature = "display")]
impl std::fmt::Display for Key {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
crate::encode::Encode::encode(self, f, None, ("", ""))
}
}
+#[cfg(feature = "parse")]
impl FromStr for Key {
type Err = crate::TomlError;
@@ -226,11 +230,33 @@ impl FromStr for Key {
}
}
+#[cfg(feature = "display")]
fn to_key_repr(key: &str) -> Repr {
- if key.as_bytes().iter().copied().all(is_unquoted_char) && !key.is_empty() {
- Repr::new_unchecked(key)
- } else {
- to_string_repr(key, Some(StringStyle::OnelineSingle), Some(false))
+ #[cfg(feature = "parse")]
+ {
+ if key
+ .as_bytes()
+ .iter()
+ .copied()
+ .all(crate::parser::key::is_unquoted_char)
+ && !key.is_empty()
+ {
+ Repr::new_unchecked(key)
+ } else {
+ crate::encode::to_string_repr(
+ key,
+ Some(crate::encode::StringStyle::OnelineSingle),
+ Some(false),
+ )
+ }
+ }
+ #[cfg(not(feature = "parse"))]
+ {
+ crate::encode::to_string_repr(
+ key,
+ Some(crate::encode::StringStyle::OnelineSingle),
+ Some(false),
+ )
}
}
@@ -283,11 +309,13 @@ impl<'k> KeyMut<'k> {
}
/// Returns the default raw representation.
+ #[cfg(feature = "display")]
pub fn default_repr(&self) -> Repr {
self.key.default_repr()
}
/// Returns a raw representation.
+ #[cfg(feature = "display")]
pub fn display_repr(&self) -> Cow<str> {
self.key.display_repr()
}
@@ -337,6 +365,7 @@ impl<'s> PartialEq<String> for KeyMut<'s> {
}
}
+#[cfg(feature = "display")]
impl<'k> std::fmt::Display for KeyMut<'k> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.key, f)
diff --git a/vendor/toml_edit/src/lib.rs b/vendor/toml_edit/src/lib.rs
index 80c0ddda2..25e3d2042 100644
--- a/vendor/toml_edit/src/lib.rs
+++ b/vendor/toml_edit/src/lib.rs
@@ -14,6 +14,8 @@
//! # Example
//!
//! ```rust
+//! # #[cfg(feature = "parse")] {
+//! # #[cfg(feature = "display")] {
//! use toml_edit::{Document, value};
//!
//! let toml = r#"
@@ -32,47 +34,54 @@
//! c = { d = "hello" }
//! "#;
//! assert_eq!(doc.to_string(), expected);
+//! # }
+//! # }
//! ```
//!
//! ## Controlling formatting
//!
//! By default, values are created with default formatting
//! ```rust
+//! # #[cfg(feature = "display")] {
//! let mut doc = toml_edit::Document::new();
//! doc["foo"] = toml_edit::value("bar");
//! let expected = r#"foo = "bar"
//! "#;
//! assert_eq!(doc.to_string(), expected);
+//! # }
//! ```
//!
//! You can choose a custom TOML representation by parsing the value.
//! ```rust
+//! # #[cfg(feature = "display")] {
//! let mut doc = toml_edit::Document::new();
//! doc["foo"] = "'bar'".parse::<toml_edit::Item>().unwrap();
//! let expected = r#"foo = 'bar'
//! "#;
//! assert_eq!(doc.to_string(), expected);
+//! # }
//! ```
//!
//! ## Limitations
//!
//! Things it does not preserve:
//!
-//! * Scattered array of tables (tables are reordered by default, see [test]).
-//! * Order of dotted keys, see [issue](https://github.com/ordian/toml_edit/issues/163).
+//! * Order of dotted keys, see [issue](https://github.com/toml-rs/toml/issues/163).
//!
//! [`toml`]: https://docs.rs/toml/latest/toml/
-//! [test]: https://github.com/ordian/toml_edit/blob/f09bd5d075fdb7d2ef8d9bb3270a34506c276753/tests/test_valid.rs#L84
mod array;
mod array_of_tables;
mod document;
+#[cfg(feature = "display")]
mod encode;
+mod error;
mod index;
mod inline_table;
mod internal_string;
mod item;
mod key;
+#[cfg(feature = "parse")]
mod parser;
mod raw_string;
mod repr;
@@ -92,6 +101,7 @@ pub use crate::array_of_tables::{
ArrayOfTables, ArrayOfTablesIntoIter, ArrayOfTablesIter, ArrayOfTablesIterMut,
};
pub use crate::document::Document;
+pub use crate::error::TomlError;
pub use crate::inline_table::{
InlineEntry, InlineOccupiedEntry, InlineTable, InlineTableIntoIter, InlineTableIter,
InlineTableIterMut, InlineVacantEntry,
@@ -99,7 +109,6 @@ pub use crate::inline_table::{
pub use crate::internal_string::InternalString;
pub use crate::item::{array, table, value, Item};
pub use crate::key::{Key, KeyMut};
-pub use crate::parser::TomlError;
pub use crate::raw_string::RawString;
pub use crate::repr::{Decor, Formatted, Repr};
pub use crate::table::{
diff --git a/vendor/toml_edit/src/parser/array.rs b/vendor/toml_edit/src/parser/array.rs
index e3b1f3f52..078319193 100644
--- a/vendor/toml_edit/src/parser/array.rs
+++ b/vendor/toml_edit/src/parser/array.rs
@@ -81,6 +81,8 @@ pub(crate) fn array_value<'i>(
}
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/datetime.rs b/vendor/toml_edit/src/parser/datetime.rs
index 96a3854d4..945dc6935 100644
--- a/vendor/toml_edit/src/parser/datetime.rs
+++ b/vendor/toml_edit/src/parser/datetime.rs
@@ -1,6 +1,6 @@
use std::ops::RangeInclusive;
-use crate::parser::errors::CustomError;
+use crate::parser::error::CustomError;
use crate::parser::prelude::*;
use crate::parser::trivia::from_utf8_unchecked;
@@ -263,6 +263,8 @@ pub(crate) fn unsigned_digits<'i, const MIN: usize, const MAX: usize>(
const DIGIT: RangeInclusive<u8> = b'0'..=b'9';
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/error.rs b/vendor/toml_edit/src/parser/error.rs
new file mode 100644
index 000000000..22e8e6626
--- /dev/null
+++ b/vendor/toml_edit/src/parser/error.rs
@@ -0,0 +1,87 @@
+use std::error::Error as StdError;
+use std::fmt::{Display, Formatter, Result};
+
+use crate::Key;
+
+#[derive(Debug, Clone)]
+pub(crate) enum CustomError {
+ DuplicateKey {
+ key: String,
+ table: Option<Vec<Key>>,
+ },
+ DottedKeyExtendWrongType {
+ key: Vec<Key>,
+ actual: &'static str,
+ },
+ OutOfRange,
+ #[cfg_attr(feature = "unbounded", allow(dead_code))]
+ RecursionLimitExceeded,
+}
+
+impl CustomError {
+ pub(crate) fn duplicate_key(path: &[Key], i: usize) -> Self {
+ assert!(i < path.len());
+ let key = &path[i];
+ let repr = key
+ .as_repr()
+ .and_then(|key| key.as_raw().as_str())
+ .map(|s| s.to_owned())
+ .unwrap_or_else(|| {
+ #[cfg(feature = "display")]
+ {
+ key.default_repr().as_raw().as_str().unwrap().to_owned()
+ }
+ #[cfg(not(feature = "display"))]
+ {
+ format!("{:?}", key.get())
+ }
+ });
+ Self::DuplicateKey {
+ key: repr,
+ table: Some(path[..i].to_vec()),
+ }
+ }
+
+ pub(crate) fn extend_wrong_type(path: &[Key], i: usize, actual: &'static str) -> Self {
+ assert!(i < path.len());
+ Self::DottedKeyExtendWrongType {
+ key: path[..=i].to_vec(),
+ actual,
+ }
+ }
+}
+
+impl StdError for CustomError {
+ fn description(&self) -> &'static str {
+ "TOML parse error"
+ }
+}
+
+impl Display for CustomError {
+ fn fmt(&self, f: &mut Formatter<'_>) -> Result {
+ match self {
+ CustomError::DuplicateKey { key, table } => {
+ if let Some(table) = table {
+ if table.is_empty() {
+ write!(f, "duplicate key `{}` in document root", key)
+ } else {
+ let path = table.iter().map(|k| k.get()).collect::<Vec<_>>().join(".");
+ write!(f, "duplicate key `{}` in table `{}`", key, path)
+ }
+ } else {
+ write!(f, "duplicate key `{}`", key)
+ }
+ }
+ CustomError::DottedKeyExtendWrongType { key, actual } => {
+ let path = key.iter().map(|k| k.get()).collect::<Vec<_>>().join(".");
+ write!(
+ f,
+ "dotted key `{}` attempted to extend non-table type ({})",
+ path, actual
+ )
+ }
+ CustomError::OutOfRange => write!(f, "value is out of range"),
+ CustomError::RecursionLimitExceeded => write!(f, "recursion limit exceeded"),
+ }
+ }
+}
diff --git a/vendor/toml_edit/src/parser/inline_table.rs b/vendor/toml_edit/src/parser/inline_table.rs
index f7cf2e9c5..c2e6619a3 100644
--- a/vendor/toml_edit/src/parser/inline_table.rs
+++ b/vendor/toml_edit/src/parser/inline_table.rs
@@ -5,7 +5,7 @@ use winnow::token::one_of;
use winnow::trace::trace;
use crate::key::Key;
-use crate::parser::errors::CustomError;
+use crate::parser::error::CustomError;
use crate::parser::key::key;
use crate::parser::prelude::*;
use crate::parser::trivia::ws;
@@ -165,6 +165,8 @@ fn keyval<'i>(
}
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/key.rs b/vendor/toml_edit/src/parser/key.rs
index bd8804a23..71b756300 100644
--- a/vendor/toml_edit/src/parser/key.rs
+++ b/vendor/toml_edit/src/parser/key.rs
@@ -7,7 +7,7 @@ use winnow::token::take_while;
use winnow::trace::trace;
use crate::key::Key;
-use crate::parser::errors::CustomError;
+use crate::parser::error::CustomError;
use crate::parser::prelude::*;
use crate::parser::strings::{basic_string, literal_string};
use crate::parser::trivia::{from_utf8_unchecked, ws};
@@ -88,6 +88,8 @@ const UNQUOTED_CHAR: (
const DOT_SEP: u8 = b'.';
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/mod.rs b/vendor/toml_edit/src/parser/mod.rs
index eb4755055..e0322024c 100644
--- a/vendor/toml_edit/src/parser/mod.rs
+++ b/vendor/toml_edit/src/parser/mod.rs
@@ -3,7 +3,7 @@
pub(crate) mod array;
pub(crate) mod datetime;
pub(crate) mod document;
-pub(crate) mod errors;
+pub(crate) mod error;
pub(crate) mod inline_table;
pub(crate) mod key;
pub(crate) mod numbers;
@@ -13,7 +13,7 @@ pub(crate) mod table;
pub(crate) mod trivia;
pub(crate) mod value;
-pub use errors::TomlError;
+pub use crate::error::TomlError;
pub(crate) fn parse_document(raw: &str) -> Result<crate::Document, TomlError> {
use prelude::*;
@@ -95,11 +95,11 @@ pub(crate) mod prelude {
#[cfg(not(feature = "unbounded"))]
impl RecursionCheck {
- pub(crate) fn check_depth(depth: usize) -> Result<(), super::errors::CustomError> {
+ pub(crate) fn check_depth(depth: usize) -> Result<(), super::error::CustomError> {
if depth < 128 {
Ok(())
} else {
- Err(super::errors::CustomError::RecursionLimitExceeded)
+ Err(super::error::CustomError::RecursionLimitExceeded)
}
}
@@ -114,7 +114,7 @@ pub(crate) mod prelude {
Err(winnow::error::ErrMode::from_external_error(
input,
winnow::error::ErrorKind::Eof,
- super::errors::CustomError::RecursionLimitExceeded,
+ super::error::CustomError::RecursionLimitExceeded,
))
}
}
@@ -126,7 +126,7 @@ pub(crate) mod prelude {
#[cfg(feature = "unbounded")]
impl RecursionCheck {
- pub(crate) fn check_depth(_depth: usize) -> Result<(), super::errors::CustomError> {
+ pub(crate) fn check_depth(_depth: usize) -> Result<(), super::error::CustomError> {
Ok(())
}
@@ -140,6 +140,8 @@ pub(crate) mod prelude {
}
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/numbers.rs b/vendor/toml_edit/src/parser/numbers.rs
index 4c77f51c1..96815268e 100644
--- a/vendor/toml_edit/src/parser/numbers.rs
+++ b/vendor/toml_edit/src/parser/numbers.rs
@@ -319,6 +319,8 @@ pub(crate) const HEXDIG: (RangeInclusive<u8>, RangeInclusive<u8>, RangeInclusive
(DIGIT, b'A'..=b'F', b'a'..=b'f');
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/state.rs b/vendor/toml_edit/src/parser/state.rs
index 235391c75..8388c8847 100644
--- a/vendor/toml_edit/src/parser/state.rs
+++ b/vendor/toml_edit/src/parser/state.rs
@@ -1,5 +1,5 @@
use crate::key::Key;
-use crate::parser::errors::CustomError;
+use crate::parser::error::CustomError;
use crate::repr::Decor;
use crate::table::TableKeyValue;
use crate::{ArrayOfTables, Document, InternalString, Item, RawString, Table};
diff --git a/vendor/toml_edit/src/parser/strings.rs b/vendor/toml_edit/src/parser/strings.rs
index 8c366fad5..675b5c67c 100644
--- a/vendor/toml_edit/src/parser/strings.rs
+++ b/vendor/toml_edit/src/parser/strings.rs
@@ -21,7 +21,7 @@ use winnow::token::tag;
use winnow::token::take_while;
use winnow::trace::trace;
-use crate::parser::errors::CustomError;
+use crate::parser::error::CustomError;
use crate::parser::numbers::HEXDIG;
use crate::parser::prelude::*;
use crate::parser::trivia::{from_utf8_unchecked, newline, ws, ws_newlines, NON_ASCII, WSCHAR};
@@ -363,6 +363,8 @@ fn mll_quotes<'i>(
}
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/trivia.rs b/vendor/toml_edit/src/parser/trivia.rs
index a359805b2..4575fb153 100644
--- a/vendor/toml_edit/src/parser/trivia.rs
+++ b/vendor/toml_edit/src/parser/trivia.rs
@@ -120,6 +120,8 @@ pub(crate) fn line_trailing(input: &mut Input<'_>) -> PResult<std::ops::Range<us
}
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/parser/value.rs b/vendor/toml_edit/src/parser/value.rs
index 9e1f0781c..33300ec4c 100644
--- a/vendor/toml_edit/src/parser/value.rs
+++ b/vendor/toml_edit/src/parser/value.rs
@@ -121,6 +121,8 @@ fn apply_raw(mut val: Value, span: std::ops::Range<usize>) -> Result<Value, std:
}
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod test {
use super::*;
diff --git a/vendor/toml_edit/src/raw_string.rs b/vendor/toml_edit/src/raw_string.rs
index c5961f133..53714a1d3 100644
--- a/vendor/toml_edit/src/raw_string.rs
+++ b/vendor/toml_edit/src/raw_string.rs
@@ -80,6 +80,7 @@ impl RawString {
}
}
+ #[cfg(feature = "display")]
pub(crate) fn encode(&self, buf: &mut dyn std::fmt::Write, input: &str) -> std::fmt::Result {
let raw = self.to_str(input);
for part in raw.split('\r') {
@@ -88,6 +89,7 @@ impl RawString {
Ok(())
}
+ #[cfg(feature = "display")]
pub(crate) fn encode_with_default(
&self,
buf: &mut dyn std::fmt::Write,
diff --git a/vendor/toml_edit/src/repr.rs b/vendor/toml_edit/src/repr.rs
index d4ab6c231..7b408f4bf 100644
--- a/vendor/toml_edit/src/repr.rs
+++ b/vendor/toml_edit/src/repr.rs
@@ -44,11 +44,13 @@ where
}
/// Returns the default raw representation.
+ #[cfg(feature = "display")]
pub fn default_repr(&self) -> Repr {
self.value.to_repr()
}
/// Returns a raw representation.
+ #[cfg(feature = "display")]
pub fn display_repr(&self) -> Cow<str> {
self.as_repr()
.and_then(|r| r.as_raw().as_str())
@@ -82,7 +84,7 @@ where
/// Auto formats the value.
pub fn fmt(&mut self) {
- self.repr = Some(self.value.to_repr());
+ self.repr = None;
}
}
@@ -103,6 +105,7 @@ where
}
}
+#[cfg(feature = "display")]
impl<T> std::fmt::Display for Formatted<T>
where
T: ValueRepr,
@@ -114,9 +117,21 @@ where
pub trait ValueRepr: crate::private::Sealed {
/// The TOML representation of the value
+ #[cfg(feature = "display")]
fn to_repr(&self) -> Repr;
}
+#[cfg(not(feature = "display"))]
+mod inner {
+ use super::ValueRepr;
+
+ impl ValueRepr for String {}
+ impl ValueRepr for i64 {}
+ impl ValueRepr for f64 {}
+ impl ValueRepr for bool {}
+ impl ValueRepr for toml_datetime::Datetime {}
+}
+
/// TOML-encoded value
#[derive(Eq, PartialEq, Clone, Hash)]
pub struct Repr {
@@ -144,6 +159,7 @@ impl Repr {
self.raw_value.despan(input)
}
+ #[cfg(feature = "display")]
pub(crate) fn encode(&self, buf: &mut dyn std::fmt::Write, input: &str) -> std::fmt::Result {
self.as_raw().encode(buf, input)
}
@@ -185,6 +201,7 @@ impl Decor {
self.prefix.as_ref()
}
+ #[cfg(feature = "display")]
pub(crate) fn prefix_encode(
&self,
buf: &mut dyn std::fmt::Write,
@@ -208,6 +225,7 @@ impl Decor {
self.suffix.as_ref()
}
+ #[cfg(feature = "display")]
pub(crate) fn suffix_encode(
&self,
buf: &mut dyn std::fmt::Write,
diff --git a/vendor/toml_edit/src/ser/mod.rs b/vendor/toml_edit/src/ser/mod.rs
index 7f9993027..ba31708be 100644
--- a/vendor/toml_edit/src/ser/mod.rs
+++ b/vendor/toml_edit/src/ser/mod.rs
@@ -84,6 +84,7 @@ impl std::error::Error for Error {}
/// Serialization can fail if `T`'s implementation of `Serialize` decides to
/// fail, if `T` contains a map with non-string keys, or if `T` attempts to
/// serialize an unsupported datatype such as an enum, tuple, or tuple struct.
+#[cfg(feature = "display")]
pub fn to_vec<T: ?Sized>(value: &T) -> Result<Vec<u8>, Error>
where
T: serde::ser::Serialize,
@@ -127,6 +128,7 @@ where
/// let toml = toml_edit::ser::to_string(&config).unwrap();
/// println!("{}", toml)
/// ```
+#[cfg(feature = "display")]
pub fn to_string<T: ?Sized>(value: &T) -> Result<String, Error>
where
T: serde::ser::Serialize,
@@ -138,6 +140,7 @@ where
///
/// This is identical to `to_string` except the output string has a more
/// "pretty" output. See `ValueSerializer::pretty` for more details.
+#[cfg(feature = "display")]
pub fn to_string_pretty<T: ?Sized>(value: &T) -> Result<String, Error>
where
T: serde::ser::Serialize,
diff --git a/vendor/toml_edit/src/table.rs b/vendor/toml_edit/src/table.rs
index 893028903..0f44a8e4b 100644
--- a/vendor/toml_edit/src/table.rs
+++ b/vendor/toml_edit/src/table.rs
@@ -165,11 +165,15 @@ impl Table {
/// In the document above, tables `target` and `target."x86_64/windows.json"` are implicit.
///
/// ```
+ /// # #[cfg(feature = "parse")] {
+ /// # #[cfg(feature = "display")] {
/// use toml_edit::Document;
/// let mut doc = "[a]\n[a.b]\n".parse::<Document>().expect("invalid toml");
///
/// doc["a"].as_table_mut().unwrap().set_implicit(true);
/// assert_eq!(doc.to_string(), "[a.b]\n");
+ /// # }
+ /// # }
/// ```
pub fn set_implicit(&mut self, implicit: bool) {
self.implicit = implicit;
@@ -413,6 +417,7 @@ impl Table {
}
}
+#[cfg(feature = "display")]
impl std::fmt::Display for Table {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
use crate::encode::Encode;
diff --git a/vendor/toml_edit/src/value.rs b/vendor/toml_edit/src/value.rs
index 62eb30c7a..1b397d905 100644
--- a/vendor/toml_edit/src/value.rs
+++ b/vendor/toml_edit/src/value.rs
@@ -4,7 +4,6 @@ use std::str::FromStr;
use toml_datetime::*;
use crate::key::Key;
-use crate::parser;
use crate::repr::{Decor, Formatted};
use crate::{Array, InlineTable, InternalString, RawString};
@@ -190,10 +189,12 @@ impl Value {
/// Sets the prefix and the suffix for value.
/// # Example
/// ```rust
+ /// # #[cfg(feature = "display")] {
/// let mut v = toml_edit::Value::from(42);
/// assert_eq!(&v.to_string(), "42");
/// let d = v.decorated(" ", " ");
/// assert_eq!(&d.to_string(), " 42 ");
+ /// # }
/// ```
pub fn decorated(mut self, prefix: impl Into<RawString>, suffix: impl Into<RawString>) -> Self {
self.decorate(prefix, suffix);
@@ -231,12 +232,13 @@ impl Value {
}
}
+#[cfg(feature = "parse")]
impl FromStr for Value {
type Err = crate::TomlError;
/// Parses a value from a &str
fn from_str(s: &str) -> Result<Self, Self::Err> {
- parser::parse_value(s)
+ crate::parser::parse_value(s)
}
}
@@ -347,6 +349,7 @@ impl<K: Into<Key>, V: Into<Value>> FromIterator<(K, V)> for Value {
}
}
+#[cfg(feature = "display")]
impl std::fmt::Display for Value {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
crate::encode::Encode::encode(self, f, None, ("", ""))
@@ -361,6 +364,8 @@ pub(crate) const DEFAULT_TRAILING_VALUE_DECOR: (&str, &str) = (" ", " ");
pub(crate) const DEFAULT_LEADING_VALUE_DECOR: (&str, &str) = ("", "");
#[cfg(test)]
+#[cfg(feature = "parse")]
+#[cfg(feature = "display")]
mod tests {
use super::*;
diff --git a/vendor/toml_edit/src/visit.rs b/vendor/toml_edit/src/visit.rs
index 1bc640a88..6d7be0b84 100644
--- a/vendor/toml_edit/src/visit.rs
+++ b/vendor/toml_edit/src/visit.rs
@@ -43,6 +43,7 @@
//! This visitor stores every string in the document.
//!
//! ```
+//! # #[cfg(feature = "parse")] {
//! # use toml_edit::*;
//! use toml_edit::visit::*;
//!
@@ -67,10 +68,11 @@
//! visitor.visit_document(&document);
//!
//! assert_eq!(visitor.strings, vec!["sky-castle", "surrounds-you"]);
+//! # }
//! ```
//!
//! For a more complex example where the visitor has internal state, see `examples/visit.rs`
-//! [on GitHub](https://github.com/ordian/toml_edit/blob/master/examples/visit.rs).
+//! [on GitHub](https://github.com/toml-rs/toml/blob/main/crates/toml_edit/examples/visit.rs).
use crate::{
Array, ArrayOfTables, Datetime, Document, Formatted, InlineTable, Item, Table, TableLike, Value,
diff --git a/vendor/toml_edit/src/visit_mut.rs b/vendor/toml_edit/src/visit_mut.rs
index 2c2af9752..c823cfbc9 100644
--- a/vendor/toml_edit/src/visit_mut.rs
+++ b/vendor/toml_edit/src/visit_mut.rs
@@ -45,6 +45,8 @@
//! 2 decimal points.
//!
//! ```
+//! # #[cfg(feature = "parse")] {
+//! # #[cfg(feature = "display")] {
//! # use toml_edit::*;
//! use toml_edit::visit_mut::*;
//!
@@ -80,10 +82,12 @@
//! "#;
//!
//! assert_eq!(format!("{}", document), output);
+//! # }
+//! # }
//! ```
//!
//! For a more complex example where the visitor has internal state, see `examples/visit.rs`
-//! [on GitHub](https://github.com/ordian/toml_edit/blob/master/examples/visit.rs).
+//! [on GitHub](https://github.com/toml-rs/toml/blob/main/crates/toml_edit/examples/visit.rs).
use crate::{
Array, ArrayOfTables, Datetime, Document, Formatted, InlineTable, Item, KeyMut, Table,