Allow empty lines in annotations (#7394)

This commit is contained in:
Diego Imbert
2025-12-16 19:07:19 +02:00
committed by GitHub
parent 7a05601b11
commit f2cf116359
2 changed files with 19 additions and 7 deletions
+3 -1
View File
@@ -51,13 +51,15 @@ pub fn annotations(attr: TokenStream, item: TokenStream) -> TokenStream {
let mut lines = code.lines();
while let Some(line) = lines.next() {
if line.trim().is_empty() {
continue;
}
if !line.starts_with(#comm_lit) {
break;
}
let line = line[#comm_lit.len()..].trim();
let (key, value) = line.split_once('=').unwrap_or((line, ""));
match key {
#(
stringify!(#custom_field_names) => {
+16 -6
View File
@@ -102,12 +102,12 @@ mod annotations_tests {
#[test]
fn spacing_integration() {
// First line is ignored and not used
// First line is ignored
{
let cont = "
# ann2";
let expected = Annotations { ..Default::default() };
assert_eq!(expected, old(cont));
let expected = Annotations { ann2: true, ..Default::default() };
// assert_eq!(expected, old(cont));
assert_eq!(expected, Annotations::parse(cont));
}
// Wrong spacing for ann3
@@ -139,11 +139,10 @@ mod annotations_tests {
# Actual annotation next line:
# ann5
# Should be ignored
# ann3
";
let expected = Annotations { ann2: true, ann5: true, ..Default::default() };
assert_eq!(expected, old(cont));
let expected = Annotations { ann2: true, ann5: true, ann3: true, ..Default::default() };
// assert_eq!(expected, old(cont));
assert_eq!(expected, Annotations::parse(cont));
}
@@ -168,6 +167,17 @@ mod annotations_tests {
}
}
#[test]
fn newline_between() {
let cont = "// ann1
// ann2";
assert_eq!(
SlashedAnnotations { ann1: true, ann2: true, ann3: false, ann4: false },
SlashedAnnotations::parse(cont)
);
}
// // #[derive(serde_derive::Serialize, serde_derive::Deserialize, Eq, PartialEq)]
// // #[annotations("#")]
// // pub struct SerAnnotations {