22
33use std:: collections:: BTreeSet ;
44use std:: env;
5- use std:: fs:: { self , File } ;
6- use std:: io:: Write ;
5+ use std:: fs:: { self , write} ;
76use std:: path:: Path ;
87use tidy:: features:: { collect_lang_features, collect_lib_features, Features } ;
8+ use tidy:: t;
99use tidy:: unstable_book:: {
1010 collect_unstable_book_section_file_names, collect_unstable_feature_names, LANG_FEATURES_DIR ,
1111 LIB_FEATURES_DIR , PATH_STR ,
1212} ;
1313
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-
2814fn 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 ) ;
3117}
3218
3319fn 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 ) ;
3622}
3723
3824fn 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
5238 let lang_features_str = set_to_summary_str ( & unstable_lang_features, "language-features" ) ;
5339 let lib_features_str = set_to_summary_str ( & unstable_lib_features, "library-features" ) ;
5440
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 ! (
5743 include_str!( "SUMMARY.md" ) ,
5844 compiler_flags = compiler_flags_str,
5945 language_features = lang_features_str,
6046 library_features = lib_features_str
61- ) ) ) ;
47+ ) ;
48+ t ! ( write( & summary_path, content) , summary_path) ;
6249}
6350
6451fn generate_unstable_book_files ( src : & Path , out : & Path , features : & Features ) {
0 commit comments