From 41321fa71d43244737f29604abc48959ed72e654 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Tue, 1 Jun 2021 19:03:00 +0200 Subject: Fall back to legacy prelude --- crates/hir_def/src/nameres/collector.rs | 41 ++++++++++++++++++++++----------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'crates/hir_def/src') diff --git a/crates/hir_def/src/nameres/collector.rs b/crates/hir_def/src/nameres/collector.rs index 598424305..6b41921ae 100644 --- a/crates/hir_def/src/nameres/collector.rs +++ b/crates/hir_def/src/nameres/collector.rs @@ -486,22 +486,35 @@ impl DefCollector<'_> { } else { PathKind::Abs }; - let path = - ModPath::from_segments(path_kind, [krate, name![prelude], edition].iter().cloned()); + let path = ModPath::from_segments( + path_kind.clone(), + [krate.clone(), name![prelude], edition].iter().cloned(), + ); + // Fall back to the older `std::prelude::v1` for compatibility with Rust <1.52.0 + // FIXME remove this fallback + let fallback_path = + ModPath::from_segments(path_kind, [krate, name![prelude], name![v1]].iter().cloned()); - let (per_ns, _) = - self.def_map.resolve_path(self.db, self.def_map.root, &path, BuiltinShadowMode::Other); + for path in &[path, fallback_path] { + let (per_ns, _) = self.def_map.resolve_path( + self.db, + self.def_map.root, + &path, + BuiltinShadowMode::Other, + ); - match &per_ns.types { - Some((ModuleDefId::ModuleId(m), _)) => { - self.def_map.prelude = Some(*m); - } - _ => { - log::error!( - "could not resolve prelude path `{}` to module (resolved to {:?})", - path, - per_ns.types - ); + match &per_ns.types { + Some((ModuleDefId::ModuleId(m), _)) => { + self.def_map.prelude = Some(*m); + return; + } + _ => { + log::debug!( + "could not resolve prelude path `{}` to module (resolved to {:?})", + path, + per_ns.types + ); + } } } } -- cgit v1.2.3