diff options
author | John Hodge <tpg@mutabah.net> | 2016-10-22 10:31:16 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-10-22 16:00:27 +0800 |
commit | 5a20d91b53d7889a5be8ed9dabeccbac0371f121 (patch) | |
tree | e66c887acbb3f15ee560851792f964939ade8470 | |
parent | e29fa8f3a2b429ed2da10bd941c52cb80c8bc859 (diff) | |
download | mrust-5a20d91b53d7889a5be8ed9dabeccbac0371f121.tar.gz |
Expand - #[prelude_import] support
-rw-r--r-- | src/expand/std_prelude.cpp | 20 | ||||
-rw-r--r-- | src/resolve/index.cpp | 7 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/expand/std_prelude.cpp b/src/expand/std_prelude.cpp index 4499dc6d..81eecf7f 100644 --- a/src/expand/std_prelude.cpp +++ b/src/expand/std_prelude.cpp @@ -52,11 +52,29 @@ public: } }; +class Decorator_PreludeImport: + public ExpandDecorator +{ +public: + AttrStage stage() const override { return AttrStage::Post; } + + void handle(const Span& sp, const AST::MetaItem& mi, ::AST::Crate& crate, const AST::Path& path, AST::Module& mod, AST::Item&i) const override { + if( i.is_Use() ) { + const auto& p = i.as_Use().path; + // TODO: Ensure that this statement is a glob (has a name of "") + crate.m_prelude_path = AST::Path(p); + } + else { + ERROR(sp, E0000, "Invalid use of #[no_prelude] on non-module"); + } + } +}; STATIC_DECORATOR("no_std", Decorator_NoStd) STATIC_DECORATOR("no_core", Decorator_NoCore) -//STATIC_DECORATOR("prelude", Decorator_Prelude) +//STATIC_DECORATOR("prelude", Decorator_Prelude) // mrustc +STATIC_DECORATOR("prelude_import", Decorator_PreludeImport) // rustc STATIC_DECORATOR("no_prelude", Decorator_NoPrelude) diff --git a/src/resolve/index.cpp b/src/resolve/index.cpp index 39ae4ff2..66a9ec3d 100644 --- a/src/resolve/index.cpp +++ b/src/resolve/index.cpp @@ -404,11 +404,12 @@ void Resolve_Index_Module_Wildcard(AST::Crate& crate, AST::Module& mod, bool han const auto& hmod = *e.hir; Resolve_Index_Module_Wildcard__glob_in_hir_mod(sp, crate, mod, hmod, i_data.path, i.is_pub); } + else if( e.module_ == &mod ) { + // NOTE: Happens in libcore's prelude due to `#[prelude_import] use prelude::v1::*; + //ERROR(sp, E0000, "Glob import of self"); + } else { - if( e.module_ == &mod ) { - ERROR(sp, E0000, "Glob import of self"); - } // 1. Begin indexing of this module if it is not already indexed assert( e.module_->m_index_populated != 0 ); if( e.module_->m_index_populated == 1 ) |