// along with GCC; see the file COPYING3. If not see
// <http://www.gnu.org/licenses/>.
-#include "rust-hir-type-check-base.h"
#include "rust-coercion.h"
#include "rust-type-util.h"
rust_debug (
"autoderef type-coercion select autoderefed={%s} can_eq expected={%s}",
autoderefed.debug_str ().c_str (), expected->debug_str ().c_str ());
- if (expected->can_eq (&autoderefed, false))
- {
- try_result = CoercionResult{adjustments, autoderefed.clone ()};
- return true;
- }
- return false;
+
+ TyTy::BaseType *result
+ = unify_site_and (autoderefed.get_ref (), TyTy::TyWithLocation (expected),
+ TyTy::TyWithLocation (&autoderefed),
+ Location () /* locus */, false /*emit_errors*/,
+ false /*commit_if_ok*/, true /*infer*/, true /*cleanup*/);
+ bool ok = result->get_kind () != TyTy::TypeKind::ERROR;
+ if (!ok)
+ return false;
+
+ try_result = CoercionResult{adjustments, autoderefed.clone ()};
+ return true;
}
/// Coercing a mutable reference to an immutable works, while
void
MethodResolver::try_hook (const TyTy::BaseType &r)
{
+ rust_debug ("MethodResolver::try_hook get_predicate_items: [%s]",
+ r.debug_str ().c_str ());
const auto &specified_bounds = r.get_specified_bounds ();
predicate_items = get_predicate_items (segment_name, r, specified_bounds);
+
+ if (predicate_items.size () > 0)
+ return;
+
+ if (r.get_kind () == TyTy::TypeKind::REF)
+ {
+ const auto &ref = static_cast<const TyTy::ReferenceType &> (r);
+ const auto &element = ref.get_var_element_type ();
+ const auto &element_ty = *element.get_tyty ();
+ const auto &specified_bounds = element_ty.get_specified_bounds ();
+ predicate_items
+ = get_predicate_items (segment_name, element_ty, specified_bounds);
+ }
}
bool