@@ -27,19 +27,12 @@ struct FnStats {
27
27
28
28
#[ derive( Clone ) ]
29
29
struct StructuredFnName {
30
- trait_impl : Option < ( String , String ) > ,
31
- krate : String ,
30
+ trait_impl : Option < ( String , String ) > , // type as trait
32
31
module_path : Vec < String > ,
33
32
type_parameters : Vec < String > ,
34
33
item : String ,
35
34
}
36
35
37
- #[ derive( PartialOrd , Ord , Hash , Eq , PartialEq ) ]
38
- struct CrateAndModules {
39
- krate : String ,
40
- module_path : Vec < String >
41
- }
42
-
43
36
fn split_by_double_colons ( s : & str ) -> Vec < String > {
44
37
let mut bracket_level = 0 ;
45
38
let mut current_string = String :: new ( ) ;
@@ -158,7 +151,6 @@ fn parse_fn_name(raw_name:String) -> StructuredFnName {
158
151
let ti_captures = trait_impl_re. captures ( & parts[ 1 ] ) . unwrap ( ) ;
159
152
return StructuredFnName {
160
153
trait_impl : Some ( ( ti_captures[ 1 ] . to_string ( ) , ti_captures[ 2 ] . to_string ( ) ) ) ,
161
- krate : "" . to_string ( ) ,
162
154
module_path : vec ! [ ] ,
163
155
type_parameters : vec ! [ ] ,
164
156
item : parts[ 0 ] . to_string ( )
@@ -180,14 +172,9 @@ fn parse_fn_name(raw_name:String) -> StructuredFnName {
180
172
mp. push ( parts[ parts_index] . to_string ( ) ) ;
181
173
parts_index += 1 ;
182
174
}
183
- let kr = match mp. pop ( ) {
184
- Some ( k) => k,
185
- None => "" . to_string ( )
186
- } ;
187
175
188
176
StructuredFnName {
189
177
trait_impl : None ,
190
- krate : kr,
191
178
module_path : mp. into_iter ( ) . rev ( ) . collect ( ) ,
192
179
type_parameters : type_parameters. into_iter ( ) . map ( |x| x. to_string ( ) ) . collect ( ) ,
193
180
item : item. to_string ( )
@@ -200,30 +187,26 @@ fn handle_file(path:&Path) -> Result<(), Box<dyn Error>> {
200
187
201
188
println ! ( "# Unsafe usages in file {}" , path. display( ) ) ;
202
189
203
- let mut fns_by_crate_and_modules : HashMap < CrateAndModules , Vec < StructuredFnName > > = HashMap :: new ( ) ;
190
+ let mut fns_by_modules : HashMap < Vec < String > , Vec < StructuredFnName > > = HashMap :: new ( ) ;
204
191
205
192
for result in rdr. deserialize ( ) {
206
193
let fn_stats: FnStats = result?;
207
194
if matches ! ( fn_stats. is_unsafe, Some ( true ) ) || matches ! ( fn_stats. has_unsafe_ops, Some ( true ) ) {
208
195
let structured_fn_name = parse_fn_name ( fn_stats. name ) ;
209
- let krate_and_module_path = CrateAndModules {
210
- krate : structured_fn_name. krate . clone ( ) ,
211
- module_path : structured_fn_name. module_path . clone ( )
212
- } ;
213
- match fns_by_crate_and_modules. get_mut ( & krate_and_module_path) {
196
+ match fns_by_modules. get_mut ( & structured_fn_name. module_path ) {
214
197
Some ( fns) => fns. push ( structured_fn_name. clone ( ) ) ,
215
- None => { fns_by_crate_and_modules . insert ( krate_and_module_path , vec ! [ structured_fn_name. clone( ) ] ) ; }
198
+ None => { fns_by_modules . insert ( structured_fn_name . module_path . clone ( ) , vec ! [ structured_fn_name. clone( ) ] ) ; }
216
199
}
217
200
}
218
201
}
219
202
220
- for krm in fns_by_crate_and_modules . keys ( ) . sorted ( ) {
221
- println ! ( "crate {}, modules {:?}" , krm . krate , krm . module_path ) ;
222
- if let Some ( fns) = fns_by_crate_and_modules . get ( krm ) {
203
+ for mp in fns_by_modules . keys ( ) . sorted ( ) {
204
+ println ! ( "modules {:?}" , mp ) ;
205
+ if let Some ( fns) = fns_by_modules . get ( mp ) {
223
206
for structured_fn_name in fns {
224
207
println ! ( "--- unsafe-containing fn {}" , structured_fn_name. item) ;
225
208
if let Some ( ti) = & structured_fn_name. trait_impl {
226
- println ! ( " trait {} as {}" , ti. 0 , ti. 1 ) ;
209
+ println ! ( " trait impl: type {} as trait {}" , ti. 0 , ti. 1 ) ;
227
210
} else { }
228
211
if !structured_fn_name. type_parameters . is_empty ( ) {
229
212
println ! ( " type parameters {:?}" , structured_fn_name. type_parameters) ;
0 commit comments