]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: [E0034] found more than one items for method
authorMuhammad Mahad <mahadtxt@gmail.com>
Tue, 15 Aug 2023 15:19:36 +0000 (20:19 +0500)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 16 Jan 2024 18:00:32 +0000 (19:00 +0100)
Multiple items found with same prototype.
Fixes: https://github.com/Rust-GCC/gccrs/issues/2366
gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.h:
Fixes issue & added rich location message.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Added rich location and error code.

gcc/testsuite/ChangeLog:

* rust/compile/generics6.rs: Updated dejagnu comment.
* rust/compile/generics7.rs: likewise.
* rust/compile/issue-925.rs: likewise.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
gcc/rust/typecheck/rust-hir-path-probe.h
gcc/rust/typecheck/rust-hir-type-check-expr.cc
gcc/testsuite/rust/compile/generics6.rs
gcc/testsuite/rust/compile/generics7.rs
gcc/testsuite/rust/compile/issue-925.rs

index 3fd96e631052f8ae221417bcfa51d8781d220e39..b71d8c33fdefe263b9fdaf60c92c68c57adaec44 100644 (file)
@@ -165,8 +165,11 @@ public:
     for (auto &c : candidates)
       r.add_range (c.locus);
 
+    std::string rich_msg = "multiple " + query.as_string () + " found";
+    r.add_fixit_replace (rich_msg.c_str ());
+
     rust_error_at (r, ErrorCode::E0034,
-                  "multiple applicable items in scope for: %s",
+                  "multiple applicable items in scope for: %qs",
                   query.as_string ().c_str ());
   }
 };
index e8fbe34afd020c9260f77c055334bd3eff0cf949..af350ed67d3085fe473bddc8170851d12158ef70 100644 (file)
@@ -1065,11 +1065,18 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
   if (candidates.size () > 1)
     {
       rich_location r (line_table, expr.get_method_name ().get_locus ());
+      std::string rich_msg
+       = "multiple " + expr.get_method_name ().get_segment ().as_string ()
+         + " found";
+
       for (auto &c : candidates)
        r.add_range (c.candidate.locus);
 
+      r.add_fixit_replace (rich_msg.c_str ());
+
       rust_error_at (
-       r, "multiple candidates found for method %<%s%>",
+       r, ErrorCode::E0034,
+       "multiple applicable items in scope for method %qs",
        expr.get_method_name ().get_segment ().as_string ().c_str ());
       return;
     }
index 00b93c33ebee083df37756beb5f4be35e4291061..33093cf706b93cf464fd005f406fcff1f439a14d 100644 (file)
@@ -26,7 +26,7 @@ impl Foo<f32> {
 }
 
 fn main() {
-    let a: i32 = Foo::test(); // { dg-error "multiple applicable items in scope for: test" }
+    let a: i32 = Foo::test(); // { dg-error "multiple applicable items in scope for: .test." }
     // { dg-error {Failed to resolve expression of function call} "" { target *-*-* } .-1 }
 }
 
index f2cd607a330cbd0c16b0dde054862e2e667ccd3b..ae0dc7e906a5a2bc94f18a084d308b82bf2b08ed 100644 (file)
@@ -26,5 +26,5 @@ impl<T> Foo<T> {
 fn main() {
     let a = Foo { a: 123 };
     a.bar();
-    // { dg-error "multiple candidates found for method .bar." "" { target *-*-* } .-1 }
+    // { dg-error "multiple applicable items in scope for method .bar." "" { target *-*-* } .-1 }
 }
index 2d536a54725217671e66e22d55f4a7a69d1e2a2b..d5eed7e758989323d3d87eefb10988f63f1f2395 100644 (file)
@@ -21,5 +21,5 @@ impl B for S {
 fn test() {
     let a = S;
     a.foo();
-    // { dg-error "multiple candidates found for method .foo." "" { target *-*-* } .-1 }
+    // { dg-error "multiple applicable items in scope for method .foo." "" { target *-*-* } .-1 }
 }