Repository: toml-rs/toml (language: rust)

Issue:
Could not compile toml_edit due to recursion limit reached
I am trying to install `cargo-edit`, which fails on trying to compile `toml_edit`.  Building `toml_edit` by itself also fails.  Minimal test case:

```
bram@raggel:~/Code$ cargo new --bin toml_edit_test
     Created binary (application) `toml_edit_test` project
bram@raggel:~/Code$ cd toml_edit_test/
bram@raggel:~/Code/toml_edit_test$ vi Cargo.toml 
bram@raggel:~/Code/toml_edit_test$ cat Cargo.toml 
[package]
name = "toml_edit_test"
version = "0.1.0"
authors = ["..."]

[dependencies]
toml_edit = "*"
bram@raggel:~/Code/toml_edit_test$ cargo build -vv
[...]
   Compiling toml_edit v0.1.2
     Running `rustc --crate-name toml_edit /home/bram/.cargo/registry/src/github.com-1ecc6299db9ec823/toml_edit-0.1.2/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg 'feature="default"' -C metadata=33d17469c5ea603f -C extra-filename=-33d17469c5ea603f --out-dir /home/bram/Code/toml_edit_test/target/debug/deps -L dependency=/home/bram/Code/toml_edit_test/target/debug/deps --extern combine=/home/bram/Code/toml_edit_test/target/debug/deps/libcombine-a3f87f244ed072d4.rlib --extern chrono=/home/bram/Code/toml_edit_test/target/debug/deps/libchrono-9e8cfa828b060d66.rlib --extern linked_hash_map=/home/bram/Code/toml_edit_test/target/debug/deps/liblinked_hash_map-e0125a89193b31b6.rlib --cap-lints warn`
error: reached the recursion limit while instantiating `<parser::datetime::date_time<combine::easy::Stream<combine::stream::state::State<&str, combine::stream::state::SourcePosition>>> as combine::Parser>::parse_mode::<combine::parser::FirstMode>`

error: aborting due to previous error

error: Could not compile `toml_edit`.

Caused by:
  process didn't exit successfully: `rustc --crate-name toml_edit /home/bram/.cargo/registry/src/github.com-1ecc6299db9ec823/toml_edit-0.1.2/src/lib.rs --crate-type lib --emit=dep-info,link -C debuginfo=2 --cfg feature="default" -C metadata=33d17469c5ea603f -C extra-filename=-33d17469c5ea603f --out-dir /home/bram/Code/toml_edit_test/target/debug/deps -L dependency=/home/bram/Code/toml_edit_test/target/debug/deps --extern combine=/home/bram/Code/toml_edit_test/target/debug/deps/libcombine-a3f87f244ed072d4.rlib --extern chrono=/home/bram/Code/toml_edit_test/target/debug/deps/libchrono-9e8cfa828b060d66.rlib --extern linked_hash_map=/home/bram/Code/toml_edit_test/target/debug/deps/liblinked_hash_map-e0125a89193b31b6.rlib --cap-lints warn` (exit code: 101)
bram@raggel:~/Code/toml_edit_test$ rustc -V
rustc 1.27.0 (3eda71b00 2018-06-19)
```

I am using Linux x86_64, on a pretty low-specced netbook (2 cores, 4GB RAM).  I am curious as to why this fails to compile, as I have installed `cargo-edit` (and thus `toml_edit`) on a couple of x86_64 machines using the same `rustc` version over the last couple of days, which all worked fine.  Is `rustc`'s recursion limit dynamic based on the machine's specs?  That's the only thing I can think of why compilation fails on this netbook, and not on other machines.


Discussion / hints:

Fix patch:
diff --git a/.travis.yml b/.travis.yml
index b90bb461..666273d1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -30,23 +30,9 @@ branches:
 matrix:
   allow_failures:
     - rust: nightly
-    - rust: nightly-2017-12-08
 
   include:
-  - rust: "1.26.2"
-
-    before_script:
-    - rustup component add rustfmt-preview --toolchain 1.26.2
-
-    script:
-    - rustfmt -V
-    - cargo fmt -- --write-mode diff
-    - cargo test --all
-
-    after_success:
-    - ./.travis/coverage.sh
-
-  - rust: nightly-2017-12-08
+  - rust: nightly-2018-06-29
     env:
       global:
         - RUSTFLAGS="-C link-dead-code"
@@ -61,10 +47,12 @@ matrix:
           - libiberty-dev
 
     before_script:
-    - bash -c '[ "$(cargo clippy --version 2>/dev/null)" == "0.0.175" ] || cargo install clippy --vers 0.0.175 --force'
+    - bash -c '[ "$(cargo clippy --version 2>/dev/null)" == "0.0.211" ] || cargo install clippy --vers 0.0.211 --force'
+    - cargo install rustfmt-nightly --force
 
     script:
-    - cargo clippy -- -D warnings -Z no-trans
+    - cargo fmt -- --check
+    - cargo clippy -- -D warnings
     - rm -rf target/debug/{test_,toml_edit-}*
     # - RUSTFLAGS="-Z sanitizer=leak" cargo test --verbose --target x86_64-unknown-linux-gnu
 
diff --git a/Cargo.toml b/Cargo.toml
index 7fb850d3..d6a2ee89 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
 [package]
 name = "toml_edit"
-version = "0.1.2"
+version = "0.1.3"
 readme = "README.md"
 license = "MIT/Apache-2.0"
 keywords = ["toml"]
diff --git a/src/decor.rs b/src/decor.rs
index b37a5ffb..a3145393 100644
--- a/src/decor.rs
+++ b/src/decor.rs
@@ -60,9 +60,6 @@ impl<T> Formatted<T> {
     }
 
     pub(crate) fn new(v: T, repr: Repr) -> Self {
-        Self {
-            value: v,
-            repr: repr,
-        }
+        Self { value: v, repr }
     }
 }
diff --git a/src/display.rs b/src/display.rs
index a40a5c68..79fac455 100644
--- a/src/display.rs
+++ b/src/display.rs
@@ -62,7 +62,8 @@ impl Display for InlineTable {
     fn fmt(&self, f: &mut Formatter) -> Result {
         write!(f, "{}{{", self.decor.prefix)?;
         write!(f, "{}", self.preamble)?;
-        for (i, (key, value)) in self.items
+        for (i, (key, value)) in self
+            .items
             .iter()
             .filter(|&(_, kv)| kv.value.is_value())
             .map(|(_, kv)| (&kv.key, kv.value.as_value().unwrap()))
@@ -88,7 +89,7 @@ impl<'a> Display for TableFormatState<'a> {
 
         for kv in table.items.values() {
             if let Item::Value(ref value) = kv.value {
-                write!(f, "{}={}\n", kv.key, value)?;
+                writeln!(f, "{}={}", kv.key, value)?;
             }
         }
 
@@ -100,7 +101,7 @@ impl<'a> Display for TableFormatState<'a> {
                     if !(t.implicit && t.values_len() == 0) {
                         write!(f, "{}[", t.decor.prefix)?;
                         write!(f, "{}", self.path.borrow().join("."))?;
-                        write!(f, "]{}\n", t.decor.suffix)?;
+                        writeln!(f, "]{}", t.decor.suffix)?;
                     }
                     write!(f, "{}", self)?;
                     self.table.set(table);
@@ -112,7 +113,7 @@ impl<'a> Display for TableFormatState<'a> {
                         self.table.set(t);
                         write!(f, "{}[[", t.decor.prefix)?;
                         write!(f, "{}", self.path.borrow().join("."))?;
-                        write!(f, "]]{}\n", t.decor.suffix)?;
+                        writeln!(f, "]]{}", t.decor.suffix)?;
                         write!(f, "{}", self)?;
                     }
                     self.table.set(table);
diff --git a/src/formatted.rs b/src/formatted.rs
index 4194459d..bbcee534 100644
--- a/src/formatted.rs
+++ b/src/formatted.rs
@@ -95,7 +95,7 @@ pub(crate) fn to_key_value(key: &str, mut value: Value) -> TableKeyValue {
 pub(crate) fn to_table_key_value(key: &str, value: Item) -> TableKeyValue {
     TableKeyValue {
         key: key_repr(key),
-        value: value,
+        value,
     }
 }
 
diff --git a/src/index.rs b/src/index.rs
index 702ce3de..d6c7ac6d 100644
--- a/src/index.rs
+++ b/src/index.rs
@@ -46,7 +46,8 @@ impl Index for usize {
             Item::ArrayOfTables(ref mut vec) => {
                 vec.values.get_mut(*self).expect("index out of bounds")
             }
-            Item::Value(ref mut a) if a.is_array() => a.as_array_mut()
+            Item::Value(ref mut a) if a.is_array() => a
+                .as_array_mut()
                 .unwrap()
                 .values
                 .get_mut(*self)
@@ -60,7 +61,8 @@ impl Index for str {
     fn index<'v>(&self, v: &'v Item) -> Option<&'v Item> {
         match *v {
             Item::Table(ref t) => t.get(self),
-            Item::Value(ref v) if v.is_inline_table() => v.as_inline_table()
+            Item::Value(ref v) if v.is_inline_table() => v
+                .as_inline_table()
                 .and_then(|t| t.items.get(self).map(|kv| &kv.value)),
             _ => None,
         }
@@ -75,7 +77,8 @@ impl Index for str {
         match *v {
             Item::Table(ref mut t) => t.entry(self).or_insert(Item::None),
             Item::Value(ref mut v) if v.is_inline_table() => {
-                &mut v.as_inline_table_mut()
+                &mut v
+                    .as_inline_table_mut()
                     .unwrap()
                     .items
                     .entry(self.to_owned())
diff --git a/src/key.rs b/src/key.rs
index 6dfd9e9a..00ce4ccf 100644
--- a/src/key.rs
+++ b/src/key.rs
@@ -62,7 +62,7 @@ impl Key {
     pub(crate) fn new(raw: &str, key: InternalString) -> Self {
         Self {
             raw: raw.into(),
-            key: key,
+            key,
         }
     }
 
diff --git a/src/lib.rs b/src/lib.rs
index e654ac9e..e4065ef4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,5 +1,7 @@
 #![deny(missing_docs)]
 #![deny(warnings)]
+// https://github.com/Marwes/combine/issues/172
+#![recursion_limit = "256"]
 
 //! # `toml_edit`
 //!
diff --git a/src/parser/document.rs b/src/parser/document.rs
index a1024ab6..7769be3b 100644
--- a/src/parser/document.rs
+++ b/src/parser/document.rs
@@ -120,7 +120,7 @@ impl TomlParser {
 
         if table.contains_key(&key) {
             Err(CustomError::DuplicateKey {
-                key: key,
+                key,
                 table: "<unknown>".into(), // TODO: get actual table name
             })
         } else {
diff --git a/src/parser/errors.rs b/src/parser/errors.rs
index 6a8e2101..8e00b101 100644
--- a/src/parser/errors.rs
+++ b/src/parser/errors.rs
@@ -57,10 +57,7 @@ pub(crate) struct FancyError<'a> {
 
 impl<'a> FancyError<'a> {
     pub(crate) fn new(error: ParseError<char, &'a str, SourcePosition>, input: &'a str) -> Self {
-        Self {
-            error: error,
-            input: input,
-        }
+        Self { error, input }
     }
 }
 
@@ -69,7 +66,8 @@ impl<'a> Display for FancyError<'a> {
         let SourcePosition { line, column } = self.error.position;
 
         let offset = line.to_string().len();
-        let content = self.input
+        let content = self
+            .input
             .split('\n')
             .nth((line - 1) as usize)
             .expect("line");
diff --git a/src/parser/mod.rs b/src/parser/mod.rs
index 73fa5b7c..17b17f0e 100644
--- a/src/parser/mod.rs
+++ b/src/parser/mod.rs
@@ -1,4 +1,5 @@
 #![cfg_attr(feature = "cargo-clippy", allow(unneeded_field_pattern))]
+#![cfg_attr(feature = "cargo-clippy", allow(toplevel_ref_arg))]
 
 #[macro_use]
 mod macros;
diff --git a/src/table.rs b/src/table.rs
index e486e2f8..7cd9cf6e 100644
--- a/src/table.rs
+++ b/src/table.rs
@@ -48,10 +48,7 @@ pub struct TableKeyValue {
 
 impl TableKeyValue {
     pub(crate) fn new(key: Repr, value: Item) -> Self {
-        TableKeyValue {
-            key: key,
-            value: value,
-        }
+        TableKeyValue { key, value }
     }
 }
 
@@ -66,7 +63,7 @@ impl Table {
 
     pub(crate) fn with_decor(decor: Decor) -> Self {
         Self {
-            decor: decor,
+            decor,
             ..Default::default()
         }
     }
@@ -146,7 +143,8 @@ impl Table {
     /// and set it to the appropriate value.
     pub fn entry<'a>(&'a mut self, key: &str) -> &'a mut Item {
         let parsed_key = key.parse::<Key>().expect("invalid key");
-        &mut self.items
+        &mut self
+            .items
             .entry(parsed_key.get().to_owned())
             .or_insert(TableKeyValue::new(key_repr(parsed_key.raw()), Item::None))
             .value


Test patch: