From 5a20d91b53d7889a5be8ed9dabeccbac0371f121 Mon Sep 17 00:00:00 2001 From: John Hodge Date: Sat, 22 Oct 2016 10:31:16 +0800 Subject: Expand - #[prelude_import] support --- src/expand/std_prelude.cpp | 20 +++++++++++++++++++- 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 ) -- cgit v1.2.3