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] Improve error message for failure in Method resolution
Date: Wed,  8 Jun 2022 12:00:38 +0000 (GMT)	[thread overview]
Message-ID: <20220608120038.0886F3AA9400@sourceware.org> (raw)

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

commit d31c1bdaa8f0c08ec5517a0819b590e5650795ee
Author: Philip Herron <philip.herron@embecosm.com>
Date:   Fri Jan 21 20:49:55 2022 +0000

    Improve error message for failure in Method resolution
    
    Use the locus for the method name segment and print its name as part of the
    error message improves the quality of the error handling in method
    resolution.
    
    Fixes #861

Diff:
---
 gcc/rust/typecheck/rust-hir-type-check-expr.h | 15 ++++-----------
 gcc/testsuite/rust/compile/method1.rs         |  2 +-
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.h b/gcc/rust/typecheck/rust-hir-type-check-expr.h
index 1ac49463062..0ac924fa26e 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.h
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.h
@@ -299,17 +299,10 @@ public:
       = MethodResolution::Select (candidates, receiver_tyty, adjustments);
     if (resolved_candidate == nullptr)
       {
-	if (candidates.size () > 1)
-	  {
-	    // not sure if this is the correct error here
-	    ReportMultipleCandidateError::Report (
-	      candidates, expr.get_method_name ().get_segment (),
-	      expr.get_method_name ().get_locus ());
-	  }
-	else
-	  {
-	    rust_error_at (expr.get_locus (), "failed to resolve method");
-	  }
+	rust_error_at (
+	  expr.get_method_name ().get_locus (),
+	  "failed to resolve method for %<%s%>",
+	  expr.get_method_name ().get_segment ().as_string ().c_str ());
 	return;
       }
 
diff --git a/gcc/testsuite/rust/compile/method1.rs b/gcc/testsuite/rust/compile/method1.rs
index cce4ecfb683..18652406085 100644
--- a/gcc/testsuite/rust/compile/method1.rs
+++ b/gcc/testsuite/rust/compile/method1.rs
@@ -8,6 +8,6 @@ pub fn main() {
     a = Foo(123);
 
     a.test();
-    // { dg-error "failed to resolve method" "" { target *-*-* } .-1 }
+    // { dg-error "failed to resolve method for .test." "" { target *-*-* } .-1 }
     // { dg-error {failed to type resolve expression} "" { target *-*-* } .-2 }
 }


                 reply	other threads:[~2022-06-08 12:00 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=20220608120038.0886F3AA9400@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).