summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ast/crate.cpp23
-rw-r--r--src/expand/mod.cpp5
2 files changed, 25 insertions, 3 deletions
diff --git a/src/ast/crate.cpp b/src/ast/crate.cpp
index 49f9242f..fc93a809 100644
--- a/src/ast/crate.cpp
+++ b/src/ast/crate.cpp
@@ -56,6 +56,29 @@ void Crate::load_externs()
}
};
iterate_module(m_root_module, cb);
+
+ // Check for no_std or no_core, and load libstd/libcore
+ // - Duplicates some of the logic in "Expand", but also helps keep crate loading separate to most of expand
+ bool no_std = false;
+ bool no_core = false;
+
+ for( const auto& a : this->m_attrs.m_items )
+ {
+ if( a.name() == "no_std" )
+ no_std = true;
+ if( a.name() == "no_core" )
+ no_core = true;
+ }
+
+ if( no_core ) {
+ // Don't load anything
+ }
+ else if( no_std ) {
+ this->load_extern_crate(Span(), "core");
+ }
+ else {
+ this->load_extern_crate(Span(), "std");
+ }
}
void Crate::load_extern_crate(Span sp, const ::std::string& name)
{
diff --git a/src/expand/mod.cpp b/src/expand/mod.cpp
index a3600ce5..e6d5d60e 100644
--- a/src/expand/mod.cpp
+++ b/src/expand/mod.cpp
@@ -938,13 +938,13 @@ void Expand(::AST::Crate& crate)
// 1. Crate attributes
Expand_Attrs(crate.m_attrs, AttrStage::EarlyPre, [&](const auto& sp, const auto& d, const auto& a){ d.handle(sp, a, crate); });
- // Load libstd/libcore
+ // Insert magic for libstd/libcore
+ // NOTE: The actual crates are loaded in "LoadCrates" using magic in AST::Crate::load_externs
switch( crate.m_load_std )
{
case ::AST::Crate::LOAD_STD:
if( crate.m_prelude_path == AST::Path() )
crate.m_prelude_path = AST::Path("std", {AST::PathNode("prelude"), AST::PathNode("v1")});
- crate.load_extern_crate(Span(), "std");
crate.m_extern_crates.at("std").with_all_macros([&](const auto& name, const auto& mac) {
crate.m_root_module.add_macro_import( name, mac );
});
@@ -953,7 +953,6 @@ void Expand(::AST::Crate& crate)
case ::AST::Crate::LOAD_CORE:
if( crate.m_prelude_path == AST::Path() )
crate.m_prelude_path = AST::Path("core", {AST::PathNode("prelude"), AST::PathNode("v1")});
- crate.load_extern_crate(Span(), "core");
crate.m_extern_crates.at("core").with_all_macros([&](const auto& name, const auto& mac) {
crate.m_root_module.add_macro_import( name, mac );
});