@@ -69,7 +69,7 @@ pub fn canonicalize(
69
69
let mut seen_links = 0 ;
70
70
let mut queue = VecDeque :: new ( ) ;
71
71
72
- queue. push_back ( path) ;
72
+ queue. push_back ( path. to_path_buf ( ) ) ;
73
73
74
74
while let Some ( cur_path) = queue. pop_front ( ) {
75
75
let mut components = cur_path. components ( ) ;
@@ -87,11 +87,9 @@ pub fn canonicalize(
87
87
ret. push ( c) ;
88
88
89
89
// First, check the cache for the path up to this point.
90
- let link: & Path = if let Some ( cached) = cache. get ( & ret) {
90
+ let link = if let Some ( cached) = cache. get ( & ret) {
91
91
if let Some ( link) = & * cached {
92
- // SAFETY: Keys are never removed from the cache or mutated
93
- // and PathBuf has a stable address for path data even when moved.
94
- unsafe { & * ( link. as_path ( ) as * const _ ) }
92
+ link. clone ( )
95
93
} else {
96
94
continue ;
97
95
}
@@ -103,9 +101,8 @@ pub fn canonicalize(
103
101
}
104
102
105
103
let link = std:: fs:: read_link ( & ret) ?;
106
- let ptr = unsafe { & * ( link. as_path ( ) as * const _ ) } ;
107
- cache. insert ( ret. clone ( ) , Some ( link) ) ;
108
- ptr
104
+ cache. insert ( ret. clone ( ) , Some ( link. clone ( ) ) ) ;
105
+ link
109
106
} ;
110
107
111
108
seen_links += 1 ;
@@ -127,7 +124,7 @@ pub fn canonicalize(
127
124
128
125
let remaining = components. as_path ( ) ;
129
126
if !remaining. as_os_str ( ) . is_empty ( ) {
130
- queue. push_front ( remaining) ;
127
+ queue. push_front ( remaining. to_path_buf ( ) ) ;
131
128
}
132
129
queue. push_front ( link) ;
133
130
break ;
0 commit comments