File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed
Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,10 @@ fn rename_mod(
177177
178178 let mut source_change = SourceChange :: default ( ) ;
179179
180+ if module. is_crate_root ( sema. db ) {
181+ return Ok ( source_change) ;
182+ }
183+
180184 let InFile { file_id, value : def_source } = module. definition_source ( sema. db ) ;
181185 if let ModuleSource :: SourceFile ( ..) = def_source {
182186 let anchor = file_id. original_file ( sema. db ) ;
Original file line number Diff line number Diff line change @@ -379,6 +379,15 @@ mod tests {
379379 expect. assert_debug_eq ( & source_change)
380380 }
381381
382+ fn check_expect_will_rename_file ( new_name : & str , ra_fixture : & str , expect : Expect ) {
383+ let ( analysis, position) = fixture:: position ( ra_fixture) ;
384+ let source_change = analysis
385+ . will_rename_file ( position. file_id , new_name)
386+ . unwrap ( )
387+ . expect ( "Expect returned a RenameError" ) ;
388+ expect. assert_debug_eq ( & source_change)
389+ }
390+
382391 fn check_prepare ( ra_fixture : & str , expect : Expect ) {
383392 let ( analysis, position) = fixture:: position ( ra_fixture) ;
384393 let result = analysis
@@ -1245,6 +1254,26 @@ submodule!(bar);
12451254 )
12461255 }
12471256
1257+ #[ test]
1258+ fn test_rename_mod_for_crate_root ( ) {
1259+ check_expect_will_rename_file (
1260+ "main" ,
1261+ r#"
1262+ //- /lib.rs
1263+ use crate::foo as bar;
1264+ fn foo() {}
1265+ mod bar$0;
1266+ "# ,
1267+ expect ! [ [ r#"
1268+ SourceChange {
1269+ source_file_edits: {},
1270+ file_system_edits: [],
1271+ is_snippet: false,
1272+ }
1273+ "# ] ] ,
1274+ )
1275+ }
1276+
12481277 #[ test]
12491278 fn test_enum_variant_from_module_1 ( ) {
12501279 cov_mark:: check!( rename_non_local) ;
You can’t perform that action at this time.
0 commit comments