Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/nameres/collector.rs')
| -rw-r--r-- | crates/hir-def/src/nameres/collector.rs | 20 |
1 files changed, 15 insertions, 5 deletions
diff --git a/crates/hir-def/src/nameres/collector.rs b/crates/hir-def/src/nameres/collector.rs index c49bb248a7..64caf26299 100644 --- a/crates/hir-def/src/nameres/collector.rs +++ b/crates/hir-def/src/nameres/collector.rs @@ -291,8 +291,6 @@ impl DefCollector<'_> { let attrs = item_tree.top_level_attrs(self.db, self.def_map.krate); - self.inject_prelude(&attrs); - // Process other crate-level attributes. for attr in &*attrs { if let Some(cfg) = attr.cfg() { @@ -321,6 +319,16 @@ impl DefCollector<'_> { continue; } + if *attr_name == hir_expand::name![no_core] { + self.def_map.no_core = true; + continue; + } + + if *attr_name == hir_expand::name![no_std] { + self.def_map.no_std = true; + continue; + } + if attr_name.as_text().as_deref() == Some("rustc_coherence_is_core") { self.def_map.rustc_coherence_is_core = true; continue; @@ -359,6 +367,8 @@ impl DefCollector<'_> { } } + self.inject_prelude(); + ModCollector { def_collector: self, macro_depth: 0, @@ -517,15 +527,15 @@ impl DefCollector<'_> { } } - fn inject_prelude(&mut self, crate_attrs: &Attrs) { + fn inject_prelude(&mut self) { // See compiler/rustc_builtin_macros/src/standard_library_imports.rs - if crate_attrs.by_key("no_core").exists() { + if self.def_map.no_core { // libcore does not get a prelude. return; } - let krate = if crate_attrs.by_key("no_std").exists() { + let krate = if self.def_map.no_std { name![core] } else { let std = name![std]; |