summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-09-11 18:23:24 +0800
committerJohn Hodge <tpg@mutabah.net>2016-09-11 18:23:24 +0800
commit058047f175ba166764a77956542bec786d59d21a (patch)
tree89de69d676d34185000e804a09dd0122b66acb2d /src
parenta98cb27dedfe3b5005ac2d7b6d876ced4b4b6fc7 (diff)
downloadmrust-058047f175ba166764a77956542bec786d59d21a.tar.gz
Resolve Absolute - Support path splitting based on HIR traits
Diffstat (limited to 'src')
-rw-r--r--src/resolve/absolute.cpp30
-rw-r--r--src/resolve/use.cpp2
2 files changed, 23 insertions, 9 deletions
diff --git a/src/resolve/absolute.cpp b/src/resolve/absolute.cpp
index d6159dd3..874664dd 100644
--- a/src/resolve/absolute.cpp
+++ b/src/resolve/absolute.cpp
@@ -990,7 +990,7 @@ void Resolve_Absolute_Path_BindAbsolute(Context& context, const Span& sp, Contex
return ;
),
(Trait,
- assert( e.trait_ );
+ assert( e.trait_ || e.hir );
auto trait_path = ::AST::Path(name_ref.path);
if( !n.args().is_empty() ) {
trait_path.nodes().back().args() = mv$(n.args());
@@ -999,16 +999,30 @@ void Resolve_Absolute_Path_BindAbsolute(Context& context, const Span& sp, Contex
// - What if this item is from a nested trait?
::AST::Path new_path;
bool found = false;
- //switch(mode)
- //{
- //case Context::LookupMode::Value: {
- assert(i+1 < path_abs.nodes.size());
- auto it = ::std::find_if( e.trait_->items().begin(), e.trait_->items().end(), [&](const auto& x){ return x.name == path_abs.nodes[i+1].name(); } );
+ assert(i+1 < path_abs.nodes.size());
+ const auto& item_name = path_abs.nodes[i+1].name();
+ if( e.trait_ )
+ {
+ auto it = ::std::find_if( e.trait_->items().begin(), e.trait_->items().end(), [&](const auto& x){ return x.name == item_name; } );
if( it != e.trait_->items().end() ) {
found = true;
}
- // } break;
- //}
+ }
+ else
+ {
+ switch(mode)
+ {
+ case Context::LookupMode::Constant:
+ case Context::LookupMode::Pattern:
+ case Context::LookupMode::Variable:
+ found = (e.hir->m_values.count(item_name) != 0);
+ break;
+ case Context::LookupMode::Namespace:
+ case Context::LookupMode::Type:
+ found = (e.hir->m_types.count(item_name) != 0);
+ break;
+ }
+ }
if( !found ) {
new_path = ::AST::Path(::AST::Path::TagUfcs(), ::TypeRef(sp, mv$(trait_path)));
}
diff --git a/src/resolve/use.cpp b/src/resolve/use.cpp
index f7d9442c..a5fcec90 100644
--- a/src/resolve/use.cpp
+++ b/src/resolve/use.cpp
@@ -440,7 +440,7 @@ void Resolve_Use_Mod(const ::AST::Crate& crate, ::AST::Module& mod, ::AST::Path
return ::AST::PathBinding::make_Struct({nullptr, &e});
),
(Trait,
- return ::AST::PathBinding::make_Trait({nullptr});
+ return ::AST::PathBinding::make_Trait({nullptr, &e});
)
)
}