aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMuhammad Mahad <mahadtxt@gmail.com>2023-07-18 18:55:32 +0500
committerCohenArthur <arthur.cohen@embecosm.com>2023-07-27 09:07:54 +0000
commit245867e9999c11be2a725156cead914ad402059e (patch)
treeac58439a88a39ed56ebabce844c9553b58158729 /gcc
parentcd38fecd8fc80139956dc5f0d47a6651216a9897 (diff)
downloadgcc-245867e9999c11be2a725156cead914ad402059e.zip
gcc-245867e9999c11be2a725156cead914ad402059e.tar.gz
gcc-245867e9999c11be2a725156cead914ad402059e.tar.bz2
gccrs: [E0323] Implemented associated const, expected another trait
Refactored Error message similiar to rustc. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItemWithTrait::visit): called error function. gcc/testsuite/ChangeLog: * rust/compile/non_member_const.rs: New test. Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/typecheck/rust-hir-type-check-implitem.cc6
-rw-r--r--gcc/testsuite/rust/compile/non_member_const.rs15
2 files changed, 19 insertions, 2 deletions
diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
index e84935a..5a0ffef 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc
@@ -389,12 +389,14 @@ TypeCheckImplItemWithTrait::visit (HIR::ConstantItem &constant)
TraitItemReference::TraitItemType::CONST,
&raw_trait_item);
- // unknown trait item
+ // unknown trait item - https://doc.rust-lang.org/error_codes/E0323.html
if (!found || raw_trait_item->is_error ())
{
rich_location r (line_table, constant.get_locus ());
r.add_range (trait_reference.get_locus ());
- rust_error_at (r, "constant %<%s%> is not a member of trait %<%s%>",
+ rust_error_at (r, ErrorCode ("E0323"),
+ "item %qs is an associated const, which does not match "
+ "its trait %qs",
constant.get_identifier ().as_string ().c_str (),
trait_reference.get_name ().c_str ());
return;
diff --git a/gcc/testsuite/rust/compile/non_member_const.rs b/gcc/testsuite/rust/compile/non_member_const.rs
new file mode 100644
index 0000000..b974002
--- /dev/null
+++ b/gcc/testsuite/rust/compile/non_member_const.rs
@@ -0,0 +1,15 @@
+// https://doc.rust-lang.org/error_codes/E0323.html
+#![allow(unused)]
+fn main() {
+trait Foo {
+ type N;
+}
+
+struct Bar;
+
+impl Foo for Bar {
+ const N : u32 = 0; // { dg-error "item .N. is an associated const, which does not match its trait .Foo." }
+ // error: item `N` is an associated const, which doesn't match its
+ // trait `<Bar as Foo>`
+}
+} \ No newline at end of file