diff options
author | Muhammad Mahad <mahadtxt@gmail.com> | 2024-07-19 13:42:03 +0000 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-17 16:35:53 +0100 |
commit | f9a8ce88cb3bfe68c370ddb7bd0292b832c35d4e (patch) | |
tree | ac0277426cb6fe07c173298fd42a66810b0f201d | |
parent | c7cdae718c24e7a3f68d7090cc9947df5d848fb8 (diff) | |
download | gcc-f9a8ce88cb3bfe68c370ddb7bd0292b832c35d4e.zip gcc-f9a8ce88cb3bfe68c370ddb7bd0292b832c35d4e.tar.gz gcc-f9a8ce88cb3bfe68c370ddb7bd0292b832c35d4e.tar.bz2 |
gccrs: [E0576] Associated `item` not found in given `type`
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>
-rw-r--r-- | gcc/rust/typecheck/rust-hir-type-check-type.cc | 12 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/unknown-associated-item.rs | 10 |
2 files changed, 21 insertions, 1 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index 2a3e35c..f7ae8cc 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -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; } diff --git a/gcc/testsuite/rust/compile/unknown-associated-item.rs b/gcc/testsuite/rust/compile/unknown-associated-item.rs new file mode 100644 index 0000000..c292069 --- /dev/null +++ b/gcc/testsuite/rust/compile/unknown-associated-item.rs @@ -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 } + } +} |