@@ -119,9 +119,9 @@ pub(crate) fn rename(
119119 } ;
120120
121121 let mut source_change = SourceChange :: default ( ) ;
122- source_change. extend ( usages. iter ( ) . map ( | ( & file_id , refs ) | {
123- ( file_id, source_edit_from_references ( refs, def, new_name) )
124- } ) ) ;
122+ source_change. extend ( usages. references . get_mut ( & position . file_id ) . iter ( ) . map (
123+ |refs| ( position . file_id , source_edit_from_references ( refs, def, new_name) ) ,
124+ ) ) ;
125125
126126 Ok ( source_change)
127127 } )
@@ -444,12 +444,8 @@ mod tests {
444444
445445 use super :: { RangeInfo , RenameError } ;
446446
447- fn check ( new_name : & str , ra_fixture_before : & str , ra_fixture_after : & str ) {
448- check_with_rename_config ( new_name, ra_fixture_before, ra_fixture_after) ;
449- }
450-
451447 #[ track_caller]
452- fn check_with_rename_config ( new_name : & str , ra_fixture_before : & str , ra_fixture_after : & str ) {
448+ fn check ( new_name : & str , ra_fixture_before : & str , ra_fixture_after : & str ) {
453449 let ra_fixture_after = & trim_indent ( ra_fixture_after) ;
454450 let ( analysis, position) = fixture:: position ( ra_fixture_before) ;
455451 if !ra_fixture_after. starts_with ( "error: " ) {
@@ -466,7 +462,7 @@ mod tests {
466462 let ( & file_id, edit) = match source_change. source_file_edits . len ( ) {
467463 0 => return ,
468464 1 => source_change. source_file_edits . iter ( ) . next ( ) . unwrap ( ) ,
469- _ => ( & position . file_id , & source_change . source_file_edits [ & position . file_id ] ) ,
465+ _ => panic ! ( ) ,
470466 } ;
471467 for indel in edit. 0 . iter ( ) {
472468 text_edit_builder. replace ( indel. delete , indel. insert . clone ( ) ) ;
@@ -2689,7 +2685,7 @@ use qux as frob;
26892685
26902686 #[ test]
26912687 fn disallow_renaming_for_non_local_definition ( ) {
2692- check_with_rename_config (
2688+ check (
26932689 "Baz" ,
26942690 r#"
26952691//- /lib.rs crate:lib new_source_root:library
@@ -2704,7 +2700,7 @@ fn main() { let _: S$0; }
27042700
27052701 #[ test]
27062702 fn disallow_renaming_for_builtin_macros ( ) {
2707- check_with_rename_config (
2703+ check (
27082704 "Baz" ,
27092705 r#"
27102706//- minicore: derive, hash
@@ -2762,14 +2758,19 @@ fn test() {
27622758 check (
27632759 "Baz" ,
27642760 r#"
2761+ //- /main.rs crate:main
2762+ mod module;
27652763mod foo { pub struct Foo; }
27662764mod bar { use super::Foo; }
27672765
27682766use foo::Foo$0;
27692767
27702768fn main() { let _: Foo; }
2769+ //- /module.rs
2770+ use crate::foo::Foo;
27712771"# ,
27722772 r#"
2773+ mod module;
27732774mod foo { pub struct Foo; }
27742775mod bar { use super::Baz; }
27752776
@@ -2779,4 +2780,22 @@ fn main() { let _: Baz; }
27792780"# ,
27802781 )
27812782 }
2783+
2784+ #[ test]
2785+ fn rename_path_inside_use_tree_foreign ( ) {
2786+ check (
2787+ "Baz" ,
2788+ r#"
2789+ //- /lib.rs crate:lib new_source_root:library
2790+ pub struct S;
2791+ //- /main.rs crate:main deps:lib new_source_root:local
2792+ use lib::S$0;
2793+ fn main() { let _: S; }
2794+ "# ,
2795+ r#"
2796+ use lib::S as Baz;
2797+ fn main() { let _: Baz; }
2798+ "# ,
2799+ ) ;
2800+ }
27822801}
0 commit comments