aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_def/src/find_path.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir_def/src/find_path.rs')
-rw-r--r--crates/ra_hir_def/src/find_path.rs57
1 files changed, 30 insertions, 27 deletions
diff --git a/crates/ra_hir_def/src/find_path.rs b/crates/ra_hir_def/src/find_path.rs
index 2eb12ec8f..68d3cde08 100644
--- a/crates/ra_hir_def/src/find_path.rs
+++ b/crates/ra_hir_def/src/find_path.rs
@@ -4,7 +4,7 @@ use std::sync::Arc;
4 4
5use hir_expand::name::{known, AsName, Name}; 5use hir_expand::name::{known, AsName, Name};
6use ra_prof::profile; 6use ra_prof::profile;
7use test_utils::tested_by; 7use test_utils::mark;
8 8
9use crate::{ 9use crate::{
10 db::DefDatabase, 10 db::DefDatabase,
@@ -164,17 +164,19 @@ fn find_path_inner(
164 164
165fn select_best_path(old_path: ModPath, new_path: ModPath, prefer_no_std: bool) -> ModPath { 165fn select_best_path(old_path: ModPath, new_path: ModPath, prefer_no_std: bool) -> ModPath {
166 if old_path.starts_with_std() && new_path.can_start_with_std() { 166 if old_path.starts_with_std() && new_path.can_start_with_std() {
167 tested_by!(prefer_std_paths);
168 if prefer_no_std { 167 if prefer_no_std {
168 mark::hit!(prefer_no_std_paths);
169 new_path 169 new_path
170 } else { 170 } else {
171 mark::hit!(prefer_std_paths);
171 old_path 172 old_path
172 } 173 }
173 } else if new_path.starts_with_std() && old_path.can_start_with_std() { 174 } else if new_path.starts_with_std() && old_path.can_start_with_std() {
174 tested_by!(prefer_std_paths);
175 if prefer_no_std { 175 if prefer_no_std {
176 mark::hit!(prefer_no_std_paths);
176 old_path 177 old_path
177 } else { 178 } else {
179 mark::hit!(prefer_std_paths);
178 new_path 180 new_path
179 } 181 }
180 } else if new_path.len() < old_path.len() { 182 } else if new_path.len() < old_path.len() {
@@ -251,12 +253,14 @@ pub(crate) fn importable_locations_of_query(
251 253
252#[cfg(test)] 254#[cfg(test)]
253mod tests { 255mod tests {
254 use super::*;
255 use crate::test_db::TestDB;
256 use hir_expand::hygiene::Hygiene; 256 use hir_expand::hygiene::Hygiene;
257 use ra_db::fixture::WithFixture; 257 use ra_db::fixture::WithFixture;
258 use ra_syntax::ast::AstNode; 258 use ra_syntax::ast::AstNode;
259 use test_utils::covers; 259 use test_utils::mark;
260
261 use crate::test_db::TestDB;
262
263 use super::*;
260 264
261 /// `code` needs to contain a cursor marker; checks that `find_path` for the 265 /// `code` needs to contain a cursor marker; checks that `find_path` for the
262 /// item the `path` refers to returns that same path when called from the 266 /// item the `path` refers to returns that same path when called from the
@@ -511,7 +515,7 @@ mod tests {
511 515
512 #[test] 516 #[test]
513 fn prefer_std_paths_over_alloc() { 517 fn prefer_std_paths_over_alloc() {
514 covers!(prefer_std_paths); 518 mark::check!(prefer_std_paths);
515 let code = r#" 519 let code = r#"
516 //- /main.rs crate:main deps:alloc,std 520 //- /main.rs crate:main deps:alloc,std
517 <|> 521 <|>
@@ -530,51 +534,50 @@ mod tests {
530 } 534 }
531 535
532 #[test] 536 #[test]
533 fn prefer_alloc_paths_over_std() { 537 fn prefer_core_paths_over_std() {
534 covers!(prefer_std_paths); 538 mark::check!(prefer_no_std_paths);
535 let code = r#" 539 let code = r#"
536 //- /main.rs crate:main deps:alloc,std 540 //- /main.rs crate:main deps:core,std
537 #![no_std] 541 #![no_std]
538 542
539 <|> 543 <|>
540 544
541 //- /std.rs crate:std deps:alloc 545 //- /std.rs crate:std deps:core
542 546
543 pub mod sync { 547 pub mod fmt {
544 pub use alloc::sync::Arc; 548 pub use core::fmt::Error;
545 } 549 }
546 550
547 //- /zzz.rs crate:alloc 551 //- /zzz.rs crate:core
548 552
549 pub mod sync { 553 pub mod fmt {
550 pub struct Arc; 554 pub struct Error;
551 } 555 }
552 "#; 556 "#;
553 check_found_path(code, "alloc::sync::Arc"); 557 check_found_path(code, "core::fmt::Error");
554 } 558 }
555 559
556 #[test] 560 #[test]
557 fn prefer_core_paths_over_std() { 561 fn prefer_alloc_paths_over_std() {
558 covers!(prefer_std_paths);
559 let code = r#" 562 let code = r#"
560 //- /main.rs crate:main deps:core,std 563 //- /main.rs crate:main deps:alloc,std
561 #![no_std] 564 #![no_std]
562 565
563 <|> 566 <|>
564 567
565 //- /std.rs crate:std deps:core 568 //- /std.rs crate:std deps:alloc
566 569
567 pub mod fmt { 570 pub mod sync {
568 pub use core::fmt::Error; 571 pub use alloc::sync::Arc;
569 } 572 }
570 573
571 //- /zzz.rs crate:core 574 //- /zzz.rs crate:alloc
572 575
573 pub mod fmt { 576 pub mod sync {
574 pub struct Error; 577 pub struct Arc;
575 } 578 }
576 "#; 579 "#;
577 check_found_path(code, "core::fmt::Error"); 580 check_found_path(code, "alloc::sync::Arc");
578 } 581 }
579 582
580 #[test] 583 #[test]