@@ -16,7 +16,7 @@ pub fn expand_manifest(
16
16
config : & Config ,
17
17
) -> CargoResult < String > {
18
18
let comment = match extract_comment ( content) {
19
- Ok ( comment) => Some ( comment) ,
19
+ Ok ( comment) => comment,
20
20
Err ( err) => {
21
21
tracing:: trace!( "failed to extract doc comment: {err}" ) ;
22
22
None
@@ -160,7 +160,7 @@ fn sanitize_name(name: &str) -> String {
160
160
}
161
161
162
162
/// Locates a "code block manifest" in Rust source.
163
- fn extract_comment ( input : & str ) -> CargoResult < String > {
163
+ fn extract_comment ( input : & str ) -> CargoResult < Option < String > > {
164
164
let mut doc_fragments = Vec :: new ( ) ;
165
165
let file = syn:: parse_file ( input) ?;
166
166
// HACK: `syn` doesn't tell us what kind of comment was used, so infer it from how many
@@ -181,7 +181,7 @@ fn extract_comment(input: &str) -> CargoResult<String> {
181
181
}
182
182
}
183
183
if doc_fragments. is_empty ( ) {
184
- anyhow :: bail! ( "no doc-comment found" ) ;
184
+ return Ok ( None ) ;
185
185
}
186
186
unindent_doc_fragments ( & mut doc_fragments) ;
187
187
@@ -190,7 +190,7 @@ fn extract_comment(input: &str) -> CargoResult<String> {
190
190
add_doc_fragment ( & mut doc_comment, frag) ;
191
191
}
192
192
193
- Ok ( doc_comment)
193
+ Ok ( Some ( doc_comment) )
194
194
}
195
195
196
196
/// A `#[doc]`
@@ -561,38 +561,38 @@ mod test_comment {
561
561
562
562
macro_rules! ec {
563
563
( $s: expr) => {
564
- extract_comment( $s) . unwrap_or_else( |err| panic!( "{}" , err) )
564
+ extract_comment( $s)
565
+ . unwrap_or_else( |err| panic!( "{}" , err) )
566
+ . unwrap( )
565
567
} ;
566
568
}
567
569
568
570
#[ test]
569
571
fn test_no_comment ( ) {
570
- snapbox :: assert_eq (
571
- "no doc-comment found" ,
572
+ assert_eq ! (
573
+ None ,
572
574
extract_comment(
573
575
r#"
574
576
fn main () {
575
577
}
576
578
"# ,
577
579
)
578
- . unwrap_err ( )
579
- . to_string ( ) ,
580
+ . unwrap( )
580
581
) ;
581
582
}
582
583
583
584
#[ test]
584
585
fn test_no_comment_she_bang ( ) {
585
- snapbox :: assert_eq (
586
- "no doc-comment found" ,
586
+ assert_eq ! (
587
+ None ,
587
588
extract_comment(
588
589
r#"#!/usr/bin/env cargo-eval
589
590
590
591
fn main () {
591
592
}
592
593
"# ,
593
594
)
594
- . unwrap_err ( )
595
- . to_string ( ) ,
595
+ . unwrap( )
596
596
) ;
597
597
}
598
598
0 commit comments