[gcc r14-7968] gccrs: gccrs:[E0592] methods or associated functions with same name already defined

Arthur Cohen cohenarthur@gcc.gnu.org
Tue Jan 16 18:09:37 GMT 2024


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

commit r14-7968-gdc68505f4cedfd06cc72657f3e9d14cc57335362
Author: Muhammad Mahad <mahadtxt@gmail.com>
Date:   Thu Aug 17 10:42:52 2023 +0500

    gccrs: gccrs:[E0592] methods or associated functions with same name already defined
    
    gcc/rust/ChangeLog:
    
            * typecheck/rust-hir-inherent-impl-overlap.h:
            Added rich location and errorcode.
            * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
            likewise.
    
    gcc/testsuite/ChangeLog:
    
            * rust/compile/generics7.rs: Added Errorcode hint.
            * rust/compile/generics8.rs: Updated dejagnu comment.
            * rust/compile/issue-925.rs: Added Errorcode hint.
    
    Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>

Diff:
---
 gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h | 5 ++++-
 gcc/rust/typecheck/rust-hir-type-check-expr.cc      | 3 +--
 gcc/testsuite/rust/compile/generics7.rs             | 4 ++--
 gcc/testsuite/rust/compile/generics8.rs             | 2 +-
 gcc/testsuite/rust/compile/issue-925.rs             | 4 ++--
 5 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h b/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h
index ae5a5d57c8d..abb93ca0e4a 100644
--- a/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h
+++ b/gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h
@@ -129,8 +129,11 @@ public:
 			   const std::string &name)
   {
     rich_location r (line_table, dup->get_locus ());
+    std::string msg = "duplicate definitions for " + name;
+    r.add_fixit_replace (query->get_locus (), msg.c_str ());
     r.add_range (query->get_locus ());
-    rust_error_at (r, "duplicate definitions with name %s", name.c_str ());
+    rust_error_at (r, ErrorCode::E0592, "duplicate definitions with name %qs",
+		   name.c_str ());
   }
 
 private:
diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
index 898ea117333..f0911967470 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc
@@ -1097,8 +1097,7 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
       r.add_fixit_replace (rich_msg.c_str ());
 
       rust_error_at (
-	r, ErrorCode::E0034,
-	"multiple applicable items in scope for method %qs",
+	r, ErrorCode::E0592, "duplicate definitions with name %qs",
 	expr.get_method_name ().get_segment ().as_string ().c_str ());
       return;
     }
diff --git a/gcc/testsuite/rust/compile/generics7.rs b/gcc/testsuite/rust/compile/generics7.rs
index ae0dc7e906a..dcedead4b9f 100644
--- a/gcc/testsuite/rust/compile/generics7.rs
+++ b/gcc/testsuite/rust/compile/generics7.rs
@@ -22,9 +22,9 @@ impl<T> Foo<T> {
         self.a
     }
 }
-
+// E0592
 fn main() {
     let a = Foo { a: 123 };
     a.bar();
-    // { dg-error "multiple applicable items in scope for method .bar." "" { target *-*-* } .-1 }
+    // { dg-error "duplicate definitions with name .bar." "" { target *-*-* } .-1 }
 }
diff --git a/gcc/testsuite/rust/compile/generics8.rs b/gcc/testsuite/rust/compile/generics8.rs
index 99df0c9b58c..88c4bac1b07 100644
--- a/gcc/testsuite/rust/compile/generics8.rs
+++ b/gcc/testsuite/rust/compile/generics8.rs
@@ -10,7 +10,7 @@ impl<T> Foo<i32, T> {
 }
 
 impl Foo<i32, f32> {
-    fn test() -> f32 { // { dg-error "duplicate definitions with name test" }
+    fn test() -> f32 { // { dg-error "duplicate definitions with name .test." }
         123f32
     }
 }
diff --git a/gcc/testsuite/rust/compile/issue-925.rs b/gcc/testsuite/rust/compile/issue-925.rs
index d5eed7e7589..507fe9444e5 100644
--- a/gcc/testsuite/rust/compile/issue-925.rs
+++ b/gcc/testsuite/rust/compile/issue-925.rs
@@ -17,9 +17,9 @@ impl A for S {
 impl B for S {
     fn foo(&self) {}
 }
-
+// E0592
 fn test() {
     let a = S;
     a.foo();
-    // { dg-error "multiple applicable items in scope for method .foo." "" { target *-*-* } .-1 }
+    // { dg-error "duplicate definitions with name .foo." "" { target *-*-* } .-1 }
 }


More information about the Gcc-cvs mailing list