Skip to content

Commit

Permalink
gccrs:[E0592] methods or associated functions with same name already …
Browse files Browse the repository at this point in the history
…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 <[email protected]>
  • Loading branch information
MahadMuhammad authored and P-E-P committed Sep 4, 2023
1 parent 699f525 commit e5b5938
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 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
3 changes: 1 addition & 2 deletions gcc/rust/typecheck/rust-hir-type-check-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions gcc/testsuite/rust/compile/generics7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
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
4 changes: 2 additions & 2 deletions gcc/testsuite/rust/compile/issue-925.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

0 comments on commit e5b5938

Please sign in to comment.