summaryrefslogtreecommitdiff
path: root/src/hir_typeck
diff options
context:
space:
mode:
authorJohn Hodge <tpg@ucc.asn.au>2017-05-26 14:52:11 +0800
committerJohn Hodge <tpg@ucc.asn.au>2017-05-26 14:52:11 +0800
commit1ca60578426833dfcfda6ecfa7ef67e31f5d6a85 (patch)
tree322525df5c3d0f4a53ad66cffd24df1ba6b21d96 /src/hir_typeck
parent1b8e9e01a8ebce42e8ad3dca101180430b28c947 (diff)
downloadmrust-1ca60578426833dfcfda6ecfa7ef67e31f5d6a85.tar.gz
Typecheck Expr - Fix a place where literals can become trait objects
Diffstat (limited to 'src/hir_typeck')
-rw-r--r--src/hir_typeck/expr_cs.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/hir_typeck/expr_cs.cpp b/src/hir_typeck/expr_cs.cpp
index 5c69e20b..ac2cf511 100644
--- a/src/hir_typeck/expr_cs.cpp
+++ b/src/hir_typeck/expr_cs.cpp
@@ -4214,16 +4214,29 @@ namespace {
// If the source is '_', we can't know yet
TU_IFLET(::HIR::TypeRef::Data, ty_src.m_data, Infer, r_e,
- // TODO: If the source is a literal, and the destination isn't a TraitObject, equate.
- // - Except if it's known to be a primitive
- //if( r_e.ty_class != ::HIR::InferClass::None ) {
- // context.equate_types(sp, ty_dst, ty_src);
- // return true;
- //}
- context.possible_equate_type_unsize_to(r_e.index, ty_dst);
- DEBUG("- Infer, add possibility");
- return false;
+ // No avaliable information, add a possible unsize
+ if( r_e.ty_class == ::HIR::InferClass::None || r_e.ty_class == ::HIR::InferClass::Diverge )
+ {
+ // Possibility
+ context.possible_equate_type_unsize_to(r_e.index, ty_dst);
+ DEBUG("- Infer, add possibility");
+ return false;
+ }
+ // Destination is infer, fall through to next TU_IFLET
+ else if( ty_dst.m_data.is_Infer() )
+ {
+ }
+ // Destination is a TraitObject, fall through to doing an impl search
+ else if( ty_dst.m_data.is_TraitObject() )
+ {
+ }
+ // Otherwise, they have to be equal
+ else
+ {
+ context.equate_types(sp, ty_dst, ty_src);
+ return true;
+ }
)
TU_IFLET(::HIR::TypeRef::Data, ty_dst.m_data, Infer, l_e,