aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock86
-rw-r--r--crates/ra_hir/src/source_binder.rs2
-rw-r--r--crates/ra_hir_def/src/body.rs7
-rw-r--r--crates/ra_hir_def/src/nameres.rs29
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs4
-rw-r--r--crates/ra_hir_def/src/nameres/path_resolution.rs55
-rw-r--r--crates/ra_hir_def/src/resolver.rs38
-rw-r--r--crates/ra_hir_ty/src/tests.rs36
8 files changed, 182 insertions, 75 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 83e41940b..57cfde978 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -10,7 +10,7 @@ dependencies = [
10 10
11[[package]] 11[[package]]
12name = "anyhow" 12name = "anyhow"
13version = "1.0.24" 13version = "1.0.25"
14source = "registry+https://github.com/rust-lang/crates.io-index" 14source = "registry+https://github.com/rust-lang/crates.io-index"
15 15
16[[package]] 16[[package]]
@@ -23,7 +23,7 @@ name = "atty"
23version = "0.2.13" 23version = "0.2.13"
24source = "registry+https://github.com/rust-lang/crates.io-index" 24source = "registry+https://github.com/rust-lang/crates.io-index"
25dependencies = [ 25dependencies = [
26 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 26 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
27 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 27 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
28] 28]
29 29
@@ -39,7 +39,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
39dependencies = [ 39dependencies = [
40 "backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", 40 "backtrace-sys 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
41 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 41 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
42 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 42 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
43 "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", 43 "rustc-demangle 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)",
44] 44]
45 45
@@ -49,7 +49,7 @@ version = "0.1.32"
49source = "registry+https://github.com/rust-lang/crates.io-index" 49source = "registry+https://github.com/rust-lang/crates.io-index"
50dependencies = [ 50dependencies = [
51 "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", 51 "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)",
52 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 52 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
53] 53]
54 54
55[[package]] 55[[package]]
@@ -101,7 +101,7 @@ dependencies = [
101 101
102[[package]] 102[[package]]
103name = "cargo_metadata" 103name = "cargo_metadata"
104version = "0.9.0" 104version = "0.9.1"
105source = "registry+https://github.com/rust-lang/crates.io-index" 105source = "registry+https://github.com/rust-lang/crates.io-index"
106dependencies = [ 106dependencies = [
107 "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", 107 "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -127,7 +127,7 @@ source = "git+https://github.com/jackh726/chalk.git?rev=095cd38a4f16337913bba487
127dependencies = [ 127dependencies = [
128 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 128 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
129 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 129 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
130 "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", 130 "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
131] 131]
132 132
133[[package]] 133[[package]]
@@ -193,7 +193,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
193dependencies = [ 193dependencies = [
194 "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", 194 "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)",
195 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 195 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
196 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 196 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
197 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 197 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
198] 198]
199 199
@@ -213,7 +213,7 @@ dependencies = [
213 "clicolors-control 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 213 "clicolors-control 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
214 "encode_unicode 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", 214 "encode_unicode 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
215 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 215 "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
216 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 216 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
217 "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 217 "regex 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
218 "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 218 "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
219 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 219 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -328,7 +328,7 @@ version = "0.2.8"
328source = "registry+https://github.com/rust-lang/crates.io-index" 328source = "registry+https://github.com/rust-lang/crates.io-index"
329dependencies = [ 329dependencies = [
330 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 330 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
331 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 331 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
332 "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", 332 "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
333 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 333 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
334] 334]
@@ -367,7 +367,7 @@ name = "fsevent-sys"
367version = "2.0.1" 367version = "2.0.1"
368source = "registry+https://github.com/rust-lang/crates.io-index" 368source = "registry+https://github.com/rust-lang/crates.io-index"
369dependencies = [ 369dependencies = [
370 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 370 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
371] 371]
372 372
373[[package]] 373[[package]]
@@ -403,7 +403,7 @@ version = "0.1.13"
403source = "registry+https://github.com/rust-lang/crates.io-index" 403source = "registry+https://github.com/rust-lang/crates.io-index"
404dependencies = [ 404dependencies = [
405 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 405 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
406 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 406 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
407 "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", 407 "wasi 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
408] 408]
409 409
@@ -432,7 +432,7 @@ name = "hermit-abi"
432version = "0.1.3" 432version = "0.1.3"
433source = "registry+https://github.com/rust-lang/crates.io-index" 433source = "registry+https://github.com/rust-lang/crates.io-index"
434dependencies = [ 434dependencies = [
435 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 435 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
436] 436]
437 437
438[[package]] 438[[package]]
@@ -468,7 +468,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
468dependencies = [ 468dependencies = [
469 "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 469 "bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
470 "inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 470 "inotify-sys 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
471 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 471 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
472] 472]
473 473
474[[package]] 474[[package]]
@@ -476,7 +476,7 @@ name = "inotify-sys"
476version = "0.1.3" 476version = "0.1.3"
477source = "registry+https://github.com/rust-lang/crates.io-index" 477source = "registry+https://github.com/rust-lang/crates.io-index"
478dependencies = [ 478dependencies = [
479 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 479 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
480] 480]
481 481
482[[package]] 482[[package]]
@@ -498,7 +498,7 @@ name = "iovec"
498version = "0.1.4" 498version = "0.1.4"
499source = "registry+https://github.com/rust-lang/crates.io-index" 499source = "registry+https://github.com/rust-lang/crates.io-index"
500dependencies = [ 500dependencies = [
501 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 501 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
502] 502]
503 503
504[[package]] 504[[package]]
@@ -520,7 +520,7 @@ version = "0.3.3"
520source = "registry+https://github.com/rust-lang/crates.io-index" 520source = "registry+https://github.com/rust-lang/crates.io-index"
521dependencies = [ 521dependencies = [
522 "jemalloc-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 522 "jemalloc-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
523 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 523 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
524 "paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 524 "paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
525] 525]
526 526
@@ -531,7 +531,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
531dependencies = [ 531dependencies = [
532 "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", 532 "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)",
533 "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 533 "fs_extra 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
534 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 534 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
535] 535]
536 536
537[[package]] 537[[package]]
@@ -540,7 +540,7 @@ version = "0.3.2"
540source = "registry+https://github.com/rust-lang/crates.io-index" 540source = "registry+https://github.com/rust-lang/crates.io-index"
541dependencies = [ 541dependencies = [
542 "jemalloc-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", 542 "jemalloc-sys 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
543 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 543 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
544] 544]
545 545
546[[package]] 546[[package]]
@@ -579,7 +579,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
579 579
580[[package]] 580[[package]]
581name = "libc" 581name = "libc"
582version = "0.2.65" 582version = "0.2.66"
583source = "registry+https://github.com/rust-lang/crates.io-index" 583source = "registry+https://github.com/rust-lang/crates.io-index"
584 584
585[[package]] 585[[package]]
@@ -654,7 +654,7 @@ dependencies = [
654 "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", 654 "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
655 "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", 655 "iovec 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
656 "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 656 "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
657 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 657 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
658 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 658 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
659 "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 659 "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
660 "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", 660 "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -690,7 +690,7 @@ version = "0.2.33"
690source = "registry+https://github.com/rust-lang/crates.io-index" 690source = "registry+https://github.com/rust-lang/crates.io-index"
691dependencies = [ 691dependencies = [
692 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 692 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
693 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 693 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
694 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 694 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
695] 695]
696 696
@@ -705,7 +705,7 @@ dependencies = [
705 "fsevent-sys 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", 705 "fsevent-sys 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
706 "inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", 706 "inotify 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
707 "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", 707 "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
708 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 708 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
709 "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)", 709 "mio 0.6.21 (registry+https://github.com/rust-lang/crates.io-index)",
710 "mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)", 710 "mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
711 "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)", 711 "walkdir 2.2.9 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -726,7 +726,7 @@ version = "1.11.1"
726source = "registry+https://github.com/rust-lang/crates.io-index" 726source = "registry+https://github.com/rust-lang/crates.io-index"
727dependencies = [ 727dependencies = [
728 "hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", 728 "hermit-abi 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
729 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 729 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
730] 730]
731 731
732[[package]] 732[[package]]
@@ -755,7 +755,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
755dependencies = [ 755dependencies = [
756 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 756 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
757 "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 757 "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
758 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 758 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
759 "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", 759 "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
760 "smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", 760 "smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
761 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 761 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -778,7 +778,7 @@ dependencies = [
778 "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)", 778 "proc-macro-hack 0.5.11 (registry+https://github.com/rust-lang/crates.io-index)",
779 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 779 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
780 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 780 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
781 "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", 781 "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
782] 782]
783 783
784[[package]] 784[[package]]
@@ -812,7 +812,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
812dependencies = [ 812dependencies = [
813 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 813 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
814 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 814 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
815 "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", 815 "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
816] 816]
817 817
818[[package]] 818[[package]]
@@ -1098,7 +1098,7 @@ dependencies = [
1098name = "ra_project_model" 1098name = "ra_project_model"
1099version = "0.1.0" 1099version = "0.1.0"
1100dependencies = [ 1100dependencies = [
1101 "cargo_metadata 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", 1101 "cargo_metadata 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)",
1102 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", 1102 "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
1103 "ra_arena 0.1.0", 1103 "ra_arena 0.1.0",
1104 "ra_cfg 0.1.0", 1104 "ra_cfg 0.1.0",
@@ -1170,7 +1170,7 @@ version = "0.6.5"
1170source = "registry+https://github.com/rust-lang/crates.io-index" 1170source = "registry+https://github.com/rust-lang/crates.io-index"
1171dependencies = [ 1171dependencies = [
1172 "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", 1172 "autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
1173 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 1173 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
1174 "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 1174 "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
1175 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 1175 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
1176 "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", 1176 "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1188,7 +1188,7 @@ version = "0.7.2"
1188source = "registry+https://github.com/rust-lang/crates.io-index" 1188source = "registry+https://github.com/rust-lang/crates.io-index"
1189dependencies = [ 1189dependencies = [
1190 "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", 1190 "getrandom 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)",
1191 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 1191 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
1192 "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", 1192 "rand_chacha 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
1193 "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", 1193 "rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
1194 "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", 1194 "rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1263,7 +1263,7 @@ name = "rand_jitter"
1263version = "0.1.4" 1263version = "0.1.4"
1264source = "registry+https://github.com/rust-lang/crates.io-index" 1264source = "registry+https://github.com/rust-lang/crates.io-index"
1265dependencies = [ 1265dependencies = [
1266 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 1266 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
1267 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 1267 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
1268 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 1268 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
1269] 1269]
@@ -1275,7 +1275,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1275dependencies = [ 1275dependencies = [
1276 "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", 1276 "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
1277 "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 1277 "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
1278 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 1278 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
1279 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", 1279 "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
1280 "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", 1280 "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
1281 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 1281 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1448,7 +1448,7 @@ dependencies = [
1448 "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", 1448 "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
1449 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 1449 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
1450 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 1450 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
1451 "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", 1451 "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
1452] 1452]
1453 1453
1454[[package]] 1454[[package]]
@@ -1493,7 +1493,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1493dependencies = [ 1493dependencies = [
1494 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 1494 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
1495 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 1495 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
1496 "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", 1496 "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
1497] 1497]
1498 1498
1499[[package]] 1499[[package]]
@@ -1513,7 +1513,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1513dependencies = [ 1513dependencies = [
1514 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 1514 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
1515 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 1515 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
1516 "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", 1516 "syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)",
1517] 1517]
1518 1518
1519[[package]] 1519[[package]]
@@ -1552,7 +1552,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1552dependencies = [ 1552dependencies = [
1553 "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)", 1553 "cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)",
1554 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 1554 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
1555 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 1555 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
1556 "psm 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", 1556 "psm 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
1557 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", 1557 "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
1558] 1558]
@@ -1564,7 +1564,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1564 1564
1565[[package]] 1565[[package]]
1566name = "syn" 1566name = "syn"
1567version = "1.0.8" 1567version = "1.0.11"
1568source = "registry+https://github.com/rust-lang/crates.io-index" 1568source = "registry+https://github.com/rust-lang/crates.io-index"
1569dependencies = [ 1569dependencies = [
1570 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 1570 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1578,7 +1578,7 @@ version = "3.1.0"
1578source = "registry+https://github.com/rust-lang/crates.io-index" 1578source = "registry+https://github.com/rust-lang/crates.io-index"
1579dependencies = [ 1579dependencies = [
1580 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", 1580 "cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
1581 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 1581 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
1582 "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", 1582 "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
1583 "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", 1583 "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
1584 "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", 1584 "remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1590,7 +1590,7 @@ name = "termios"
1590version = "0.3.1" 1590version = "0.3.1"
1591source = "registry+https://github.com/rust-lang/crates.io-index" 1591source = "registry+https://github.com/rust-lang/crates.io-index"
1592dependencies = [ 1592dependencies = [
1593 "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", 1593 "libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
1594] 1594]
1595 1595
1596[[package]] 1596[[package]]
@@ -1752,7 +1752,7 @@ dependencies = [
1752name = "xtask" 1752name = "xtask"
1753version = "0.1.0" 1753version = "0.1.0"
1754dependencies = [ 1754dependencies = [
1755 "anyhow 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)", 1755 "anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
1756 "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", 1756 "pico-args 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
1757 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", 1757 "proc-macro2 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
1758 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", 1758 "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1771,7 +1771,7 @@ dependencies = [
1771 1771
1772[metadata] 1772[metadata]
1773"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" 1773"checksum aho-corasick 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d"
1774"checksum anyhow 1.0.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b412394828b7ca486b362f300b762d8e43dafd6f0d727b63f1cd2ade207c6cef" 1774"checksum anyhow 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "9267dff192e68f3399525901e709a48c1d3982c9c072fa32f2127a0cb0babf14"
1775"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8" 1775"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
1776"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" 1776"checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90"
1777"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" 1777"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
@@ -1784,7 +1784,7 @@ dependencies = [
1784"checksum bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8d6c2c5b58ab920a4f5aeaaca34b4488074e8cc7596af94e6f8c6ff247c60245" 1784"checksum bstr 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8d6c2c5b58ab920a4f5aeaaca34b4488074e8cc7596af94e6f8c6ff247c60245"
1785"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" 1785"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5"
1786"checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb" 1786"checksum c2-chacha 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "214238caa1bf3a496ec3392968969cab8549f96ff30652c9e56885329315f6bb"
1787"checksum cargo_metadata 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8d2d1617e838936c0d2323a65cc151e03ae19a7678dd24f72bccf27119b90a5d" 1787"checksum cargo_metadata 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "46e3374c604fb39d1a2f35ed5e4a4e30e60d01fab49446e08f1b3e9a90aef202"
1788"checksum cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "aa87058dce70a3ff5621797f1506cb837edd02ac4c0ae642b4542dce802908b8" 1788"checksum cc 1.0.47 (registry+https://github.com/rust-lang/crates.io-index)" = "aa87058dce70a3ff5621797f1506cb837edd02ac4c0ae642b4542dce802908b8"
1789"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" 1789"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
1790"checksum chalk-derive 0.1.0 (git+https://github.com/jackh726/chalk.git?rev=095cd38a4f16337913bba487f2055b9ca0179f30)" = "<none>" 1790"checksum chalk-derive 0.1.0 (git+https://github.com/jackh726/chalk.git?rev=095cd38a4f16337913bba487f2055b9ca0179f30)" = "<none>"
@@ -1842,7 +1842,7 @@ dependencies = [
1842"checksum lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cc4fd87be4a815fd373e02773983940f0d75fb26fde8c098e9e45f7af03154c0" 1842"checksum lalrpop-intern 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cc4fd87be4a815fd373e02773983940f0d75fb26fde8c098e9e45f7af03154c0"
1843"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" 1843"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
1844"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" 1844"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f"
1845"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" 1845"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
1846"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" 1846"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83"
1847"checksum lock_api 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e57b3997725d2b60dbec1297f6c2e2957cc383db1cebd6be812163f969c7d586" 1847"checksum lock_api 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e57b3997725d2b60dbec1297f6c2e2957cc383db1cebd6be812163f969c7d586"
1848"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" 1848"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
@@ -1921,7 +1921,7 @@ dependencies = [
1921"checksum smol_str 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "34836c9a295c62c2ce3514471117c5cb269891e8421b2aafdd910050576c4d8b" 1921"checksum smol_str 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "34836c9a295c62c2ce3514471117c5cb269891e8421b2aafdd910050576c4d8b"
1922"checksum stacker 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d96fc4f13a0ac088e9a3cd9af1cc8c5cc1ab5deb2145cef661267dfc9c542f8a" 1922"checksum stacker 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d96fc4f13a0ac088e9a3cd9af1cc8c5cc1ab5deb2145cef661267dfc9c542f8a"
1923"checksum superslice 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f" 1923"checksum superslice 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab16ced94dbd8a46c82fd81e3ed9a8727dac2977ea869d217bcc4ea1f122e81f"
1924"checksum syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "661641ea2aa15845cddeb97dad000d22070bb5c1fb456b96c1cba883ec691e92" 1924"checksum syn 1.0.11 (registry+https://github.com/rust-lang/crates.io-index)" = "dff0acdb207ae2fe6d5976617f887eb1e35a2ba52c13c7234c790960cdad9238"
1925"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" 1925"checksum tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9"
1926"checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625" 1926"checksum termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72b620c5ea021d75a735c943269bb07d30c9b77d6ac6b236bc8b5c496ef05625"
1927"checksum text_unit 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e08bbcb7a3adbda0eb23431206b653bdad3d8dea311e72d36bf2215e27a42579" 1927"checksum text_unit 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e08bbcb7a3adbda0eb23431206b653bdad3d8dea311e72d36bf2215e27a42579"
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 1661d92a2..0df7a7cb4 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -286,7 +286,7 @@ impl SourceAnalyzer {
286 286
287 let items = self 287 let items = self
288 .resolver 288 .resolver
289 .resolve_module_path(db, &path) 289 .resolve_module_path_in_items(db, &path)
290 .take_types() 290 .take_types()
291 .map(|it| PathResolution::Def(it.into())); 291 .map(|it| PathResolution::Def(it.into()));
292 types.or(values).or(items).or_else(|| { 292 types.or(values).or(items).or_else(|| {
diff --git a/crates/ra_hir_def/src/body.rs b/crates/ra_hir_def/src/body.rs
index 69508dd8a..239f35229 100644
--- a/crates/ra_hir_def/src/body.rs
+++ b/crates/ra_hir_def/src/body.rs
@@ -15,7 +15,7 @@ use rustc_hash::FxHashMap;
15use crate::{ 15use crate::{
16 db::DefDatabase, 16 db::DefDatabase,
17 expr::{Expr, ExprId, Pat, PatId}, 17 expr::{Expr, ExprId, Pat, PatId},
18 nameres::CrateDefMap, 18 nameres::{BuiltinShadowMode, CrateDefMap},
19 path::Path, 19 path::Path,
20 src::HasSource, 20 src::HasSource,
21 DefWithBodyId, HasModule, Lookup, ModuleId, 21 DefWithBodyId, HasModule, Lookup, ModuleId,
@@ -83,7 +83,10 @@ impl Expander {
83 } 83 }
84 84
85 fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { 85 fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> {
86 self.crate_def_map.resolve_path(db, self.module.local_id, path).0.take_macros() 86 self.crate_def_map
87 .resolve_path(db, self.module.local_id, path, BuiltinShadowMode::Other)
88 .0
89 .take_macros()
87 } 90 }
88} 91}
89 92
diff --git a/crates/ra_hir_def/src/nameres.rs b/crates/ra_hir_def/src/nameres.rs
index df42ea84a..3e1521870 100644
--- a/crates/ra_hir_def/src/nameres.rs
+++ b/crates/ra_hir_def/src/nameres.rs
@@ -149,6 +149,15 @@ static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| {
149 .collect() 149 .collect()
150}); 150});
151 151
152/// Shadow mode for builtin type which can be shadowed by module.
153#[derive(Debug, Copy, Clone, PartialEq, Eq)]
154pub enum BuiltinShadowMode {
155 // Prefer Module
156 Module,
157 // Prefer Other Types
158 Other,
159}
160
152/// Legacy macros can only be accessed through special methods like `get_legacy_macros`. 161/// Legacy macros can only be accessed through special methods like `get_legacy_macros`.
153/// Other methods will only resolve values, types and module scoped macros only. 162/// Other methods will only resolve values, types and module scoped macros only.
154impl ModuleScope { 163impl ModuleScope {
@@ -178,8 +187,20 @@ impl ModuleScope {
178 } 187 }
179 188
180 /// Get a name from current module scope, legacy macros are not included 189 /// Get a name from current module scope, legacy macros are not included
181 pub fn get(&self, name: &Name) -> Option<&Resolution> { 190 pub fn get(&self, name: &Name, shadow: BuiltinShadowMode) -> Option<&Resolution> {
182 self.items.get(name).or_else(|| BUILTIN_SCOPE.get(name)) 191 match shadow {
192 BuiltinShadowMode::Module => self.items.get(name).or_else(|| BUILTIN_SCOPE.get(name)),
193 BuiltinShadowMode::Other => {
194 let item = self.items.get(name);
195 if let Some(res) = item {
196 if let Some(ModuleDefId::ModuleId(_)) = res.def.take_types() {
197 return BUILTIN_SCOPE.get(name).or(item);
198 }
199 }
200
201 item.or_else(|| BUILTIN_SCOPE.get(name))
202 }
203 }
183 } 204 }
184 205
185 pub fn traits<'a>(&'a self) -> impl Iterator<Item = TraitId> + 'a { 206 pub fn traits<'a>(&'a self) -> impl Iterator<Item = TraitId> + 'a {
@@ -250,8 +271,10 @@ impl CrateDefMap {
250 db: &impl DefDatabase, 271 db: &impl DefDatabase,
251 original_module: LocalModuleId, 272 original_module: LocalModuleId,
252 path: &Path, 273 path: &Path,
274 shadow: BuiltinShadowMode,
253 ) -> (PerNs, Option<usize>) { 275 ) -> (PerNs, Option<usize>) {
254 let res = self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path); 276 let res =
277 self.resolve_path_fp_with_macro(db, ResolveMode::Other, original_module, path, shadow);
255 (res.resolved_def, res.segment_index) 278 (res.resolved_def, res.segment_index)
256 } 279 }
257} 280}
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs
index fd8245113..d4bfcae1d 100644
--- a/crates/ra_hir_def/src/nameres/collector.rs
+++ b/crates/ra_hir_def/src/nameres/collector.rs
@@ -19,7 +19,7 @@ use crate::{
19 db::DefDatabase, 19 db::DefDatabase,
20 nameres::{ 20 nameres::{
21 diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint, 21 diagnostics::DefDiagnostic, mod_resolution::ModDir, path_resolution::ReachedFixedPoint,
22 raw, CrateDefMap, ModuleData, Resolution, ResolveMode, 22 raw, BuiltinShadowMode, CrateDefMap, ModuleData, Resolution, ResolveMode,
23 }, 23 },
24 path::{Path, PathKind}, 24 path::{Path, PathKind},
25 per_ns::PerNs, 25 per_ns::PerNs,
@@ -299,6 +299,7 @@ where
299 ResolveMode::Import, 299 ResolveMode::Import,
300 module_id, 300 module_id,
301 &import.path, 301 &import.path,
302 BuiltinShadowMode::Module,
302 ); 303 );
303 304
304 (res.resolved_def, res.reached_fixedpoint) 305 (res.resolved_def, res.reached_fixedpoint)
@@ -477,6 +478,7 @@ where
477 ResolveMode::Other, 478 ResolveMode::Other,
478 *module_id, 479 *module_id,
479 path, 480 path,
481 BuiltinShadowMode::Module,
480 ); 482 );
481 483
482 if let Some(def) = resolved_res.resolved_def.take_macros() { 484 if let Some(def) = resolved_res.resolved_def.take_macros() {
diff --git a/crates/ra_hir_def/src/nameres/path_resolution.rs b/crates/ra_hir_def/src/nameres/path_resolution.rs
index b72c55bd1..42a75226b 100644
--- a/crates/ra_hir_def/src/nameres/path_resolution.rs
+++ b/crates/ra_hir_def/src/nameres/path_resolution.rs
@@ -16,7 +16,7 @@ use test_utils::tested_by;
16 16
17use crate::{ 17use crate::{
18 db::DefDatabase, 18 db::DefDatabase,
19 nameres::CrateDefMap, 19 nameres::{BuiltinShadowMode, CrateDefMap},
20 path::{Path, PathKind}, 20 path::{Path, PathKind},
21 per_ns::PerNs, 21 per_ns::PerNs,
22 AdtId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId, 22 AdtId, EnumVariantId, LocalModuleId, ModuleDefId, ModuleId,
@@ -68,7 +68,17 @@ impl CrateDefMap {
68 mode: ResolveMode, 68 mode: ResolveMode,
69 original_module: LocalModuleId, 69 original_module: LocalModuleId,
70 path: &Path, 70 path: &Path,
71 shadow: BuiltinShadowMode,
71 ) -> ResolvePathResult { 72 ) -> ResolvePathResult {
73 // if it is not the last segment, we prefer the module to the builtin
74 let prefer_module = |index| {
75 if index == path.segments.len() - 1 {
76 shadow
77 } else {
78 BuiltinShadowMode::Module
79 }
80 };
81
72 let mut segments = path.segments.iter().enumerate(); 82 let mut segments = path.segments.iter().enumerate();
73 let mut curr_per_ns: PerNs = match path.kind { 83 let mut curr_per_ns: PerNs = match path.kind {
74 PathKind::DollarCrate(krate) => { 84 PathKind::DollarCrate(krate) => {
@@ -96,20 +106,20 @@ impl CrateDefMap {
96 if self.edition == Edition::Edition2015 106 if self.edition == Edition::Edition2015
97 && (path.kind == PathKind::Abs || mode == ResolveMode::Import) => 107 && (path.kind == PathKind::Abs || mode == ResolveMode::Import) =>
98 { 108 {
99 let segment = match segments.next() { 109 let (idx, segment) = match segments.next() {
100 Some((_, segment)) => segment, 110 Some((idx, segment)) => (idx, segment),
101 None => return ResolvePathResult::empty(ReachedFixedPoint::Yes), 111 None => return ResolvePathResult::empty(ReachedFixedPoint::Yes),
102 }; 112 };
103 log::debug!("resolving {:?} in crate root (+ extern prelude)", segment); 113 log::debug!("resolving {:?} in crate root (+ extern prelude)", segment);
104 self.resolve_name_in_crate_root_or_extern_prelude(&segment.name) 114 self.resolve_name_in_crate_root_or_extern_prelude(&segment.name, prefer_module(idx))
105 } 115 }
106 PathKind::Plain => { 116 PathKind::Plain => {
107 let segment = match segments.next() { 117 let (idx, segment) = match segments.next() {
108 Some((_, segment)) => segment, 118 Some((idx, segment)) => (idx, segment),
109 None => return ResolvePathResult::empty(ReachedFixedPoint::Yes), 119 None => return ResolvePathResult::empty(ReachedFixedPoint::Yes),
110 }; 120 };
111 log::debug!("resolving {:?} in module", segment); 121 log::debug!("resolving {:?} in module", segment);
112 self.resolve_name_in_module(db, original_module, &segment.name) 122 self.resolve_name_in_module(db, original_module, &segment.name, prefer_module(idx))
113 } 123 }
114 PathKind::Super => { 124 PathKind::Super => {
115 if let Some(p) = self.modules[original_module].parent { 125 if let Some(p) = self.modules[original_module].parent {
@@ -160,7 +170,7 @@ impl CrateDefMap {
160 Path { segments: path.segments[i..].to_vec(), kind: PathKind::Self_ }; 170 Path { segments: path.segments[i..].to_vec(), kind: PathKind::Self_ };
161 log::debug!("resolving {:?} in other crate", path); 171 log::debug!("resolving {:?} in other crate", path);
162 let defp_map = db.crate_def_map(module.krate); 172 let defp_map = db.crate_def_map(module.krate);
163 let (def, s) = defp_map.resolve_path(db, module.local_id, &path); 173 let (def, s) = defp_map.resolve_path(db, module.local_id, &path, shadow);
164 return ResolvePathResult::with( 174 return ResolvePathResult::with(
165 def, 175 def,
166 ReachedFixedPoint::Yes, 176 ReachedFixedPoint::Yes,
@@ -169,7 +179,7 @@ impl CrateDefMap {
169 } 179 }
170 180
171 // Since it is a qualified path here, it should not contains legacy macros 181 // Since it is a qualified path here, it should not contains legacy macros
172 match self[module.local_id].scope.get(&segment.name) { 182 match self[module.local_id].scope.get(&segment.name, prefer_module(i)) {
173 Some(res) => res.def, 183 Some(res) => res.def,
174 _ => { 184 _ => {
175 log::debug!("path segment {:?} not found", segment.name); 185 log::debug!("path segment {:?} not found", segment.name);
@@ -212,6 +222,7 @@ impl CrateDefMap {
212 } 222 }
213 }; 223 };
214 } 224 }
225
215 ResolvePathResult::with(curr_per_ns, ReachedFixedPoint::Yes, None) 226 ResolvePathResult::with(curr_per_ns, ReachedFixedPoint::Yes, None)
216 } 227 }
217 228
@@ -220,6 +231,7 @@ impl CrateDefMap {
220 db: &impl DefDatabase, 231 db: &impl DefDatabase,
221 module: LocalModuleId, 232 module: LocalModuleId,
222 name: &Name, 233 name: &Name,
234 shadow: BuiltinShadowMode,
223 ) -> PerNs { 235 ) -> PerNs {
224 // Resolve in: 236 // Resolve in:
225 // - legacy scope of macro 237 // - legacy scope of macro
@@ -228,23 +240,33 @@ impl CrateDefMap {
228 // - std prelude 240 // - std prelude
229 let from_legacy_macro = 241 let from_legacy_macro =
230 self[module].scope.get_legacy_macro(name).map_or_else(PerNs::none, PerNs::macros); 242 self[module].scope.get_legacy_macro(name).map_or_else(PerNs::none, PerNs::macros);
231 let from_scope = self[module].scope.get(name).map_or_else(PerNs::none, |res| res.def); 243 let from_scope =
244 self[module].scope.get(name, shadow).map_or_else(PerNs::none, |res| res.def);
232 let from_extern_prelude = 245 let from_extern_prelude =
233 self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it)); 246 self.extern_prelude.get(name).map_or(PerNs::none(), |&it| PerNs::types(it));
234 let from_prelude = self.resolve_in_prelude(db, name); 247 let from_prelude = self.resolve_in_prelude(db, name, shadow);
235 248
236 from_legacy_macro.or(from_scope).or(from_extern_prelude).or(from_prelude) 249 from_legacy_macro.or(from_scope).or(from_extern_prelude).or(from_prelude)
237 } 250 }
238 251
239 fn resolve_name_in_crate_root_or_extern_prelude(&self, name: &Name) -> PerNs { 252 fn resolve_name_in_crate_root_or_extern_prelude(
253 &self,
254 name: &Name,
255 shadow: BuiltinShadowMode,
256 ) -> PerNs {
240 let from_crate_root = 257 let from_crate_root =
241 self[self.root].scope.get(name).map_or_else(PerNs::none, |res| res.def); 258 self[self.root].scope.get(name, shadow).map_or_else(PerNs::none, |res| res.def);
242 let from_extern_prelude = self.resolve_name_in_extern_prelude(name); 259 let from_extern_prelude = self.resolve_name_in_extern_prelude(name);
243 260
244 from_crate_root.or(from_extern_prelude) 261 from_crate_root.or(from_extern_prelude)
245 } 262 }
246 263
247 fn resolve_in_prelude(&self, db: &impl DefDatabase, name: &Name) -> PerNs { 264 fn resolve_in_prelude(
265 &self,
266 db: &impl DefDatabase,
267 name: &Name,
268 shadow: BuiltinShadowMode,
269 ) -> PerNs {
248 if let Some(prelude) = self.prelude { 270 if let Some(prelude) = self.prelude {
249 let keep; 271 let keep;
250 let def_map = if prelude.krate == self.krate { 272 let def_map = if prelude.krate == self.krate {
@@ -254,7 +276,10 @@ impl CrateDefMap {
254 keep = db.crate_def_map(prelude.krate); 276 keep = db.crate_def_map(prelude.krate);
255 &keep 277 &keep
256 }; 278 };
257 def_map[prelude.local_id].scope.get(name).map_or_else(PerNs::none, |res| res.def) 279 def_map[prelude.local_id]
280 .scope
281 .get(name, shadow)
282 .map_or_else(PerNs::none, |res| res.def)
258 } else { 283 } else {
259 PerNs::none() 284 PerNs::none()
260 } 285 }
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs
index 0847f6dcf..7d4df222e 100644
--- a/crates/ra_hir_def/src/resolver.rs
+++ b/crates/ra_hir_def/src/resolver.rs
@@ -14,7 +14,7 @@ use crate::{
14 db::DefDatabase, 14 db::DefDatabase,
15 expr::{ExprId, PatId}, 15 expr::{ExprId, PatId},
16 generics::GenericParams, 16 generics::GenericParams,
17 nameres::CrateDefMap, 17 nameres::{BuiltinShadowMode, CrateDefMap},
18 path::{Path, PathKind}, 18 path::{Path, PathKind},
19 per_ns::PerNs, 19 per_ns::PerNs,
20 AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId, 20 AdtId, AstItemDef, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, FunctionId,
@@ -91,7 +91,7 @@ pub enum ValueNs {
91impl Resolver { 91impl Resolver {
92 /// Resolve known trait from std, like `std::futures::Future` 92 /// Resolve known trait from std, like `std::futures::Future`
93 pub fn resolve_known_trait(&self, db: &impl DefDatabase, path: &Path) -> Option<TraitId> { 93 pub fn resolve_known_trait(&self, db: &impl DefDatabase, path: &Path) -> Option<TraitId> {
94 let res = self.resolve_module_path(db, path).take_types()?; 94 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
95 match res { 95 match res {
96 ModuleDefId::TraitId(it) => Some(it), 96 ModuleDefId::TraitId(it) => Some(it),
97 _ => None, 97 _ => None,
@@ -100,7 +100,7 @@ impl Resolver {
100 100
101 /// Resolve known struct from std, like `std::boxed::Box` 101 /// Resolve known struct from std, like `std::boxed::Box`
102 pub fn resolve_known_struct(&self, db: &impl DefDatabase, path: &Path) -> Option<StructId> { 102 pub fn resolve_known_struct(&self, db: &impl DefDatabase, path: &Path) -> Option<StructId> {
103 let res = self.resolve_module_path(db, path).take_types()?; 103 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
104 match res { 104 match res {
105 ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it), 105 ModuleDefId::AdtId(AdtId::StructId(it)) => Some(it),
106 _ => None, 106 _ => None,
@@ -109,26 +109,34 @@ impl Resolver {
109 109
110 /// Resolve known enum from std, like `std::result::Result` 110 /// Resolve known enum from std, like `std::result::Result`
111 pub fn resolve_known_enum(&self, db: &impl DefDatabase, path: &Path) -> Option<EnumId> { 111 pub fn resolve_known_enum(&self, db: &impl DefDatabase, path: &Path) -> Option<EnumId> {
112 let res = self.resolve_module_path(db, path).take_types()?; 112 let res = self.resolve_module_path(db, path, BuiltinShadowMode::Other).take_types()?;
113 match res { 113 match res {
114 ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it), 114 ModuleDefId::AdtId(AdtId::EnumId(it)) => Some(it),
115 _ => None, 115 _ => None,
116 } 116 }
117 } 117 }
118 118
119 /// pub only for source-binder 119 fn resolve_module_path(
120 pub fn resolve_module_path(&self, db: &impl DefDatabase, path: &Path) -> PerNs { 120 &self,
121 db: &impl DefDatabase,
122 path: &Path,
123 shadow: BuiltinShadowMode,
124 ) -> PerNs {
121 let (item_map, module) = match self.module() { 125 let (item_map, module) = match self.module() {
122 Some(it) => it, 126 Some(it) => it,
123 None => return PerNs::none(), 127 None => return PerNs::none(),
124 }; 128 };
125 let (module_res, segment_index) = item_map.resolve_path(db, module, path); 129 let (module_res, segment_index) = item_map.resolve_path(db, module, path, shadow);
126 if segment_index.is_some() { 130 if segment_index.is_some() {
127 return PerNs::none(); 131 return PerNs::none();
128 } 132 }
129 module_res 133 module_res
130 } 134 }
131 135
136 pub fn resolve_module_path_in_items(&self, db: &impl DefDatabase, path: &Path) -> PerNs {
137 self.resolve_module_path(db, path, BuiltinShadowMode::Module)
138 }
139
132 pub fn resolve_path_in_type_ns( 140 pub fn resolve_path_in_type_ns(
133 &self, 141 &self,
134 db: &impl DefDatabase, 142 db: &impl DefDatabase,
@@ -163,7 +171,12 @@ impl Resolver {
163 } 171 }
164 } 172 }
165 Scope::ModuleScope(m) => { 173 Scope::ModuleScope(m) => {
166 let (module_def, idx) = m.crate_def_map.resolve_path(db, m.module_id, path); 174 let (module_def, idx) = m.crate_def_map.resolve_path(
175 db,
176 m.module_id,
177 path,
178 BuiltinShadowMode::Other,
179 );
167 let res = match module_def.take_types()? { 180 let res = match module_def.take_types()? {
168 ModuleDefId::AdtId(it) => TypeNs::AdtId(it), 181 ModuleDefId::AdtId(it) => TypeNs::AdtId(it),
169 ModuleDefId::EnumVariantId(it) => TypeNs::EnumVariantId(it), 182 ModuleDefId::EnumVariantId(it) => TypeNs::EnumVariantId(it),
@@ -256,7 +269,12 @@ impl Resolver {
256 Scope::ImplBlockScope(_) | Scope::AdtScope(_) => continue, 269 Scope::ImplBlockScope(_) | Scope::AdtScope(_) => continue,
257 270
258 Scope::ModuleScope(m) => { 271 Scope::ModuleScope(m) => {
259 let (module_def, idx) = m.crate_def_map.resolve_path(db, m.module_id, path); 272 let (module_def, idx) = m.crate_def_map.resolve_path(
273 db,
274 m.module_id,
275 path,
276 BuiltinShadowMode::Other,
277 );
260 return match idx { 278 return match idx {
261 None => { 279 None => {
262 let value = match module_def.take_values()? { 280 let value = match module_def.take_values()? {
@@ -310,7 +328,7 @@ impl Resolver {
310 328
311 pub fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> { 329 pub fn resolve_path_as_macro(&self, db: &impl DefDatabase, path: &Path) -> Option<MacroDefId> {
312 let (item_map, module) = self.module()?; 330 let (item_map, module) = self.module()?;
313 item_map.resolve_path(db, module, path).0.take_macros() 331 item_map.resolve_path(db, module, path, BuiltinShadowMode::Other).0.take_macros()
314 } 332 }
315 333
316 pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) { 334 pub fn process_all_names(&self, db: &impl DefDatabase, f: &mut dyn FnMut(Name, ScopeDef)) {
diff --git a/crates/ra_hir_ty/src/tests.rs b/crates/ra_hir_ty/src/tests.rs
index c856d6afd..a3cc5cf95 100644
--- a/crates/ra_hir_ty/src/tests.rs
+++ b/crates/ra_hir_ty/src/tests.rs
@@ -3694,6 +3694,42 @@ fn main() {
3694} 3694}
3695 3695
3696#[test] 3696#[test]
3697fn not_shadowing_primitive_by_module() {
3698 let t = type_at(
3699 r#"
3700//- /str.rs
3701fn foo() {}
3702
3703//- /main.rs
3704mod str;
3705fn foo() -> &'static str { "" }
3706
3707fn main() {
3708 foo()<|>;
3709}"#,
3710 );
3711 assert_eq!(t, "&str");
3712}
3713
3714#[test]
3715fn not_shadowing_module_by_primitive() {
3716 let t = type_at(
3717 r#"
3718//- /str.rs
3719fn foo() -> u32 {0}
3720
3721//- /main.rs
3722mod str;
3723fn foo() -> &'static str { "" }
3724
3725fn main() {
3726 str::foo()<|>;
3727}"#,
3728 );
3729 assert_eq!(t, "u32");
3730}
3731
3732#[test]
3697fn deref_trait() { 3733fn deref_trait() {
3698 let t = type_at( 3734 let t = type_at(
3699 r#" 3735 r#"