Refactor cast_site to be a simple function in rust-type-util.h.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::cast_site):
Remove cast_site.
* typecheck/rust-hir-type-check-base.h: Remove cast_site
prototype.
* typecheck/rust-type-util.cc (cast_site): Add cast_site.
* typecheck/rust-type-util.h (cast_site): Add cast_site
prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
// <http://www.gnu.org/licenses/>.
#include "rust-hir-type-check-base.h"
-#include "rust-casts.h"
#include "rust-hir-type-check-expr.h"
#include "rust-hir-type-check-implitem.h"
#include "rust-hir-type-check-item.h"
return repr;
}
-TyTy::BaseType *
-TypeCheckBase::cast_site (HirId id, TyTy::TyWithLocation from,
- TyTy::TyWithLocation to, Location cast_locus)
-{
- rust_debug ("cast_site id={%u} from={%s} to={%s}", id,
- from.get_ty ()->debug_str ().c_str (),
- to.get_ty ()->debug_str ().c_str ());
-
- auto context = TypeCheckContext::get ();
- if (from.get_ty ()->get_kind () == TyTy::TypeKind::ERROR
- || to.get_ty ()->get_kind () == TyTy::TypeKind::ERROR)
- return to.get_ty ();
-
- // do the cast
- auto result = TypeCastRules::resolve (cast_locus, from, to);
-
- // we assume error has already been emitted
- if (result.is_error ())
- return to.get_ty ();
-
- // the result needs to be unified
- TyTy::BaseType *casted_result = result.tyty;
- rust_debug ("cast_default_unify(a={%s}, b={%s})",
- casted_result->debug_str ().c_str (),
- to.get_ty ()->debug_str ().c_str ());
-
- TyTy::BaseType *casted
- = unify_site (id, to,
- TyTy::TyWithLocation (casted_result, from.get_locus ()),
- cast_locus);
- context->insert_cast_autoderef_mappings (id, std::move (result.adjustments));
- return casted;
-}
-
void
TypeCheckBase::resolve_generic_params (
const std::vector<std::unique_ptr<HIR::GenericParam> > &generic_params,
public:
virtual ~TypeCheckBase () {}
- static TyTy::BaseType *cast_site (HirId id, TyTy::TyWithLocation from,
- TyTy::TyWithLocation to,
- Location cast_locus);
-
protected:
TypeCheckBase ();
#include "rust-hir-type-check.h"
#include "rust-hir-visitor.h"
#include "rust-name-resolver.h"
+#include "rust-casts.h"
#include "rust-unify.h"
#include "rust-coercion.h"
return coerced;
}
+TyTy::BaseType *
+cast_site (HirId id, TyTy::TyWithLocation from, TyTy::TyWithLocation to,
+ Location cast_locus)
+{
+ rust_debug ("cast_site id={%u} from={%s} to={%s}", id,
+ from.get_ty ()->debug_str ().c_str (),
+ to.get_ty ()->debug_str ().c_str ());
+
+ auto context = TypeCheckContext::get ();
+ if (from.get_ty ()->get_kind () == TyTy::TypeKind::ERROR
+ || to.get_ty ()->get_kind () == TyTy::TypeKind::ERROR)
+ return to.get_ty ();
+
+ // do the cast
+ auto result = TypeCastRules::resolve (cast_locus, from, to);
+
+ // we assume error has already been emitted
+ if (result.is_error ())
+ return to.get_ty ();
+
+ // the result needs to be unified
+ TyTy::BaseType *casted_result = result.tyty;
+ rust_debug ("cast_default_unify(a={%s}, b={%s})",
+ casted_result->debug_str ().c_str (),
+ to.get_ty ()->debug_str ().c_str ());
+
+ TyTy::BaseType *casted
+ = unify_site (id, to,
+ TyTy::TyWithLocation (casted_result, from.get_locus ()),
+ cast_locus);
+ context->insert_cast_autoderef_mappings (id, std::move (result.adjustments));
+ return casted;
+}
+
} // namespace Resolver
} // namespace Rust
coercion_site (HirId id, TyTy::TyWithLocation lhs, TyTy::TyWithLocation rhs,
Location coercion_locus);
+TyTy::BaseType *
+cast_site (HirId id, TyTy::TyWithLocation from, TyTy::TyWithLocation to,
+ Location cast_locus);
+
} // namespace Resolver
} // namespace Rust