@@ -38,7 +38,7 @@ fn fixes(ctx: &DiagnosticsContext, file_id: FileId) -> Option<Vec<Assist>> {
38
38
39
39
let source_root = ctx. sema . db . source_root ( ctx. sema . db . file_source_root ( file_id) ) ;
40
40
let our_path = source_root. path_for_file ( & file_id) ?;
41
- let module_name = our_path. name_and_extension ( ) ?. 0 ;
41
+ let ( module_name, _ ) = our_path. name_and_extension ( ) ?;
42
42
43
43
// Candidates to look for:
44
44
// - `mod.rs` in the same folder
@@ -48,26 +48,23 @@ fn fixes(ctx: &DiagnosticsContext, file_id: FileId) -> Option<Vec<Assist>> {
48
48
let mut paths = vec ! [ parent. join( "mod.rs" ) ?, parent. join( "lib.rs" ) ?, parent. join( "main.rs" ) ?] ;
49
49
50
50
// `submod/bla.rs` -> `submod.rs`
51
- if let Some ( newmod ) = ( || {
52
- let name = parent. name_and_extension ( ) ?. 0 ;
51
+ let parent_mod = ( || {
52
+ let ( name, _ ) = parent. name_and_extension ( ) ?;
53
53
parent. parent ( ) ?. join ( & format ! ( "{}.rs" , name) )
54
- } ) ( ) {
55
- paths. push ( newmod) ;
56
- }
54
+ } ) ( ) ;
55
+ paths. extend ( parent_mod) ;
56
+
57
+ for & parent_id in paths. iter ( ) . filter_map ( |path| source_root. file_for_path ( path) ) {
58
+ for & krate in ctx. sema . db . relevant_crates ( parent_id) . iter ( ) {
59
+ let crate_def_map = ctx. sema . db . crate_def_map ( krate) ;
60
+ for ( _, module) in crate_def_map. modules ( ) {
61
+ if module. origin . is_inline ( ) {
62
+ // We don't handle inline `mod parent {}`s, they use different paths.
63
+ continue ;
64
+ }
57
65
58
- for path in & paths {
59
- if let Some ( parent_id) = source_root. file_for_path ( path) {
60
- for krate in ctx. sema . db . relevant_crates ( * parent_id) . iter ( ) {
61
- let crate_def_map = ctx. sema . db . crate_def_map ( * krate) ;
62
- for ( _, module) in crate_def_map. modules ( ) {
63
- if module. origin . is_inline ( ) {
64
- // We don't handle inline `mod parent {}`s, they use different paths.
65
- continue ;
66
- }
67
-
68
- if module. origin . file_id ( ) == Some ( * parent_id) {
69
- return make_fixes ( ctx. sema . db , * parent_id, module_name, file_id) ;
70
- }
66
+ if module. origin . file_id ( ) == Some ( parent_id) {
67
+ return make_fixes ( ctx. sema . db , parent_id, module_name, file_id) ;
71
68
}
72
69
}
73
70
}
0 commit comments