diff --git a/src/debuginfo/line_info.rs b/src/debuginfo/line_info.rs index ae3d39183ba..c001d4b082b 100644 --- a/src/debuginfo/line_info.rs +++ b/src/debuginfo/line_info.rs @@ -37,22 +37,17 @@ fn osstr_as_utf8_bytes(path: &OsStr) -> &[u8] { pub(crate) const MD5_LEN: usize = 16; -#[derive(Default, Clone, Copy)] -pub struct FileHash([u8; MD5_LEN]); - -impl FileHash { - pub fn from_source_hash(hash: SourceFileHash) -> Option { - if hash.kind == SourceFileHashAlgorithm::Md5 { - let mut buf = [0u8; MD5_LEN]; - buf.copy_from_slice(hash.hash_bytes()); - Some(Self(buf)) - } else { - None - } - } - - pub fn inner(self) -> [u8; MD5_LEN] { - self.0 +pub fn make_file_info(hash: SourceFileHash) -> Option { + if hash.kind == SourceFileHashAlgorithm::Md5 { + let mut buf = [0u8; MD5_LEN]; + buf.copy_from_slice(hash.hash_bytes()); + Some(FileInfo { + timestamp: 0, + size: 0, + md5: buf, + }) + } else { + None } } @@ -79,14 +74,10 @@ fn line_program_add_file( line_strings, ); - let file_hash = FileHash::from_source_hash(file.src_hash); + let info = make_file_info(file.src_hash); - line_program.file_has_md5 = file_hash.is_some(); - line_program.add_file(file_name, dir_id, Some(FileInfo { - timestamp: 0, - size: 0, - md5: file_hash.unwrap_or_default().inner(), - })) + line_program.file_has_md5 = info.is_some(); + line_program.add_file(file_name, dir_id, info) } // FIXME give more appropriate file names filename => { diff --git a/src/debuginfo/mod.rs b/src/debuginfo/mod.rs index 042beb4de1b..c1d96183ea4 100644 --- a/src/debuginfo/mod.rs +++ b/src/debuginfo/mod.rs @@ -11,7 +11,7 @@ use cranelift_codegen::ValueLocRange; use gimli::write::{ self, Address, AttributeValue, DwarfUnit, Expression, LineProgram, LineString, Location, - LocationList, Range, RangeList, UnitEntryId, Writer, FileInfo, + LocationList, Range, RangeList, UnitEntryId, Writer, }; use gimli::{Encoding, Format, LineEncoding, RunTimeEndian, X86_64}; @@ -59,15 +59,15 @@ impl<'tcx> DebugContext<'tcx> { // Normally this would use option_env!("CFG_VERSION"). let producer = format!("cg_clif (rustc {})", "unknown version"); let comp_dir = tcx.sess.working_dir.0.to_string_lossy().into_owned(); - let (name, file_hash) = match tcx.sess.local_crate_source_file.clone() { + let (name, file_info) = match tcx.sess.local_crate_source_file.clone() { Some(path) => { let name = path.to_string_lossy().into_owned(); - let hash = tcx.sess + let info = tcx.sess .source_map() .get_source_file(&FileName::Real(path)) .map(|f| f.src_hash) - .and_then(line_info::FileHash::from_source_hash); - (name, hash) + .and_then(line_info::make_file_info); + (name, info) }, None => (tcx.crate_name(LOCAL_CRATE).to_string(), None), }; @@ -77,13 +77,9 @@ impl<'tcx> DebugContext<'tcx> { LineEncoding::default(), LineString::new(comp_dir.as_bytes(), encoding, &mut dwarf.line_strings), LineString::new(name.as_bytes(), encoding, &mut dwarf.line_strings), - Some(FileInfo { - timestamp: 0, - size: 0, - md5: file_hash.unwrap_or_default().inner(), - }), + file_info, ); - line_program.file_has_md5 = file_hash.is_some(); + line_program.file_has_md5 = file_info.is_some(); dwarf.unit.line_program = line_program;