public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Thomas Schwinge <tschwinge@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/rust/master] typecheck: Fix casting error behind generics Date: Sun, 5 Mar 2023 11:40:58 +0000 (GMT) [thread overview] Message-ID: <20230305114058.F333B3858D38@sourceware.org> (raw) https://gcc.gnu.org/g:193c21c85b4b3f603b1b6280779c758d35570446 commit 193c21c85b4b3f603b1b6280779c758d35570446 Author: bl7awy <mahadelr19@gmail.com> Date: Tue Feb 28 20:53:01 2023 +0300 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> Diff: --- gcc/rust/typecheck/rust-casts.cc | 11 ++++++----- gcc/testsuite/rust/compile/cast_generics.rs | 8 ++++++++ 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/gcc/rust/typecheck/rust-casts.cc b/gcc/rust/typecheck/rust-casts.cc index 0ecb50f7d1d..f41c7134a75 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 diff --git a/gcc/testsuite/rust/compile/cast_generics.rs b/gcc/testsuite/rust/compile/cast_generics.rs new file mode 100644 index 00000000000..7d185964e50 --- /dev/null +++ b/gcc/testsuite/rust/compile/cast_generics.rs @@ -0,0 +1,8 @@ +fn test<T>(a: T) -> T { + a +} + +fn main() { + let t: i32 = test(123 as i32) as i32; + // { dg-warning "unused name" "" { target *-*-* } .-1 } +}
reply other threads:[~2023-03-05 11:40 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20230305114058.F333B3858D38@sourceware.org \ --to=tschwinge@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).