2
2
3
3
use std:: collections:: BTreeSet ;
4
4
use std:: env;
5
- use std:: fs:: { self , File } ;
6
- use std:: io:: Write ;
5
+ use std:: fs:: { self , write} ;
7
6
use std:: path:: Path ;
8
7
use tidy:: features:: { collect_lang_features, collect_lib_features, Features } ;
8
+ use tidy:: t;
9
9
use tidy:: unstable_book:: {
10
10
collect_unstable_book_section_file_names, collect_unstable_feature_names, LANG_FEATURES_DIR ,
11
11
LIB_FEATURES_DIR , PATH_STR ,
12
12
} ;
13
13
14
- /// A helper macro to `unwrap` a result except also print out details like:
15
- ///
16
- /// * The file/line of the panic
17
- /// * The expression that failed
18
- /// * The error itself
19
- macro_rules! t {
20
- ( $e: expr) => {
21
- match $e {
22
- Ok ( e) => e,
23
- Err ( e) => panic!( "{} failed with {}" , stringify!( $e) , e) ,
24
- }
25
- } ;
26
- }
27
-
28
14
fn generate_stub_issue ( path : & Path , name : & str , issue : u32 ) {
29
- let mut file = t ! ( File :: create ( path ) ) ;
30
- t ! ( write! ( file , include_str! ( "stub-issue.md" ) , name = name , issue = issue ) ) ;
15
+ let content = format ! ( include_str! ( "stub-issue.md" ) , name = name , issue = issue ) ;
16
+ t ! ( write( path , content ) , path ) ;
31
17
}
32
18
33
19
fn generate_stub_no_issue ( path : & Path , name : & str ) {
34
- let mut file = t ! ( File :: create ( path ) ) ;
35
- t ! ( write! ( file , include_str! ( "stub-no-issue.md" ) , name = name ) ) ;
20
+ let content = format ! ( include_str! ( "stub-no-issue.md" ) , name = name ) ;
21
+ t ! ( write( path , content ) , path ) ;
36
22
}
37
23
38
24
fn set_to_summary_str ( set : & BTreeSet < String > , dir : & str ) -> String {
@@ -52,13 +38,14 @@ fn generate_summary(path: &Path, lang_features: &Features, lib_features: &Featur
52
38
let lang_features_str = set_to_summary_str ( & unstable_lang_features, "language-features" ) ;
53
39
let lib_features_str = set_to_summary_str ( & unstable_lib_features, "library-features" ) ;
54
40
55
- let mut file = t ! ( File :: create ( & path. join( "src/SUMMARY.md" ) ) ) ;
56
- t ! ( file . write_fmt ( format_args !(
41
+ let summary_path = path. join ( "src/SUMMARY.md" ) ;
42
+ let content = format ! (
57
43
include_str!( "SUMMARY.md" ) ,
58
44
compiler_flags = compiler_flags_str,
59
45
language_features = lang_features_str,
60
46
library_features = lib_features_str
61
- ) ) ) ;
47
+ ) ;
48
+ t ! ( write( & summary_path, content) , summary_path) ;
62
49
}
63
50
64
51
fn generate_unstable_book_files ( src : & Path , out : & Path , features : & Features ) {
0 commit comments