@@ -8,6 +8,7 @@ use crate::{
88 CrateId , ModuleDefId , ModuleId ,
99} ;
1010use hir_expand:: name:: { known, Name } ;
11+ use test_utils:: tested_by;
1112
1213const MAX_PATH_LEN : usize = 15 ;
1314
@@ -151,8 +152,10 @@ fn find_path_inner(
151152
152153fn select_best_path ( old_path : ModPath , new_path : ModPath ) -> ModPath {
153154 if old_path. starts_with_std ( ) && new_path. should_start_with_std ( ) {
155+ tested_by ! ( prefer_std_paths) ;
154156 old_path
155157 } else if new_path. starts_with_std ( ) && old_path. should_start_with_std ( ) {
158+ tested_by ! ( prefer_std_paths) ;
156159 new_path
157160 } else if new_path. len ( ) < old_path. len ( ) {
158161 new_path
@@ -231,6 +234,7 @@ mod tests {
231234 use hir_expand:: hygiene:: Hygiene ;
232235 use ra_db:: fixture:: WithFixture ;
233236 use ra_syntax:: ast:: AstNode ;
237+ use test_utils:: covers;
234238
235239 /// `code` needs to contain a cursor marker; checks that `find_path` for the
236240 /// item the `path` refers to returns that same path when called from the
@@ -482,4 +486,41 @@ mod tests {
482486 "# ;
483487 check_found_path ( code, "crate::foo::S" ) ;
484488 }
489+
490+ #[ test]
491+ fn prefer_std_paths_over_alloc ( ) {
492+ covers ! ( prefer_std_paths) ;
493+ let code = r#"
494+ //- /main.rs crate:main deps:alloc,std
495+ <|>
496+
497+ //- /std.rs crate:std deps:alloc
498+ pub mod sync {
499+ pub use alloc::sync::Arc;
500+ }
501+
502+ //- /zzz.rs crate:alloc
503+ pub mod sync {
504+ pub struct Arc;
505+ }
506+ "# ;
507+ check_found_path ( code, "std::sync::Arc" ) ;
508+ }
509+
510+ #[ test]
511+ fn prefer_shorter_paths_if_not_alloc ( ) {
512+ let code = r#"
513+ //- /main.rs crate:main deps:megaalloc,std
514+ <|>
515+
516+ //- /std.rs crate:std deps:megaalloc
517+ pub mod sync {
518+ pub use megaalloc::sync::Arc;
519+ }
520+
521+ //- /zzz.rs crate:megaalloc
522+ pub struct Arc;
523+ "# ;
524+ check_found_path ( code, "megaalloc::Arc" ) ;
525+ }
485526}
0 commit comments