summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2019-11-03 11:59:35 +0800
committerJohn Hodge <tpg@mutabah.net>2019-11-03 11:59:35 +0800
commit56c9b3f6f9c4e9e34477b19b5abf25193dbc3a41 (patch)
treed0b1983ab77eae175086f2587522bddccb47980e /src
parent0a2ea1a773c54c3a4b02edfeb19123aa4224c735 (diff)
downloadmrust-56c9b3f6f9c4e9e34477b19b5abf25193dbc3a41.tar.gz
HIR Expand Closures - Move closure prefix to a common location
Diffstat (limited to 'src')
-rw-r--r--src/hir/type.hpp4
-rw-r--r--src/hir_expand/closures.cpp6
-rw-r--r--src/trans/auto_impls.cpp3
-rw-r--r--src/trans/enumerate.cpp2
4 files changed, 8 insertions, 7 deletions
diff --git a/src/hir/type.hpp b/src/hir/type.hpp
index cbc2e94a..f499c73f 100644
--- a/src/hir/type.hpp
+++ b/src/hir/type.hpp
@@ -17,6 +17,8 @@
/// Binding index for a Generic that indicates "Self"
#define GENERIC_Self 0xFFFF
+constexpr const char* CLOSURE_PATH_PREFIX = "closure#";
+
namespace HIR {
class TraitMarkings;
@@ -209,7 +211,7 @@ public:
bool is_closure() const {
return path.m_data.is_Generic()
&& path.m_data.as_Generic().m_path.m_components.back().size() > 8
- && path.m_data.as_Generic().m_path.m_components.back().compare(0,8, "closure#") == 0
+ && path.m_data.as_Generic().m_path.m_components.back().compare(0,strlen(CLOSURE_PATH_PREFIX), CLOSURE_PATH_PREFIX) == 0
;
}
}),
diff --git a/src/hir_expand/closures.cpp b/src/hir_expand/closures.cpp
index c53396a0..a6b404ff 100644
--- a/src/hir_expand/closures.cpp
+++ b/src/hir_expand/closures.cpp
@@ -1261,7 +1261,7 @@ namespace {
::HIR::SimplePath root_mod_path(crate.m_crate_name,{});
m_cur_mod_path = &root_mod_path;
m_new_type = [&](const char* suffix, auto s)->auto {
- auto name = RcString::new_interned(FMT("closure#I_" << closure_count));
+ auto name = RcString::new_interned(FMT(CLOSURE_PATH_PREFIX << "I_" << closure_count));
closure_count += 1;
auto boxed = box$(( ::HIR::VisEnt< ::HIR::TypeItem> { ::HIR::Publicity::new_none(), ::HIR::TypeItem( mv$(s) ) } ));
auto* ret_ptr = &boxed->ent.as_Struct();
@@ -1287,7 +1287,7 @@ namespace {
auto saved_nt = mv$(m_new_type);
m_new_type = [&](const char* suffix, auto s)->auto {
// TODO: Use a function on `mod` that adds a closure and makes the indexes be per suffix
- auto name = RcString( FMT("closure#" << suffix << (suffix[0] ? "_" : "") << closure_count) );
+ auto name = RcString( FMT(CLOSURE_PATH_PREFIX << suffix << (suffix[0] ? "_" : "") << closure_count) );
closure_count += 1;
auto boxed = box$( (::HIR::VisEnt< ::HIR::TypeItem> { ::HIR::Publicity::new_none(), ::HIR::TypeItem( mv$(s) ) }) );
auto* ret_ptr = &boxed->ent.as_Struct();
@@ -1437,7 +1437,7 @@ void HIR_Expand_Closures_Expr(const ::HIR::Crate& crate_ro, ::HIR::ExprPtr& exp)
static int closure_count = 0;
out_impls_t new_trait_impls;
new_type_cb_t new_type_cb = [&](const char* suffix, auto s)->auto {
- auto name = RcString::new_interned(FMT("closure#C_" << closure_count));
+ auto name = RcString::new_interned(FMT(CLOSURE_PATH_PREFIX << "C_" << closure_count));
closure_count += 1;
auto boxed = box$(( ::HIR::VisEnt< ::HIR::TypeItem> { ::HIR::Publicity::new_none(), ::HIR::TypeItem( mv$(s) ) } ));
auto* ret_ptr = &boxed->ent.as_Struct();
diff --git a/src/trans/auto_impls.cpp b/src/trans/auto_impls.cpp
index 71f95a26..67a9e7c1 100644
--- a/src/trans/auto_impls.cpp
+++ b/src/trans/auto_impls.cpp
@@ -109,8 +109,7 @@ void Trans_AutoImpl_Clone(State& state, ::HIR::TypeRef ty)
default:
TODO(sp, "auto Clone for " << ty << " - Unknown and not Copy");
TU_ARMA(Path, te) {
- // closures are identified by the name starting with 'closure#'
- if( TU_TEST1(te.path.m_data, Generic, .m_path.m_components.back().compare(0, 8, "closure#") == 0) ) {
+ if( te.is_closure() ) {
const auto& gp = te.path.m_data.as_Generic();
const auto& str = state.resolve.m_crate.get_struct_by_path(sp, gp.m_path);
Trans_Params p;
diff --git a/src/trans/enumerate.cpp b/src/trans/enumerate.cpp
index d8426022..34d18781 100644
--- a/src/trans/enumerate.cpp
+++ b/src/trans/enumerate.cpp
@@ -1447,7 +1447,7 @@ void Trans_Enumerate_FillFrom_PathMono(EnumState& state, ::HIR::Path path_mono)
else if( const auto* te = inner_ty.m_data.opt_Array() ) {
enum_impl(*te->inner);
}
- else if( TU_TEST2(inner_ty.m_data, Path, .path.m_data, Generic, .m_path.m_components.back().compare(0, 8, "closure#") == 0) ) {
+ else if( TU_TEST1(inner_ty.m_data, Path, .is_closure()) ) {
const auto& gp = inner_ty.m_data.as_Path().path.m_data.as_Generic();
const auto& str = state.crate.get_struct_by_path(sp, gp.m_path);
Trans_Params p;