Skip to content

Fix casting error behind generics #1938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 1, 2023
Merged

Conversation

goar5670
Copy link
Contributor

@goar5670 goar5670 commented Feb 28, 2023

Fixes #1897

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.

@goar5670 goar5670 force-pushed the master branch 3 times, most recently from b1bb4fc to 2afdec8 Compare February 28, 2023 18:49
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You found the right fix I think a small tweak to call restructure once would be ideal here. I also think this should be squashed into 1 commit.

Otherwise great job.

@@ -63,11 +63,11 @@ TypeCastRules::cast_rules ()
from.get_ty ()->debug_str ().c_str (),
to.get_ty ()->debug_str ().c_str ());

switch (from.get_ty ()->get_kind ())
switch (from.get_ty ()->destructure ()->get_kind ())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better to do something like the unify code over in rust-unify.cc UnifyRules::go

TyTy::BaseType *
UnifyRules::go ()
{
  TyTy::BaseType *ltype = lhs.get_ty ();
  TyTy::BaseType *rtype = rhs.get_ty ();

  ltype = lhs.get_ty ()->destructure ();
  rtype = rhs.get_ty ()->destructure ();

So that you only need to call it once and it doesn't get lost.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Edited it, please take another look.

@philberty
Copy link
Member

Just so you know i would really like to merge this soon because I want to work on #1898 tomorrow

@philberty
Copy link
Member

If your having problems with the git commit format checker you can run the checker locally via:

python3 contrib/gcc-changelog/git_check_commit.py origin/master..HEAD
Checking ed45b943a1fee3310fea361c6e127f5a60ae6d22: OK
Checking 27c4590301a3da7d62d5b7e5a88cdbdc8de23070: OK
Checking 5c9a0e4a49f23f277652af6d1cc8173bc255ad44: OK
Checking d5397d90190d4a4d13c688815924b0a9439f3a98: OK
Checking 92d31693da5401291db6f667d9997a889bf0ea8a: OK
Checking 48c65d249e3fdabdac0947226f375cf911529c6b: OK
Checking 4ae86b6ce74474e65da436ab92bcd9b87ed1833b: OK
Checking fa9c51aa8d435b953c58f0ba2db3a339cd9c6f59: OK
Checking a44cf951951d6a0c747a18b3d7c71d1bb96134e6: OK
Checking b6a8e19529614610519ab97d1afa7e5cd214a2a9: OK

@goar5670 goar5670 force-pushed the master branch 3 times, most recently from 4003c26 to 4be2d6c Compare February 28, 2023 21:17
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  <[email protected]>
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM good work

@philberty philberty added this pull request to the merge queue Mar 1, 2023
Merged via the queue into Rust-GCC:master with commit 193c21c Mar 1, 2023
@goar5670 goar5670 changed the title Fix casting error behind generics [WIP] Fix casting error behind generics Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Bad cast error when behind generics
2 participants