From 9dc1826cfaa75983a83f9eb7f788067d5dedf5a7 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 11 Jan 2020 23:19:58 +0100 Subject: 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. --- crates/ra_hir_def/src/nameres/collector.rs | 2 +- .../ra_hir_def/src/nameres/tests/mod_resolution.rs | 45 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) (limited to 'crates/ra_hir_def') 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 ); let def = res.resolved_def; - if res.reached_fixedpoint == ReachedFixedPoint::No { + if res.reached_fixedpoint == ReachedFixedPoint::No || def.is_none() { return PartialResolvedImport::Unresolved; } 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 @@ -52,6 +52,51 @@ fn nested_module_resolution() { "###); } +#[test] +fn nested_module_resolution_2() { + let map = def_map( + " + //- /lib.rs + mod prelude; + mod iter; + + //- /prelude.rs + pub use crate::iter::Iterator; + + //- /iter.rs + pub use self::traits::Iterator; + mod traits; + + //- /iter/traits.rs + pub use self::iterator::Iterator; + mod iterator; + + //- /iter/traits/iterator.rs + pub trait Iterator; + ", + ); + + assert_snapshot!(map, @r###" + crate + iter: t + prelude: t + + crate::iter + Iterator: t + traits: t + + crate::iter::traits + Iterator: t + iterator: t + + crate::iter::traits::iterator + Iterator: t + + crate::prelude + Iterator: t + "###); +} + #[test] fn module_resolution_works_for_non_standard_filenames() { let map = def_map( -- cgit v1.2.3