diff options
author | John Hodge <tpg@mutabah.net> | 2016-12-15 19:08:09 +0800 |
---|---|---|
committer | John Hodge <tpg@mutabah.net> | 2016-12-15 19:08:09 +0800 |
commit | 2e361f85d70fbc07321c50c292b00ffacd095e1e (patch) | |
tree | ab3f0babdfc680ad5f422132457ee5258e445a45 /src | |
parent | e91aec61b780eb166fd1813a3fe7484574f3155e (diff) | |
download | mrust-2e361f85d70fbc07321c50c292b00ffacd095e1e.tar.gz |
MIR Const Eval - Handle borrows of statics
Diffstat (limited to 'src')
-rw-r--r-- | src/hir_expand/const_eval_full.cpp | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/src/hir_expand/const_eval_full.cpp b/src/hir_expand/const_eval_full.cpp index 3f7e7a81..614e36fa 100644 --- a/src/hir_expand/const_eval_full.cpp +++ b/src/hir_expand/const_eval_full.cpp @@ -340,16 +340,16 @@ namespace { return retval; ), (Field, - TODO(sp, "LValue::Field"); + TODO(sp, "LValue::Field - " << lv); ), (Deref, - TODO(sp, "LValue::Deref"); + TODO(sp, "LValue::Deref - " << lv); ), (Index, - TODO(sp, "LValue::Index"); + TODO(sp, "LValue::Index - " << lv); ), (Downcast, - TODO(sp, "LValue::Downcast"); + TODO(sp, "LValue::Downcast - " << lv); ) ) throw ""; @@ -450,16 +450,22 @@ namespace { MIR_BUG(state, "Only shared borrows are allowed in constants"); } - auto inner_val = read_lval(e.val); - - ::HIR::TypeRef inner_ty; - const auto& inner_ty_r = state.get_lvalue_type(inner_ty, e.val); - if( &inner_ty_r != &inner_ty ) - inner_ty = inner_ty_r.clone(); - - // Create new static containing borrowed data - auto item_path = newval_state.new_static( mv$(inner_ty), mv$(inner_val) ); - val = ::HIR::Literal::make_BorrowOf( mv$(item_path) ); + if( e.val.is_Static() ) { + // Borrow of a static, emit BorrowOf with the same path + val = ::HIR::Literal::make_BorrowOf( e.val.as_Static().clone() ); + } + else { + auto inner_val = read_lval(e.val); + + ::HIR::TypeRef inner_ty; + const auto& inner_ty_r = state.get_lvalue_type(inner_ty, e.val); + if( &inner_ty_r != &inner_ty ) + inner_ty = inner_ty_r.clone(); + + // Create new static containing borrowed data + auto item_path = newval_state.new_static( mv$(inner_ty), mv$(inner_val) ); + val = ::HIR::Literal::make_BorrowOf( mv$(item_path) ); + } ), (Cast, auto inval = read_lval(e.val); |