Skip to content

Commit b82d1d3

Browse files
committed
Inline create_dump_file_with_basename
1 parent 098d4fd commit b82d1d3

File tree

1 file changed

+13
-22
lines changed

1 file changed

+13
-22
lines changed

compiler/rustc_middle/src/mir/pretty.rs

+13-22
Original file line numberDiff line numberDiff line change
@@ -205,26 +205,6 @@ fn dump_path(tcx: TyCtxt<'_>, basename: &str, extension: &str) -> PathBuf {
205205
file_path
206206
}
207207

208-
/// Attempts to open the MIR dump file with the given name and extension.
209-
fn create_dump_file_with_basename(
210-
tcx: TyCtxt<'_>,
211-
file_basename: &str,
212-
extension: &str,
213-
) -> io::Result<io::BufWriter<fs::File>> {
214-
let file_path = dump_path(tcx, file_basename, extension);
215-
if let Some(parent) = file_path.parent() {
216-
fs::create_dir_all(parent).map_err(|e| {
217-
io::Error::new(
218-
e.kind(),
219-
format!("IO error creating MIR dump directory: {parent:?}; {e}"),
220-
)
221-
})?;
222-
}
223-
Ok(io::BufWriter::new(fs::File::create(&file_path).map_err(|e| {
224-
io::Error::new(e.kind(), format!("IO error creating MIR dump file: {file_path:?}; {e}"))
225-
})?))
226-
}
227-
228208
/// Attempts to open a file where we should dump a given MIR or other
229209
/// bit of MIR-related data. Used by `mir-dump`, but also by other
230210
/// bits of code (e.g., NLL inference) that dump graphviz data or
@@ -237,11 +217,22 @@ pub fn create_dump_file<'tcx>(
237217
disambiguator: &dyn Display,
238218
body: &Body<'tcx>,
239219
) -> io::Result<io::BufWriter<fs::File>> {
240-
create_dump_file_with_basename(
220+
let file_path = dump_path(
241221
tcx,
242222
&dump_file_basename(tcx, pass_num, pass_name, disambiguator, body),
243223
extension,
244-
)
224+
);
225+
if let Some(parent) = file_path.parent() {
226+
fs::create_dir_all(parent).map_err(|e| {
227+
io::Error::new(
228+
e.kind(),
229+
format!("IO error creating MIR dump directory: {parent:?}; {e}"),
230+
)
231+
})?;
232+
}
233+
Ok(io::BufWriter::new(fs::File::create(&file_path).map_err(|e| {
234+
io::Error::new(e.kind(), format!("IO error creating MIR dump file: {file_path:?}; {e}"))
235+
})?))
245236
}
246237

247238
///////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)