Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions gcc/rust/typecheck/rust-hir-type-check-implitem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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%>",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I liked this error message a little more personally :D but that's just nitpicking haha

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;
Expand Down
15 changes: 15 additions & 0 deletions gcc/testsuite/rust/compile/non_member_const.rs
Original file line number Diff line number Diff line change
@@ -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>`
}
}