Fall back to legacy prelude

This commit is contained in:
Jonas Schievink 2021-06-01 19:03:00 +02:00
parent 4f63e79eb3
commit 41321fa71d
2 changed files with 28 additions and 14 deletions

View File

@ -486,22 +486,35 @@ fn inject_prelude(&mut self, crate_attrs: &Attrs) {
} else { } else {
PathKind::Abs PathKind::Abs
}; };
let path = let path = ModPath::from_segments(
ModPath::from_segments(path_kind, [krate, name![prelude], edition].iter().cloned()); 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, _) = for path in &[path, fallback_path] {
self.def_map.resolve_path(self.db, self.def_map.root, &path, BuiltinShadowMode::Other); let (per_ns, _) = self.def_map.resolve_path(
self.db,
self.def_map.root,
&path,
BuiltinShadowMode::Other,
);
match &per_ns.types { match &per_ns.types {
Some((ModuleDefId::ModuleId(m), _)) => { Some((ModuleDefId::ModuleId(m), _)) => {
self.def_map.prelude = Some(*m); self.def_map.prelude = Some(*m);
} return;
_ => { }
log::error!( _ => {
"could not resolve prelude path `{}` to module (resolved to {:?})", log::debug!(
path, "could not resolve prelude path `{}` to module (resolved to {:?})",
per_ns.types path,
); per_ns.types
);
}
} }
} }
} }

View File

@ -180,6 +180,7 @@ macro_rules! known_names {
rust_2015, rust_2015,
rust_2018, rust_2018,
rust_2021, rust_2021,
v1,
// Components of known path (type name) // Components of known path (type name)
Iterator, Iterator,
IntoIterator, IntoIterator,