Skip to content

Commit

Permalink
gccrs: [E0592] Duplicate def of method or associated functions
Browse files Browse the repository at this point in the history
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: Updated dejagnu comment.
	* rust/compile/generics8.rs: likewise.
	* rust/compile/issue-925.rs: likewise.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
  • Loading branch information
MahadMuhammad committed Aug 14, 2023
1 parent 74b27ac commit f4247b0
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
5 changes: 4 additions & 1 deletion gcc/rust/typecheck/rust-hir-inherent-impl-overlap.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ class OverlappingImplItemPass : public TypeCheckBase
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:
Expand Down
9 changes: 7 additions & 2 deletions gcc/rust/typecheck/rust-hir-type-check-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1065,11 +1065,16 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
if (candidates.size () > 1)
{
rich_location r (line_table, expr.get_method_name ().get_locus ());
std::string msg = "duplicate definitions for "
+ expr.get_method_name ().get_segment ().as_string ();
for (auto &c : candidates)
r.add_range (c.candidate.locus);
{
r.add_fixit_replace (c.candidate.locus, msg.c_str ());
r.add_range (c.candidate.locus);
}

rust_error_at (
r, "multiple candidates found for method %<%s%>",
r, ErrorCode::E0592, "duplicate definitions with name %<%s%>",
expr.get_method_name ().get_segment ().as_string ().c_str ());
return;
}
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/generics7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "duplicate definitions with name .bar." "" { target *-*-* } .-1 }
}
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/generics8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/issue-925.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 "duplicate definitions with name .foo." "" { target *-*-* } .-1 }
}

0 comments on commit f4247b0

Please sign in to comment.