aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
diff options
context:
space:
mode:
authorbl7awy <mahadelr19@gmail.com>2023-02-28 20:53:01 +0300
committerArthur Cohen <arthur.cohen@embecosm.com>2024-01-16 18:19:01 +0100
commit525110ae4951fcc1ca3e858d6afa23823b79b8f0 (patch)
treee3f5552c614c3b25c17e8881dd37bc0abbce17c8 /gcc/rust
parent8a8436aa6a63dbfdee6c18f2b9533720b83f2624 (diff)
downloadgcc-525110ae4951fcc1ca3e858d6afa23823b79b8f0.zip
gcc-525110ae4951fcc1ca3e858d6afa23823b79b8f0.tar.gz
gcc-525110ae4951fcc1ca3e858d6afa23823b79b8f0.tar.bz2
gccrs: typecheck: Fix casting error behind generics
gcc/rust/ChangeLog: * typecheck/rust-casts.cc (TypeCastRules::cast_rules): Perform destructure on `from` type. gcc/testsuite/ChangeLog: * rust/compile/cast_generics.rs: New test. Signed-off-by: Mahmoud Mohamed <mahadelr19@gmail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r--gcc/rust/typecheck/rust-casts.cc11
1 files changed, 6 insertions, 5 deletions
diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc
index 269d344..bbcd846 100644
--- a/gcc/rust/typecheck/rust-casts.cc
+++ b/gcc/rust/typecheck/rust-casts.cc
@@ -60,15 +60,16 @@ TypeCastRules::cast_rules ()
// https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/cast.rs#L596
// https://github.com/rust-lang/rust/blob/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/compiler/rustc_typeck/src/check/cast.rs#L654
- rust_debug ("cast_rules from={%s} to={%s}",
- from.get_ty ()->debug_str ().c_str (),
+ TyTy::BaseType *from_type = from.get_ty ()->destructure ();
+
+ rust_debug ("cast_rules from={%s} to={%s}", from_type->debug_str ().c_str (),
to.get_ty ()->debug_str ().c_str ());
- switch (from.get_ty ()->get_kind ())
+ switch (from_type->get_kind ())
{
case TyTy::TypeKind::INFER: {
TyTy::InferType *from_infer
- = static_cast<TyTy::InferType *> (from.get_ty ());
+ = static_cast<TyTy::InferType *> (from_type);
switch (from_infer->get_infer_kind ())
{
case TyTy::InferType::InferTypeKind::GENERAL:
@@ -290,4 +291,4 @@ TypeCastRules::emit_cast_error () const
}
} // namespace Resolver
-} // namespace Rust
+} // namespace Rust \ No newline at end of file