Skip to content

Commit dbdfeee

Browse files
Merge #9102
9102: minor: Fall back to legacy prelude r=jonas-schievink a=jonas-schievink should fix #9101 bors r+ Co-authored-by: Jonas Schievink <[email protected]>
2 parents 4f63e79 + 41321fa commit dbdfeee

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

crates/hir_def/src/nameres/collector.rs

+27-14
Original file line numberDiff line numberDiff line change
@@ -486,22 +486,35 @@ impl DefCollector<'_> {
486486
} else {
487487
PathKind::Abs
488488
};
489-
let path =
490-
ModPath::from_segments(path_kind, [krate, name![prelude], edition].iter().cloned());
489+
let path = ModPath::from_segments(
490+
path_kind.clone(),
491+
[krate.clone(), name![prelude], edition].iter().cloned(),
492+
);
493+
// Fall back to the older `std::prelude::v1` for compatibility with Rust <1.52.0
494+
// FIXME remove this fallback
495+
let fallback_path =
496+
ModPath::from_segments(path_kind, [krate, name![prelude], name![v1]].iter().cloned());
491497

492-
let (per_ns, _) =
493-
self.def_map.resolve_path(self.db, self.def_map.root, &path, BuiltinShadowMode::Other);
498+
for path in &[path, fallback_path] {
499+
let (per_ns, _) = self.def_map.resolve_path(
500+
self.db,
501+
self.def_map.root,
502+
&path,
503+
BuiltinShadowMode::Other,
504+
);
494505

495-
match &per_ns.types {
496-
Some((ModuleDefId::ModuleId(m), _)) => {
497-
self.def_map.prelude = Some(*m);
498-
}
499-
_ => {
500-
log::error!(
501-
"could not resolve prelude path `{}` to module (resolved to {:?})",
502-
path,
503-
per_ns.types
504-
);
506+
match &per_ns.types {
507+
Some((ModuleDefId::ModuleId(m), _)) => {
508+
self.def_map.prelude = Some(*m);
509+
return;
510+
}
511+
_ => {
512+
log::debug!(
513+
"could not resolve prelude path `{}` to module (resolved to {:?})",
514+
path,
515+
per_ns.types
516+
);
517+
}
505518
}
506519
}
507520
}

crates/hir_expand/src/name.rs

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ pub mod known {
180180
rust_2015,
181181
rust_2018,
182182
rust_2021,
183+
v1,
183184
// Components of known path (type name)
184185
Iterator,
185186
IntoIterator,

0 commit comments

Comments
 (0)