Skip to content

Commit

Permalink
gccrs: [E0034] found more than one items for method
Browse files Browse the repository at this point in the history
Multiple items found with same prototype.
Fixes: Rust-GCC/gccrs#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 <[email protected]>
  • Loading branch information
MahadMuhammad authored and CohenArthur committed Jan 16, 2024
1 parent 6899eaa commit b763d73
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
5 changes: 4 additions & 1 deletion gcc/rust/typecheck/rust-hir-path-probe.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,11 @@ class ReportMultipleCandidateError : private TypeCheckBase
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 ());
}
};
Expand Down
9 changes: 8 additions & 1 deletion gcc/rust/typecheck/rust-hir-type-check-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion gcc/testsuite/rust/compile/generics6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

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 "multiple applicable items in scope for method .bar." "" { target *-*-* } .-1 }
}
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 "multiple applicable items in scope for method .foo." "" { target *-*-* } .-1 }
}

0 comments on commit b763d73

Please sign in to comment.