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 1
1
use std:: ffi:: OsStr ;
2
- use std:: convert:: TryFrom ;
3
2
use std:: path:: { Component , Path } ;
4
3
5
4
use crate :: prelude:: * ;
@@ -42,25 +41,19 @@ pub(crate) const MD5_LEN: usize = 16;
42
41
pub struct FileHash ( [ u8 ; MD5_LEN ] ) ;
43
42
44
43
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 > {
56
45
if hash. kind == SourceFileHashAlgorithm :: Md5 {
57
46
let mut buf = [ 0u8 ; MD5_LEN ] ;
58
47
buf. copy_from_slice ( hash. hash_bytes ( ) ) ;
59
- Ok ( Self ( buf) )
48
+ Some ( Self ( buf) )
60
49
} else {
61
- Err ( UnsupportedHashType )
50
+ None
62
51
}
63
52
}
53
+
54
+ pub fn inner ( self ) -> [ u8 ; MD5_LEN ] {
55
+ self . 0
56
+ }
64
57
}
65
58
66
59
fn line_program_add_file (
@@ -86,9 +79,9 @@ fn line_program_add_file(
86
79
line_strings,
87
80
) ;
88
81
89
- let file_hash = FileHash :: try_from ( file. src_hash ) ;
82
+ let file_hash = FileHash :: from_source_hash ( file. src_hash ) ;
90
83
91
- line_program. file_has_md5 = file_hash. is_ok ( ) ;
84
+ line_program. file_has_md5 = file_hash. is_some ( ) ;
92
85
line_program. add_file ( file_name, dir_id, Some ( FileInfo {
93
86
timestamp : 0 ,
94
87
size : 0 ,
Original file line number Diff line number Diff line change 1
1
mod emit;
2
2
mod line_info;
3
3
4
- use std:: convert:: TryFrom ;
5
-
6
4
use crate :: prelude:: * ;
7
5
8
6
use rustc_span:: FileName ;
@@ -67,7 +65,8 @@ impl<'tcx> DebugContext<'tcx> {
67
65
let hash = tcx. sess
68
66
. source_map ( )
69
67
. 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) ;
71
70
( name, hash)
72
71
} ,
73
72
None => ( tcx. crate_name ( LOCAL_CRATE ) . to_string ( ) , None ) ,
You can’t perform that action at this time.
0 commit comments