File tree Expand file tree Collapse file tree 2 files changed +11
-19
lines changed Expand file tree Collapse file tree 2 files changed +11
-19
lines changed Original file line number Diff line number Diff line change 11use std:: ffi:: OsStr ;
2- use std:: convert:: TryFrom ;
32use std:: path:: { Component , Path } ;
43
54use crate :: prelude:: * ;
@@ -42,25 +41,19 @@ pub(crate) const MD5_LEN: usize = 16;
4241pub struct FileHash ( [ u8 ; MD5_LEN ] ) ;
4342
4443impl 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
6659fn 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 ,
Original file line number Diff line number Diff line change 11mod emit;
22mod line_info;
33
4- use std:: convert:: TryFrom ;
5-
64use crate :: prelude:: * ;
75
86use 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 ) ,
You can’t perform that action at this time.
0 commit comments