File tree 2 files changed +33
-0
lines changed
2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -177,6 +177,10 @@ fn rename_mod(
177
177
178
178
let mut source_change = SourceChange :: default ( ) ;
179
179
180
+ if module. is_crate_root ( sema. db ) {
181
+ return Ok ( source_change) ;
182
+ }
183
+
180
184
let InFile { file_id, value : def_source } = module. definition_source ( sema. db ) ;
181
185
if let ModuleSource :: SourceFile ( ..) = def_source {
182
186
let anchor = file_id. original_file ( sema. db ) ;
Original file line number Diff line number Diff line change @@ -379,6 +379,15 @@ mod tests {
379
379
expect. assert_debug_eq ( & source_change)
380
380
}
381
381
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
+
382
391
fn check_prepare ( ra_fixture : & str , expect : Expect ) {
383
392
let ( analysis, position) = fixture:: position ( ra_fixture) ;
384
393
let result = analysis
@@ -1245,6 +1254,26 @@ submodule!(bar);
1245
1254
)
1246
1255
}
1247
1256
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
+
1248
1277
#[ test]
1249
1278
fn test_enum_variant_from_module_1 ( ) {
1250
1279
cov_mark:: check!( rename_non_local) ;
You can’t perform that action at this time.
0 commit comments