diff --git a/compiler/rustc_interface/src/passes.rs b/compiler/rustc_interface/src/passes.rs index b9b65755db5..cd5624e38bd 100644 --- a/compiler/rustc_interface/src/passes.rs +++ b/compiler/rustc_interface/src/passes.rs @@ -536,7 +536,7 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P let write_deps_to_file = |file: &mut dyn Write| -> io::Result<()> { for path in out_filenames { - writeln!( + write!( file, "{}: {}\n", path.display(), @@ -546,6 +546,25 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P .intersperse(" ") .collect::() )?; + + // If caller requested this information, add special comments about source file checksums. + // These are not necessarily the same checksums as was used in the debug files. + if sess.opts.unstable_opts.checksum_hash_algorithm().is_some() { + assert!( + files.iter().all(|(_path, _file_len, hash_algo)| hash_algo.is_some()), + "all files must have a checksum hash computed to output checksum hashes" + ); + write!(file, " # ")?; + files + .iter() + .filter_map(|(_path, file_len, hash_algo)| { + hash_algo.map(|hash_algo| (path, file_len, hash_algo)) + }) + .try_for_each(|(_path, file_len, checksum_hash)| { + write!(file, "checksum:{checksum_hash} file_len:{file_len}, ") + })?; + } + writeln!(file)?; } // Emit a fake target for each input file to the compilation. This @@ -575,18 +594,6 @@ fn write_out_deps(tcx: TyCtxt<'_>, outputs: &OutputFilenames, out_filenames: &[P } } - // If caller requested this information, add special comments about source file checksums. - // These are not necessarily the same checksums as was used in the debug files. - if sess.opts.unstable_opts.checksum_hash_algorithm().is_some() { - for (path, file_len, checksum_hash) in - files.iter().filter_map(|(path, file_len, hash_algo)| { - hash_algo.map(|hash_algo| (path, file_len, hash_algo)) - }) - { - writeln!(file, "# checksum:{checksum_hash} file_len:{file_len} {path}")?; - } - } - Ok(()) };