@@ -10,7 +10,7 @@ pub fn analyze_crate(path: &str) -> Result<AnalysisResult> {
1010 // make the path absolute
1111 // TODO we use dunce to canonicalize the path because otherwise there is issues with python's os.path.relpath on windows, but maybe we should fix this on the Python side
1212 let crate_dir =
13- dunce:: canonicalize ( path) . context ( format ! ( "Error resolving crate path: {}" , path ) ) ?;
13+ dunce:: canonicalize ( path) . context ( format ! ( "Error resolving crate path: {path}" ) ) ?;
1414 eprintln ! ( "running new analyzer" ) ;
1515 // check the path is a directory
1616 if !crate_dir. is_dir ( ) {
@@ -43,7 +43,12 @@ pub fn analyze_crate(path: &str) -> Result<AnalysisResult> {
4343 . targets
4444 . iter ( )
4545 . find ( |t| t. kind . contains ( & "lib" . into ( ) ) )
46- . or_else ( || root_pkg. targets . iter ( ) . find ( |t| t. kind . contains ( & "bin" . into ( ) ) ) )
46+ . or_else ( || {
47+ root_pkg
48+ . targets
49+ . iter ( )
50+ . find ( |t| t. kind . contains ( & "bin" . into ( ) ) )
51+ } )
4752 . ok_or_else ( || anyhow ! ( "No lib or bin target defined in manifest" ) ) ?;
4853
4954 let crate_name = root_target. name . clone ( ) ;
@@ -61,15 +66,11 @@ pub fn analyze_crate(path: &str) -> Result<AnalysisResult> {
6166
6267 // read the top-level module
6368 let content = std:: fs:: read_to_string ( & root_module) ?;
64- let ( module, structs, enums, functions) = Module :: parse (
65- Some ( & root_module) ,
66- & [ & result. crate_ . name ] ,
67- & content,
68- )
69- . context ( format ! (
70- "Error parsing module {}" ,
71- root_module. to_string_lossy( )
72- ) ) ?;
69+ let ( module, structs, enums, functions) =
70+ Module :: parse ( Some ( & root_module) , & [ & result. crate_ . name ] , & content) . context ( format ! (
71+ "Error parsing module {}" ,
72+ root_module. to_string_lossy( )
73+ ) ) ?;
7374
7475 let mut modules_to_read = module
7576 . declarations
@@ -91,20 +92,21 @@ pub fn analyze_crate(path: &str) -> Result<AnalysisResult> {
9192 // recursively find/read the public sub‑modules
9293 let mut read_modules = vec ! [ ] ;
9394 while let Some ( ( parent_dir, module_name, parent) ) = modules_to_read. pop ( ) {
94- let ( module_path, submodule_dir) = if parent_dir. join ( & module_name) . with_extension ( "rs" ) . exists ( ) {
95- (
96- parent_dir. join ( & module_name) . with_extension ( "rs" ) ,
97- parent_dir. join ( & module_name) ,
98- )
99- } else if parent_dir. join ( & module_name) . join ( "mod.rs" ) . exists ( ) {
100- (
101- parent_dir. join ( & module_name) . join ( "mod.rs" ) ,
102- parent_dir. to_path_buf ( ) ,
103- )
104- } else {
105- // TODO warn about missing module?
106- continue ;
107- } ;
95+ let ( module_path, submodule_dir) =
96+ if parent_dir. join ( & module_name) . with_extension ( "rs" ) . exists ( ) {
97+ (
98+ parent_dir. join ( & module_name) . with_extension ( "rs" ) ,
99+ parent_dir. join ( & module_name) ,
100+ )
101+ } else if parent_dir. join ( & module_name) . join ( "mod.rs" ) . exists ( ) {
102+ (
103+ parent_dir. join ( & module_name) . join ( "mod.rs" ) ,
104+ parent_dir. to_path_buf ( ) ,
105+ )
106+ } else {
107+ // TODO warn about missing module?
108+ continue ;
109+ } ;
108110
109111 if read_modules. contains ( & module_path) {
110112 continue ;
0 commit comments