diff options
author | Florian Diebold <[email protected]> | 2020-01-11 22:19:58 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2020-01-11 22:37:58 +0000 |
commit | 9dc1826cfaa75983a83f9eb7f788067d5dedf5a7 (patch) | |
tree | c92f033b4b97ee393dafb3a83537f47c4c82d435 /crates | |
parent | 2e09a96f82d4ba15de2c8b8fbbe40fd78e21c185 (diff) |
Fix various names, e.g. Iterator not resolving in core prelude
Basically, `Iterator` is re-exported via several steps, which happened to not be
resolved yet when we got to the prelude import, but since the name resolved to
the reexport from `core::iter` (just to no actual items), we gave up trying to
resolve it further.
Maybe part of the problem is that we can have
`PartialResolvedImport::Unresolved` or `PartialResolvedImport::Indeterminate`
with `None` in all namespaces, and handle them differently.
Fixes #2683.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir_def/src/nameres/collector.rs | 2 | ||||
-rw-r--r-- | crates/ra_hir_def/src/nameres/tests/mod_resolution.rs | 45 | ||||
-rw-r--r-- | crates/ra_hir_ty/src/tests/regression.rs | 54 |
3 files changed, 100 insertions, 1 deletions
diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index 35b852ee2..7499dff31 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs | |||
@@ -328,7 +328,7 @@ where | |||
328 | ); | 328 | ); |
329 | 329 | ||
330 | let def = res.resolved_def; | 330 | let def = res.resolved_def; |
331 | if res.reached_fixedpoint == ReachedFixedPoint::No { | 331 | if res.reached_fixedpoint == ReachedFixedPoint::No || def.is_none() { |
332 | return PartialResolvedImport::Unresolved; | 332 | return PartialResolvedImport::Unresolved; |
333 | } | 333 | } |
334 | 334 | ||
diff --git a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs index e800cc68e..22103ab29 100644 --- a/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs +++ b/crates/ra_hir_def/src/nameres/tests/mod_resolution.rs | |||
@@ -53,6 +53,51 @@ fn nested_module_resolution() { | |||
53 | } | 53 | } |
54 | 54 | ||
55 | #[test] | 55 | #[test] |
56 | fn nested_module_resolution_2() { | ||
57 | let map = def_map( | ||
58 | " | ||
59 | //- /lib.rs | ||
60 | mod prelude; | ||
61 | mod iter; | ||
62 | |||
63 | //- /prelude.rs | ||
64 | pub use crate::iter::Iterator; | ||
65 | |||
66 | //- /iter.rs | ||
67 | pub use self::traits::Iterator; | ||
68 | mod traits; | ||
69 | |||
70 | //- /iter/traits.rs | ||
71 | pub use self::iterator::Iterator; | ||
72 | mod iterator; | ||
73 | |||
74 | //- /iter/traits/iterator.rs | ||
75 | pub trait Iterator; | ||
76 | ", | ||
77 | ); | ||
78 | |||
79 | assert_snapshot!(map, @r###" | ||
80 | crate | ||
81 | iter: t | ||
82 | prelude: t | ||
83 | |||
84 | crate::iter | ||
85 | Iterator: t | ||
86 | traits: t | ||
87 | |||
88 | crate::iter::traits | ||
89 | Iterator: t | ||
90 | iterator: t | ||
91 | |||
92 | crate::iter::traits::iterator | ||
93 | Iterator: t | ||
94 | |||
95 | crate::prelude | ||
96 | Iterator: t | ||
97 | "###); | ||
98 | } | ||
99 | |||
100 | #[test] | ||
56 | fn module_resolution_works_for_non_standard_filenames() { | 101 | fn module_resolution_works_for_non_standard_filenames() { |
57 | let map = def_map( | 102 | let map = def_map( |
58 | " | 103 | " |
diff --git a/crates/ra_hir_ty/src/tests/regression.rs b/crates/ra_hir_ty/src/tests/regression.rs index 6c5d39549..aa948dcbf 100644 --- a/crates/ra_hir_ty/src/tests/regression.rs +++ b/crates/ra_hir_ty/src/tests/regression.rs | |||
@@ -2,6 +2,8 @@ use insta::assert_snapshot; | |||
2 | use test_utils::covers; | 2 | use test_utils::covers; |
3 | 3 | ||
4 | use super::infer; | 4 | use super::infer; |
5 | use crate::test_db::TestDB; | ||
6 | use ra_db::fixture::WithFixture; | ||
5 | 7 | ||
6 | #[test] | 8 | #[test] |
7 | fn bug_484() { | 9 | fn bug_484() { |
@@ -399,3 +401,55 @@ fn test() { | |||
399 | "### | 401 | "### |
400 | ); | 402 | ); |
401 | } | 403 | } |
404 | |||
405 | #[test] | ||
406 | fn issue_2683_chars_impl() { | ||
407 | let (db, pos) = TestDB::with_position( | ||
408 | r#" | ||
409 | //- /main.rs crate:main deps:std | ||
410 | fn test() { | ||
411 | let chars: std::str::Chars<'_>; | ||
412 | (chars.next(), chars.nth(1))<|>; | ||
413 | } | ||
414 | |||
415 | //- /std.rs crate:std | ||
416 | #[prelude_import] | ||
417 | use prelude::*; | ||
418 | |||
419 | pub mod prelude { | ||
420 | pub use crate::iter::Iterator; | ||
421 | pub use crate::option::Option; | ||
422 | } | ||
423 | |||
424 | pub mod iter { | ||
425 | pub use self::traits::Iterator; | ||
426 | pub mod traits { | ||
427 | pub use self::iterator::Iterator; | ||
428 | |||
429 | pub mod iterator { | ||
430 | pub trait Iterator { | ||
431 | type Item; | ||
432 | fn next(&mut self) -> Option<Self::Item>; | ||
433 | fn nth(&mut self, n: usize) -> Option<Self::Item> {} | ||
434 | } | ||
435 | } | ||
436 | } | ||
437 | } | ||
438 | |||
439 | pub mod option { | ||
440 | pub enum Option<T> {} | ||
441 | } | ||
442 | |||
443 | pub mod str { | ||
444 | pub struct Chars<'a> {} | ||
445 | impl<'a> Iterator for Chars<'a> { | ||
446 | type Item = char; | ||
447 | fn next(&mut self) -> Option<char> {} | ||
448 | } | ||
449 | } | ||
450 | "#, | ||
451 | ); | ||
452 | |||
453 | // should be Option<char>, but currently not because of Chalk ambiguity problem | ||
454 | assert_eq!("(Option<{unknown}>, Option<{unknown}>)", super::type_at_pos(&db, pos)); | ||
455 | } | ||