@@ -1098,28 +1098,43 @@ impl FilePathMapping {
1098
1098
/// The return value is the remapped path and a boolean indicating whether
1099
1099
/// the path was affected by the mapping.
1100
1100
pub fn map_prefix ( & self , path : PathBuf ) -> ( PathBuf , bool ) {
1101
- // NOTE: We are iterating over the mapping entries from last to first
1102
- // because entries specified later on the command line should
1103
- // take precedence.
1104
- for & ( ref from, ref to) in self . mapping . iter ( ) . rev ( ) {
1105
- if let Ok ( rest) = path. strip_prefix ( from) {
1106
- let remapped = if rest. as_os_str ( ) . is_empty ( ) {
1107
- // This is subtle, joining an empty path onto e.g. `foo/bar` will
1108
- // result in `foo/bar/`, that is, there'll be an additional directory
1109
- // separator at the end. This can lead to duplicated directory separators
1110
- // in remapped paths down the line.
1111
- // So, if we have an exact match, we just return that without a call
1112
- // to `Path::join()`.
1113
- to. clone ( )
1114
- } else {
1115
- to. join ( rest)
1116
- } ;
1101
+ if path. as_os_str ( ) . is_empty ( ) {
1102
+ return ( path, false ) ;
1103
+ }
1117
1104
1118
- return ( remapped, true ) ;
1105
+ return remap_path_prefix ( & self . mapping , path) ;
1106
+
1107
+ #[ instrument( level = "debug" , skip( mapping) ) ]
1108
+ fn remap_path_prefix ( mapping : & [ ( PathBuf , PathBuf ) ] , path : PathBuf ) -> ( PathBuf , bool ) {
1109
+ // NOTE: We are iterating over the mapping entries from last to first
1110
+ // because entries specified later on the command line should
1111
+ // take precedence.
1112
+ for & ( ref from, ref to) in mapping. iter ( ) . rev ( ) {
1113
+ debug ! ( "Trying to apply {:?} => {:?}" , from, to) ;
1114
+
1115
+ if let Ok ( rest) = path. strip_prefix ( from) {
1116
+ let remapped = if rest. as_os_str ( ) . is_empty ( ) {
1117
+ // This is subtle, joining an empty path onto e.g. `foo/bar` will
1118
+ // result in `foo/bar/`, that is, there'll be an additional directory
1119
+ // separator at the end. This can lead to duplicated directory separators
1120
+ // in remapped paths down the line.
1121
+ // So, if we have an exact match, we just return that without a call
1122
+ // to `Path::join()`.
1123
+ to. clone ( )
1124
+ } else {
1125
+ to. join ( rest)
1126
+ } ;
1127
+ debug ! ( "Match - remapped {:?} => {:?}" , path, remapped) ;
1128
+
1129
+ return ( remapped, true ) ;
1130
+ } else {
1131
+ debug ! ( "No match - prefix {:?} does not match {:?}" , from, path) ;
1132
+ }
1119
1133
}
1120
- }
1121
1134
1122
- ( path, false )
1135
+ debug ! ( "Path {:?} was not remapped" , path) ;
1136
+ ( path, false )
1137
+ }
1123
1138
}
1124
1139
1125
1140
fn map_filename_prefix ( & self , file : & FileName ) -> ( FileName , bool ) {
0 commit comments