Skip to content

Commit a586cae

Browse files
committed
Revert "fix(toml): Track dotted key for spans"
This reverts commit 87461d8. For duplicate key errors, it was somewhat justifiable. When looking at errors in practice, it is not: ``` [ERROR] invalid character `.` in profile name: `.release-lto`, allowed characters are letters, numbers, underscore, a nd hyphen - --> Cargo.toml:8:26 + --> Cargo.toml:8:18 | 8 | [profile.'.release-lto'] - | ^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^^^^^^^ ```
1 parent d35c3f6 commit a586cae

27 files changed

+66
-65
lines changed

crates/toml/src/de/parser/key.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,12 @@ fn more_key(input: &Input<'_>) -> bool {
8686

8787
struct State {
8888
current_key: Option<toml_parser::parser::Event>,
89-
start: usize,
9089
}
9190

9291
impl State {
9392
fn new(key_event: &toml_parser::parser::Event) -> Self {
9493
Self {
9594
current_key: Some(*key_event),
96-
start: key_event.span().start(),
9795
}
9896
}
9997

@@ -110,9 +108,8 @@ impl State {
110108
return;
111109
};
112110

113-
let key_start = self.start;
114-
let key_end = key.span().end();
115-
let key_span = key_start..key_end;
111+
let key_span = key.span();
112+
let key_span = key_span.start()..key_span.end();
116113

117114
let raw = source.get(key).unwrap();
118115
let mut decoded = alloc::borrow::Cow::Borrowed("");

crates/toml/tests/serde/spanned.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,10 @@ fn test_spanned_nested() {
381381
}
382382

383383
fn good(s: &str, foo: &Foo) {
384-
for v in foo.foo.values() {
385-
for n_v in v.values() {
384+
for (k, v) in foo.foo.iter() {
385+
assert_eq!(&s[k.span().start..k.span().end], k.as_ref());
386+
for (n_k, n_v) in v.iter() {
387+
assert_eq!(&s[n_k.span().start..n_k.span().end], n_k.as_ref());
386388
assert_eq!(
387389
&s[(n_v.span().start + 1)..(n_v.span().end - 1)],
388390
n_v.as_ref()
@@ -406,7 +408,7 @@ fn test_spanned_nested() {
406408
Foo {
407409
foo: {
408410
Spanned {
409-
span: 10..15,
411+
span: 14..15,
410412
value: "a",
411413
}: {
412414
Spanned {
@@ -432,7 +434,7 @@ Foo {
432434
},
433435
},
434436
Spanned {
435-
span: 74..81,
437+
span: 78..81,
436438
value: "bar",
437439
}: {
438440
Spanned {
@@ -688,7 +690,7 @@ Map(
688690
[
689691
(
690692
Spanned {
691-
span: 2..9,
693+
span: 6..9,
692694
value: "bar",
693695
},
694696
Spanned {
@@ -706,7 +708,7 @@ Map(
706708
[
707709
(
708710
Spanned {
709-
span: 11..20,
711+
span: 17..20,
710712
value: "bob",
711713
},
712714
Spanned {
@@ -724,7 +726,7 @@ Map(
724726
[
725727
(
726728
Spanned {
727-
span: 25..32,
729+
span: 29..32,
728730
value: "two",
729731
},
730732
Spanned {
@@ -764,19 +766,19 @@ Map(
764766
assert_data_eq!(&INPUT[foo.0.span()], str!["foo"]);
765767
assert_data_eq!(&INPUT[foo.1.span()], str!["foo"]);
766768
let bar = foo.1.get_ref().get("bar").unwrap();
767-
assert_data_eq!(&INPUT[bar.0.span()], str!["foo.bar"]);
769+
assert_data_eq!(&INPUT[bar.0.span()], str!["bar"]);
768770
assert_data_eq!(&INPUT[bar.1.span()], str!["[foo.bar]"]);
769771
let alice = bar.1.get_ref().get("alice").unwrap();
770772
assert_data_eq!(&INPUT[alice.0.span()], str!["alice"]);
771773
assert_data_eq!(&INPUT[alice.1.span()], str!["alice"]);
772774
let bob = alice.1.get_ref().get("bob").unwrap();
773-
assert_data_eq!(&INPUT[bob.0.span()], str!["alice.bob"]);
775+
assert_data_eq!(&INPUT[bob.0.span()], str!["bob"]);
774776
assert_data_eq!(&INPUT[bob.1.span()], str![[r#"{ one.two = "qux" }"#]]);
775777
let one = bob.1.get_ref().get("one").unwrap();
776778
assert_data_eq!(&INPUT[one.0.span()], str!["one"]);
777779
assert_data_eq!(&INPUT[one.1.span()], str!["one"]);
778780
let two = one.1.get_ref().get("two").unwrap();
779-
assert_data_eq!(&INPUT[two.0.span()], str!["one.two"]);
781+
assert_data_eq!(&INPUT[two.0.span()], str!["two"]);
780782
assert_data_eq!(&INPUT[two.1.span()], str![[r#""qux""#]]);
781783
}
782784

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
TOML parse error at line 3, column 1
1+
TOML parse error at line 3, column 5
22
|
33
3 | arr.val1=1
4-
| ^^^^^^^^
4+
| ^^^^
55
duplicate key
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
TOML parse error at line 9, column 4
1+
TOML parse error at line 9, column 10
22
|
33
9 | [fruit.variety]
4-
| ^^^^^^^^^^^^^
4+
| ^^^^^^^
55
duplicate key
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
TOML parse error at line 2, column 1
1+
TOML parse error at line 2, column 3
22
|
33
2 | a.b = 2
4-
| ^^^
4+
| ^
55
duplicate key
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
TOML parse error at line 5, column 2
1+
TOML parse error at line 5, column 4
22
|
33
5 | [_.s]
4-
| ^^^
4+
| ^
55
duplicate key
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
TOML parse error at line 4, column 2
1+
TOML parse error at line 4, column 4
22
|
33
4 | [_.s]
4-
| ^^^
4+
| ^
55
duplicate key

crates/toml/tests/snapshots/invalid/ext/table/duplicate-key-1.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
TOML parse error at line 3, column 2
1+
TOML parse error at line 3, column 4
22
|
33
3 | [a.b]
4-
| ^^^
4+
| ^
55
duplicate key
66

77
---
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
TOML parse error at line 1, column 29
1+
TOML parse error at line 1, column 36
22
|
33
1 | table1 = { table2.dupe = 1, table2.dupe = 2 }
4-
| ^^^^^^^^^^^
4+
| ^^^^
55
duplicate key
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
TOML parse error at line 1, column 22
1+
TOML parse error at line 1, column 24
22
|
33
1 | tbl = { a.b = "a_b", a.b.c = "a_b_c" }
4-
| ^^^
4+
| ^
55
cannot extend value of type string with a dotted key

0 commit comments

Comments
 (0)