diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-06-01 18:03:54 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-06-01 18:03:54 +0100 |
commit | dbdfeeeff91b5e42d8687df09dda1d29f99b34f8 (patch) | |
tree | a9f50b7ff09e286bd2e3939a64ff60cea303720a /crates | |
parent | 4f63e79eb30a0695675a560dfe7ebae6f1dd8a94 (diff) | |
parent | 41321fa71d43244737f29604abc48959ed72e654 (diff) |
Merge #9102
9102: minor: Fall back to legacy prelude r=jonas-schievink a=jonas-schievink
should fix https://github.com/rust-analyzer/rust-analyzer/issues/9101
bors r+
Co-authored-by: Jonas Schievink <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r-- | crates/hir_def/src/nameres/collector.rs | 41 | ||||
-rw-r--r-- | crates/hir_expand/src/name.rs | 1 |
2 files changed, 28 insertions, 14 deletions
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<'_> { | |||
486 | } else { | 486 | } else { |
487 | PathKind::Abs | 487 | PathKind::Abs |
488 | }; | 488 | }; |
489 | let path = | 489 | let path = ModPath::from_segments( |
490 | ModPath::from_segments(path_kind, [krate, name![prelude], edition].iter().cloned()); | 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()); | ||
491 | 497 | ||
492 | let (per_ns, _) = | 498 | for path in &[path, fallback_path] { |
493 | self.def_map.resolve_path(self.db, self.def_map.root, &path, BuiltinShadowMode::Other); | 499 | let (per_ns, _) = self.def_map.resolve_path( |
500 | self.db, | ||
501 | self.def_map.root, | ||
502 | &path, | ||
503 | BuiltinShadowMode::Other, | ||
504 | ); | ||
494 | 505 | ||
495 | match &per_ns.types { | 506 | match &per_ns.types { |
496 | Some((ModuleDefId::ModuleId(m), _)) => { | 507 | Some((ModuleDefId::ModuleId(m), _)) => { |
497 | self.def_map.prelude = Some(*m); | 508 | self.def_map.prelude = Some(*m); |
498 | } | 509 | return; |
499 | _ => { | 510 | } |
500 | log::error!( | 511 | _ => { |
501 | "could not resolve prelude path `{}` to module (resolved to {:?})", | 512 | log::debug!( |
502 | path, | 513 | "could not resolve prelude path `{}` to module (resolved to {:?})", |
503 | per_ns.types | 514 | path, |
504 | ); | 515 | per_ns.types |
516 | ); | ||
517 | } | ||
505 | } | 518 | } |
506 | } | 519 | } |
507 | } | 520 | } |
diff --git a/crates/hir_expand/src/name.rs b/crates/hir_expand/src/name.rs index abc6753bf..00b8adc1e 100644 --- a/crates/hir_expand/src/name.rs +++ b/crates/hir_expand/src/name.rs | |||
@@ -180,6 +180,7 @@ pub mod known { | |||
180 | rust_2015, | 180 | rust_2015, |
181 | rust_2018, | 181 | rust_2018, |
182 | rust_2021, | 182 | rust_2021, |
183 | v1, | ||
183 | // Components of known path (type name) | 184 | // Components of known path (type name) |
184 | Iterator, | 185 | Iterator, |
185 | IntoIterator, | 186 | IntoIterator, |