Skip to content

Commit cfd4bca

Browse files
committed
print [pub] for public fns
1 parent 255e8f2 commit cfd4bca

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

tools/unsafe-finder/src/main.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ struct StructuredFnName {
3030
module_path: Vec<String>,
3131
type_parameters: Vec<String>,
3232
item: String,
33+
is_public: bool
3334
}
3435

3536
fn split_by_double_colons(s:&str) -> Vec<String> {
@@ -140,7 +141,7 @@ mod tests {
140141
}
141142
}
142143

143-
fn parse_fn_name(raw_name:String) -> StructuredFnName {
144+
fn parse_fn_name(raw_name:String, is_public:bool) -> StructuredFnName {
144145
let trait_impl_re = Regex::new(r"<(.+) as (.+)>").unwrap();
145146
let brackets_re = Regex::new(r"<(.+)>").unwrap();
146147

@@ -152,7 +153,8 @@ fn parse_fn_name(raw_name:String) -> StructuredFnName {
152153
trait_impl: Some((ti_captures[1].to_string(), ti_captures[2].to_string())),
153154
module_path: vec![],
154155
type_parameters: vec![],
155-
item: parts[0].to_string()
156+
item: parts[0].to_string(),
157+
is_public: is_public
156158
}
157159
}
158160

@@ -176,7 +178,8 @@ fn parse_fn_name(raw_name:String) -> StructuredFnName {
176178
trait_impl: None,
177179
module_path: mp.into_iter().rev().collect(),
178180
type_parameters: type_parameters.into_iter().map(|x| x.to_string()).collect(),
179-
item: item.to_string()
181+
item: item.to_string(),
182+
is_public: is_public
180183
}
181184
}
182185

@@ -191,7 +194,7 @@ fn handle_file(path:&Path) -> Result<(), Box<dyn Error>> {
191194
for result in rdr.deserialize() {
192195
let fn_stats: FnStats = result?;
193196
if matches!(fn_stats.is_unsafe, Some(true)) || matches!(fn_stats.has_unsafe_ops, Some(true)) {
194-
let structured_fn_name = parse_fn_name(fn_stats.name);
197+
let structured_fn_name = parse_fn_name(fn_stats.name, fn_stats.is_public.is_some() && fn_stats.is_public.unwrap());
195198
match fns_by_modules.get_mut(&structured_fn_name.module_path) {
196199
Some(fns) => fns.push(structured_fn_name.clone()),
197200
None => { fns_by_modules.insert(structured_fn_name.module_path.clone(), vec![structured_fn_name.clone()]); }
@@ -203,7 +206,7 @@ fn handle_file(path:&Path) -> Result<(), Box<dyn Error>> {
203206
println!("modules {:?}", mp);
204207
if let Some(fns) = fns_by_modules.get(mp) {
205208
for structured_fn_name in fns {
206-
println!("--- unsafe-containing fn {}", structured_fn_name.item);
209+
println!("--- unsafe-containing fn {} {}", structured_fn_name.item, if structured_fn_name.is_public { "[pub]" } else { "" } );
207210
if let Some(ti) = &structured_fn_name.trait_impl {
208211
println!(" trait impl: type {} as trait {}", ti.0, ti.1);
209212
} else {}

0 commit comments

Comments
 (0)