Silence `unused_mut` when only `span` is mutated with `span` feature

This commit is contained in:
YOSHIOKA Takuma 2025-02-21 20:46:12 +09:00
parent c7f60b4c56
commit dc2839f850
No known key found for this signature in database
GPG Key ID: EF2059A2B64518D7
2 changed files with 23 additions and 19 deletions

View File

@ -579,27 +579,30 @@ mod test {
);
let entry: KdlEntry = " \\\n (\"m\\\"eh\")0xDEADbeef\t\\\n".parse()?;
let mut ty: KdlIdentifier = "\"m\\\"eh\"".parse()?;
#[cfg(feature = "span")]
#[cfg_attr(not(feature = "span"), allow(unused_mut))]
{
ty.span = (5..12).into();
}
assert_eq!(
entry,
KdlEntry {
ty: Some(ty),
value: KdlValue::Integer(0xdeadbeef),
name: None,
format: Some(KdlEntryFormat {
leading: " \\\n ".into(),
trailing: "\t\\\n".into(),
value_repr: "0xDEADbeef".into(),
..Default::default()
}),
#[cfg(feature = "span")]
span: SourceSpan::from(0..26),
let mut ty: KdlIdentifier = "\"m\\\"eh\"".parse()?;
#[cfg(feature = "span")]
{
ty.span = (5..12).into();
}
);
assert_eq!(
entry,
KdlEntry {
ty: Some(ty),
value: KdlValue::Integer(0xdeadbeef),
name: None,
format: Some(KdlEntryFormat {
leading: " \\\n ".into(),
trailing: "\t\\\n".into(),
value_repr: "0xDEADbeef".into(),
..Default::default()
}),
#[cfg(feature = "span")]
span: SourceSpan::from(0..26),
}
);
}
let entry: KdlEntry = " \\\n \"foo\"=(\"m\\\"eh\")0xDEADbeef\t\\\n".parse()?;
assert_eq!(

View File

@ -759,6 +759,7 @@ fn node_children(input: &mut Input<'_>) -> PResult<KdlDocument> {
.map(|_| KdlDocument::new())
.or_else(|mut e: ErrMode<KdlParseError>| {
e = match e {
#[cfg_attr(not(feature = "span"), allow(unused_mut))]
ErrMode::Cut(mut pe) => {
#[cfg(feature = "span")]
{