aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-04-18 19:49:38 +0100
committerGitHub <[email protected]>2020-04-18 19:49:38 +0100
commit9b16ae5149b7b01c8b2ec4bfb87182c993997b44 (patch)
tree6cae356ed72227e541eeca1756f102565edefb6c
parent6f60e646fc2aa50eb53e9c644f0f92651b04cc5b (diff)
parent21b98d585e0c84b14780166f6607e8f1b8560433 (diff)
Merge #4033
4033: Refactor codegen r=matklad a=Veetaha Co-authored-by: veetaha <[email protected]>
-rw-r--r--xtask/src/codegen.rs12
1 files changed, 6 insertions, 6 deletions
diff --git a/xtask/src/codegen.rs b/xtask/src/codegen.rs
index 678b40133..0e4dcb95a 100644
--- a/xtask/src/codegen.rs
+++ b/xtask/src/codegen.rs
@@ -9,9 +9,9 @@ mod gen_syntax;
9mod gen_parser_tests; 9mod gen_parser_tests;
10mod gen_assists_docs; 10mod gen_assists_docs;
11 11
12use std::{fs, mem, path::Path}; 12use std::{mem, path::Path};
13 13
14use crate::Result; 14use crate::{not_bash::fs2, Result};
15 15
16pub use self::{ 16pub use self::{
17 gen_assists_docs::generate_assists_docs, gen_parser_tests::generate_parser_tests, 17 gen_assists_docs::generate_assists_docs, gen_parser_tests::generate_parser_tests,
@@ -39,7 +39,7 @@ pub enum Mode {
39/// A helper to update file on disk if it has changed. 39/// A helper to update file on disk if it has changed.
40/// With verify = false, 40/// With verify = false,
41fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> { 41fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
42 match fs::read_to_string(path) { 42 match fs2::read_to_string(path) {
43 Ok(ref old_contents) if normalize(old_contents) == normalize(contents) => { 43 Ok(ref old_contents) if normalize(old_contents) == normalize(contents) => {
44 return Ok(()); 44 return Ok(());
45 } 45 }
@@ -49,7 +49,7 @@ fn update(path: &Path, contents: &str, mode: Mode) -> Result<()> {
49 anyhow::bail!("`{}` is not up-to-date", path.display()); 49 anyhow::bail!("`{}` is not up-to-date", path.display());
50 } 50 }
51 eprintln!("updating {}", path.display()); 51 eprintln!("updating {}", path.display());
52 fs::write(path, contents)?; 52 fs2::write(path, contents)?;
53 return Ok(()); 53 return Ok(());
54 54
55 fn normalize(s: &str) -> String { 55 fn normalize(s: &str) -> String {
@@ -65,7 +65,7 @@ fn extract_comment_blocks_with_empty_lines(text: &str) -> Vec<Vec<String>> {
65 do_extract_comment_blocks(text, true) 65 do_extract_comment_blocks(text, true)
66} 66}
67 67
68fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lins: bool) -> Vec<Vec<String>> { 68fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lines: bool) -> Vec<Vec<String>> {
69 let mut res = Vec::new(); 69 let mut res = Vec::new();
70 70
71 let prefix = "// "; 71 let prefix = "// ";
@@ -73,7 +73,7 @@ fn do_extract_comment_blocks(text: &str, allow_blocks_with_empty_lins: bool) ->
73 73
74 let mut block = vec![]; 74 let mut block = vec![];
75 for line in lines { 75 for line in lines {
76 if line == "//" && allow_blocks_with_empty_lins { 76 if line == "//" && allow_blocks_with_empty_lines {
77 block.push(String::new()); 77 block.push(String::new());
78 continue; 78 continue;
79 } 79 }