@@ -223,10 +223,17 @@ fn generate_enum(
223
223
} ) ;
224
224
225
225
let grammar_doc = & doc_comment. grammar_doc ;
226
- let mut result = quote ! {
227
- #[ doc = #grammar_doc]
228
- #[ allow( dead_code, non_camel_case_types, clippy:: upper_case_acronyms) ]
229
- #[ derive( Clone , Copy , Debug , Eq , Hash , Ord , PartialEq , PartialOrd ) ]
226
+ let mut result = if grammar_doc. is_empty ( ) {
227
+ quote ! {
228
+ #[ allow( dead_code, non_camel_case_types, clippy:: upper_case_acronyms) ]
229
+ #[ derive( Clone , Copy , Debug , Eq , Hash , Ord , PartialEq , PartialOrd ) ]
230
+ }
231
+ } else {
232
+ quote ! {
233
+ #[ doc = #grammar_doc]
234
+ #[ allow( dead_code, non_camel_case_types, clippy:: upper_case_acronyms) ]
235
+ #[ derive( Clone , Copy , Debug , Eq , Hash , Ord , PartialEq , PartialOrd ) ]
236
+ }
230
237
} ;
231
238
if non_exhaustive {
232
239
result. append_all ( quote ! {
@@ -865,6 +872,41 @@ mod tests {
865
872
) ;
866
873
}
867
874
875
+ #[ test]
876
+ fn rule_empty_doc ( ) {
877
+ let rules = vec ! [ OptimizedRule {
878
+ name: "f" . to_owned( ) ,
879
+ ty: RuleType :: Normal ,
880
+ expr: OptimizedExpr :: Ident ( "g" . to_owned( ) ) ,
881
+ } ] ;
882
+
883
+ let mut line_docs = HashMap :: new ( ) ;
884
+ line_docs. insert ( "f" . to_owned ( ) , "This is rule comment" . to_owned ( ) ) ;
885
+
886
+ let doc_comment = & DocComment {
887
+ grammar_doc : "" . to_owned ( ) ,
888
+ line_docs,
889
+ } ;
890
+
891
+ assert_eq ! (
892
+ generate_enum( & rules, doc_comment, false , false ) . to_string( ) ,
893
+ quote! {
894
+ #[ allow( dead_code, non_camel_case_types, clippy:: upper_case_acronyms) ]
895
+ #[ derive( Clone , Copy , Debug , Eq , Hash , Ord , PartialEq , PartialOrd ) ]
896
+ pub enum Rule {
897
+ #[ doc = "This is rule comment" ]
898
+ r#f
899
+ }
900
+ impl Rule {
901
+ pub fn all_rules( ) -> & ' static [ Rule ] {
902
+ & [ Rule :: r#f]
903
+ }
904
+ }
905
+ }
906
+ . to_string( )
907
+ ) ;
908
+ }
909
+
868
910
#[ test]
869
911
fn sequence ( ) {
870
912
let expr = OptimizedExpr :: Seq (
0 commit comments