Skip to content

Commit a5fd83a

Browse files
authored
Rollup merge of #101102 - est31:unstable_book_gen_write, r=Mark-Simulacrum
unstable-book-gen: use std::fs::write I wrote this code in 2017 back when std::fs::write wasn't available. Also, use the t macro from tidy.
2 parents 58ed74c + 4a82c21 commit a5fd83a

File tree

1 file changed

+10
-23
lines changed
  • src/tools/unstable-book-gen/src

1 file changed

+10
-23
lines changed

src/tools/unstable-book-gen/src/main.rs

+10-23
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,23 @@
22
33
use std::collections::BTreeSet;
44
use std::env;
5-
use std::fs::{self, File};
6-
use std::io::Write;
5+
use std::fs::{self, write};
76
use std::path::Path;
87
use tidy::features::{collect_lang_features, collect_lib_features, Features};
8+
use tidy::t;
99
use 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-
2814
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);
3117
}
3218

3319
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);
3622
}
3723

3824
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
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

6451
fn generate_unstable_book_files(src: &Path, out: &Path, features: &Features) {

0 commit comments

Comments
 (0)