Skip to content

Commit 0e837e3

Browse files
committed
Simplify FileHash ctor
1 parent 710da05 commit 0e837e3

File tree

2 files changed

+11
-19
lines changed

2 files changed

+11
-19
lines changed

src/debuginfo/line_info.rs

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::ffi::OsStr;
2-
use std::convert::TryFrom;
32
use std::path::{Component, Path};
43

54
use crate::prelude::*;
@@ -42,25 +41,19 @@ pub(crate) const MD5_LEN: usize = 16;
4241
pub struct FileHash([u8; MD5_LEN]);
4342

4443
impl FileHash {
45-
pub fn inner(self) -> [u8; MD5_LEN] {
46-
self.0
47-
}
48-
}
49-
50-
pub struct UnsupportedHashType;
51-
52-
impl TryFrom<SourceFileHash> for FileHash {
53-
type Error = UnsupportedHashType;
54-
55-
fn try_from(hash: SourceFileHash) -> Result<Self, Self::Error> {
44+
pub fn from_source_hash(hash: SourceFileHash) -> Option<Self> {
5645
if hash.kind == SourceFileHashAlgorithm::Md5 {
5746
let mut buf = [0u8; MD5_LEN];
5847
buf.copy_from_slice(hash.hash_bytes());
59-
Ok(Self(buf))
48+
Some(Self(buf))
6049
} else {
61-
Err(UnsupportedHashType)
50+
None
6251
}
6352
}
53+
54+
pub fn inner(self) -> [u8; MD5_LEN] {
55+
self.0
56+
}
6457
}
6558

6659
fn line_program_add_file(
@@ -86,9 +79,9 @@ fn line_program_add_file(
8679
line_strings,
8780
);
8881

89-
let file_hash = FileHash::try_from(file.src_hash);
82+
let file_hash = FileHash::from_source_hash(file.src_hash);
9083

91-
line_program.file_has_md5 = file_hash.is_ok();
84+
line_program.file_has_md5 = file_hash.is_some();
9285
line_program.add_file(file_name, dir_id, Some(FileInfo {
9386
timestamp: 0,
9487
size: 0,

src/debuginfo/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
mod emit;
22
mod line_info;
33

4-
use std::convert::TryFrom;
5-
64
use crate::prelude::*;
75

86
use rustc_span::FileName;
@@ -67,7 +65,8 @@ impl<'tcx> DebugContext<'tcx> {
6765
let hash = tcx.sess
6866
.source_map()
6967
.get_source_file(&FileName::Real(path))
70-
.and_then(|f| line_info::FileHash::try_from(f.src_hash).ok());
68+
.map(|f| f.src_hash)
69+
.and_then(line_info::FileHash::from_source_hash);
7170
(name, hash)
7271
},
7372
None => (tcx.crate_name(LOCAL_CRATE).to_string(), None),

0 commit comments

Comments
 (0)