summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Hodge <tpg@mutabah.net>2016-09-28 16:27:08 +0800
committerJohn Hodge <tpg@mutabah.net>2016-09-28 16:27:08 +0800
commit17259a289ff52ce6028ac78b107d0d697a9cf478 (patch)
tree6e14139d55573500a117d4e6117db8d19d3b5305 /src
parent4365dfae754e9687ff8c3d25294e7b8d89ffdc0e (diff)
downloadmrust-17259a289ff52ce6028ac78b107d0d697a9cf478.tar.gz
macro_rules - Defensive code and fix bug causing empty captures to no report empty
Diffstat (limited to 'src')
-rw-r--r--src/macro_rules/eval.cpp14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/macro_rules/eval.cpp b/src/macro_rules/eval.cpp
index f572bb15..109e2c43 100644
--- a/src/macro_rules/eval.cpp
+++ b/src/macro_rules/eval.cpp
@@ -166,6 +166,7 @@ void Macro_InvokeRules_CountSubstUses(ParameterMappings& bound_tts, const ::std:
void ParameterMappings::insert(unsigned int name_index, const ::std::vector<unsigned int>& iterations, InterpolatedFragment data)
{
+ DEBUG("index="<<name_index << ", iterations=[" << iterations << "], data="<<data);
if( name_index >= m_mappings.size() ) {
m_mappings.resize( name_index + 1 );
}
@@ -216,16 +217,21 @@ ParameterMappings::CapturedVal& ParameterMappings::get_cap(const ::std::vector<u
if( e.size() == 1 ) {
return e[0];
}
+ if( e.size() == 0 ) {
+ BUG(Span(), "Attempting to get binding for empty capture - #" << name_idx);
+ }
)
for(const auto iter : iterations)
{
TU_MATCH(CaptureLayer, (*layer), (e),
(Vals,
- return e[iter];
+ ASSERT_BUG(Span(), iter < e.size(), "Iteration index " << iter << " outside of range " << e.size() << " (values)");
+ return e.at(iter);
),
(Nested,
- layer = &e[iter];
+ ASSERT_BUG(Span(), iter < e.size(), "Iteration index " << iter << " outside of range " << e.size() << " (nest)");
+ layer = &e.at(iter);
)
)
}
@@ -245,6 +251,10 @@ unsigned int ParameterMappings::count_in(const ::std::vector<unsigned int>& iter
return 0;
}
auto& e = m_mappings.at(name_idx);
+ if( e.top_layer.is_Vals() && e.top_layer.as_Vals().size() == 0 ) {
+ DEBUG("- Not populated");
+ return 0;
+ }
auto* layer = &e.top_layer;
for(const auto iter : iterations)
{