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] gccrs: Fix ICE during method resolution
Date: Tue,  2 May 2023 07:10:33 +0000 (GMT)	[thread overview]
Message-ID: <20230502071033.7395A3858C83@sourceware.org> (raw)

https://gcc.gnu.org/g:ddcd571a67fb205f7e168a3c3cd4e63080ed026b

commit ddcd571a67fb205f7e168a3c3cd4e63080ed026b
Author: Philip Herron <herron.philip@googlemail.com>
Date:   Thu Apr 20 12:44:31 2023 +0100

    gccrs: Fix ICE during method resolution
    
    We were missing a check for trait item selection to ensure they are
    actually methods and remove assertion to check if the trait item is a
    function this is a valid error check not an assertion.
    
    Fixes #2139
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-hir-dot-operator.cc (MethodResolver::select): verify it is a method
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/issue-2139.rs: New test.
    
    Signed-off-by: Philip Herron <herron.philip@googlemail.com>

Diff:
---
 gcc/rust/typecheck/rust-hir-dot-operator.cc |  6 +++++-
 gcc/testsuite/rust/compile/issue-2139.rs    | 16 ++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/typecheck/rust-hir-dot-operator.cc b/gcc/rust/typecheck/rust-hir-dot-operator.cc
index 084ef88a858..29c3e4cbaf2 100644
--- a/gcc/rust/typecheck/rust-hir-dot-operator.cc
+++ b/gcc/rust/typecheck/rust-hir-dot-operator.cc
@@ -240,8 +240,12 @@ MethodResolver::select (TyTy::BaseType &receiver)
 
     const HIR::Trait *trait = trait_ref->get_hir_trait_ref ();
     HIR::TraitItem *item = item_ref->get_hir_trait_item ();
-    rust_assert (item->get_item_kind () == HIR::TraitItem::TraitItemKind::FUNC);
+    if (item->get_item_kind () != HIR::TraitItem::TraitItemKind::FUNC)
+      return true;
+
     HIR::TraitItemFunc *func = static_cast<HIR::TraitItemFunc *> (item);
+    if (!func->get_decl ().is_method ())
+      return true;
 
     TyTy::BaseType *ty = item_ref->get_tyty ();
     rust_assert (ty->get_kind () == TyTy::TypeKind::FNDEF);
diff --git a/gcc/testsuite/rust/compile/issue-2139.rs b/gcc/testsuite/rust/compile/issue-2139.rs
new file mode 100644
index 00000000000..780ed58d5cc
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-2139.rs
@@ -0,0 +1,16 @@
+pub trait Foo {
+    fn foo();
+}
+
+impl Foo for u16 {
+    fn foo() {
+        <u16 as Foo>::foo()
+    }
+}
+
+fn main() {
+    let a: u16 = 123;
+    a.foo();
+    // { dg-error "failed to resolve method for .foo." "" { target *-*-* } .-1 }
+    // { dg-error "failed to type resolve expression" "" { target *-*-* } .-2 }
+}

                 reply	other threads:[~2023-05-02  7:10 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=20230502071033.7395A3858C83@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: link
Be 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).