Skip to content

Commit c904e02

Browse files
authored
fix(span): Enable span properly to fix build failure with span feature disabled (#120)
1 parent 6e61b54 commit c904e02

File tree

2 files changed

+38
-22
lines changed

2 files changed

+38
-22
lines changed

src/entry.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -579,24 +579,30 @@ mod test {
579579
);
580580

581581
let entry: KdlEntry = " \\\n (\"m\\\"eh\")0xDEADbeef\t\\\n".parse()?;
582-
let mut ty: KdlIdentifier = "\"m\\\"eh\"".parse()?;
583-
ty.span = (5..12).into();
584-
assert_eq!(
585-
entry,
586-
KdlEntry {
587-
ty: Some(ty),
588-
value: KdlValue::Integer(0xdeadbeef),
589-
name: None,
590-
format: Some(KdlEntryFormat {
591-
leading: " \\\n ".into(),
592-
trailing: "\t\\\n".into(),
593-
value_repr: "0xDEADbeef".into(),
594-
..Default::default()
595-
}),
596-
#[cfg(feature = "span")]
597-
span: SourceSpan::from(0..26),
582+
#[cfg_attr(not(feature = "span"), allow(unused_mut))]
583+
{
584+
let mut ty: KdlIdentifier = "\"m\\\"eh\"".parse()?;
585+
#[cfg(feature = "span")]
586+
{
587+
ty.span = (5..12).into();
598588
}
599-
);
589+
assert_eq!(
590+
entry,
591+
KdlEntry {
592+
ty: Some(ty),
593+
value: KdlValue::Integer(0xdeadbeef),
594+
name: None,
595+
format: Some(KdlEntryFormat {
596+
leading: " \\\n ".into(),
597+
trailing: "\t\\\n".into(),
598+
value_repr: "0xDEADbeef".into(),
599+
..Default::default()
600+
}),
601+
#[cfg(feature = "span")]
602+
span: SourceSpan::from(0..26),
603+
}
604+
);
605+
}
600606

601607
let entry: KdlEntry = " \\\n \"foo\"=(\"m\\\"eh\")0xDEADbeef\t\\\n".parse()?;
602608
assert_eq!(

src/v2_parser.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,11 +439,13 @@ fn test_node() {
439439
name: KdlIdentifier {
440440
value: "foo".into(),
441441
repr: Some("foo".into()),
442+
#[cfg(feature = "span")]
442443
span: (0..3).into()
443444
},
444445
entries: vec![],
445446
children: None,
446447
format: Some(Default::default()),
448+
#[cfg(feature = "span")]
447449
span: (0..7).into()
448450
}
449451
);
@@ -455,6 +457,7 @@ fn test_node() {
455457
name: KdlIdentifier {
456458
value: "foo".into(),
457459
repr: Some("foo".into()),
460+
#[cfg(feature = "span")]
458461
span: (0..3).into()
459462
},
460463
entries: vec![KdlEntry {
@@ -466,12 +469,14 @@ fn test_node() {
466469
leading: " ".into(),
467470
..Default::default()
468471
}),
472+
#[cfg(feature = "span")]
469473
span: SourceSpan::new(3.into(), 4)
470474
}],
471475
children: None,
472476
format: Some(KdlNodeFormat {
473477
..Default::default()
474478
}),
479+
#[cfg(feature = "span")]
475480
span: (0..8).into()
476481
}
477482
);
@@ -552,7 +557,6 @@ fn node_entry(input: &mut Input<'_>) -> PResult<Option<KdlEntry>> {
552557
fmt.after_key = after_key.into();
553558
fmt.after_eq = after_eq.into();
554559
}
555-
#[cfg(feature = "span")]
556560
value
557561
})
558562
} else if let Some(ident) = maybe_ident {
@@ -607,6 +611,7 @@ fn entry_test() {
607611
value_repr: "bar".into(),
608612
..Default::default()
609613
}),
614+
#[cfg(feature = "span")]
610615
span: (0..7).into()
611616
})
612617
);
@@ -621,6 +626,7 @@ fn entry_test() {
621626
value_repr: "foo".into(),
622627
..Default::default()
623628
}),
629+
#[cfg(feature = "span")]
624630
span: (0..3).into()
625631
})
626632
);
@@ -636,6 +642,7 @@ fn entry_test() {
636642
leading: "/-foo ".into(),
637643
..Default::default()
638644
}),
645+
#[cfg(feature = "span")]
639646
span: (6..9).into()
640647
})
641648
);
@@ -648,6 +655,7 @@ fn entry_test() {
648655
name: Some(KdlIdentifier {
649656
value: "bar".into(),
650657
repr: Some("bar".into()),
658+
#[cfg(feature = "span")]
651659
span: (9..12).into(),
652660
}),
653661
format: Some(KdlEntryFormat {
@@ -657,6 +665,7 @@ fn entry_test() {
657665
after_eq: " ".into(),
658666
..Default::default()
659667
}),
668+
#[cfg(feature = "span")]
660669
span: (9..16).into()
661670
})
662671
);
@@ -669,6 +678,7 @@ fn entry_test() {
669678
name: Some(KdlIdentifier {
670679
value: "bar".into(),
671680
repr: Some("bar".into()),
681+
#[cfg(feature = "span")]
672682
span: (12..16).into(),
673683
}),
674684
format: Some(KdlEntryFormat {
@@ -678,6 +688,7 @@ fn entry_test() {
678688
after_eq: " ".into(),
679689
..Default::default()
680690
}),
691+
#[cfg(feature = "span")]
681692
span: (12..18).into()
682693
})
683694
);
@@ -749,10 +760,7 @@ fn node_children(input: &mut Input<'_>) -> PResult<KdlDocument> {
749760
.or_else(|mut e: ErrMode<KdlParseError>| {
750761
e = match e {
751762
ErrMode::Cut(mut pe) => {
752-
#[cfg(feature = "span")]
753-
{
754-
pe.span = Some((_before_open_loc.._after_open_loc).into());
755-
}
763+
pe.span = Some((_before_open_loc.._after_open_loc).into());
756764
ErrMode::Cut(pe)
757765
}
758766
e => return Err(e),
@@ -1508,6 +1516,7 @@ mod string_tests {
15081516
KdlIdentifier {
15091517
value: "foo".into(),
15101518
repr: Some("foo".into()),
1519+
#[cfg(feature = "span")]
15111520
span: (0..3).into()
15121521
}
15131522
);
@@ -1516,6 +1525,7 @@ mod string_tests {
15161525
KdlIdentifier {
15171526
value: "+.".into(),
15181527
repr: Some("+.".into()),
1528+
#[cfg(feature = "span")]
15191529
span: (0..1).into()
15201530
}
15211531
)

0 commit comments

Comments
 (0)