Skip to content

Commit

Permalink
gccrs: [E0576] Associated item not found in given type
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit):
	Add rich error message and error code similiar to rustc with
	associaed type and trait name

gcc/testsuite/ChangeLog:

	* rust/compile/unknown-associated-item.rs: New test.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
  • Loading branch information
MahadMuhammad authored and P-E-P committed Jul 24, 2024
1 parent 34a0835 commit 8c357fd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
12 changes: 11 additions & 1 deletion gcc/rust/typecheck/rust-hir-type-check-type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,17 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path)
= specified_bound.lookup_associated_item (item_seg_identifier.as_string ());
if (item.is_error ())
{
rust_error_at (item_seg->get_locus (), "unknown associated item");
std::string item_seg_ident_name, rich_msg;
item_seg_ident_name = qual_path_type.get_trait ()->as_string ();
rich_msg = "not found in `" + item_seg_ident_name + "`";

rich_location richloc (line_table, item_seg->get_locus ());
richloc.add_fixit_replace (rich_msg.c_str ());

rust_error_at (richloc, ErrorCode::E0576,
"cannot find associated type %qs in trait %qs",
item_seg_identifier.as_string ().c_str (),
item_seg_ident_name.c_str ());
return;
}

Expand Down
10 changes: 10 additions & 0 deletions gcc/testsuite/rust/compile/unknown-associated-item.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![allow(unused)]
fn main() {
trait Hello {
type Who;

fn hello() -> <Self as Hello>::You;
// { dg-error "cannot find associated type .You. in trait .Hello. .E0576." "" { target *-*-* } .-1 }
// { dg-error "failed to resolve return type" "" { target *-*-* } .-2 }
}
}

0 comments on commit 8c357fd

Please sign in to comment.