Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[E0323] Implemented associated const, expected another trait #2445

Merged
merged 1 commit into from
Jul 27, 2023

Conversation

MahadMuhammad
Copy link
Contributor

Const is not member of trait E0323

  • Refactored Error message similiar to rustc.

Code tested from E0323:

// 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>`
}
}

Output:

/home/mahad/Desktop/mahad/gccrs/gcc/testsuite/rust/compile/non_member_const.rs:11:5: error: item 'N' is an associated const, which does not match its trait 'Foo' [E0323]
compiler exited with status 1
PASS: rust/compile/non_member_const.rs  (test for errors, line 11)
PASS: rust/compile/non_member_const.rs (test for excess errors)

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.

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 %<%s%> is an associated const, which does not match "
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • Refactored Error message, similiar to rustc.
  • With a little difference,
  • The diff of rustc and gccrs error is:
# gccrs
+ item ‘N’ is an associated const, which does not match its trait ‘Foo’  

- item `N` is an associated const, which doesn't match its trait `Foo`

Is there a way to add single apostrophe, in the error message:

../../gccrs/gcc/rust/typecheck/rust-hir-type-check-implitem.cc:398:68: warning: bare apostrophe ‘'’ in format [-Wformat-diag]
  398 |                      "item %<%s%> is an associated const, which doe's not match "
      |                                                                    ^
../../gccrs/gcc/rust/typecheck/rust-hir-type-check-implitem.cc:398:22: note: if avoiding the apostrophe is not feasible, enclose it in a pair of ‘%<’ and ‘%>’ directives instead
  398 |                      "item %<%s%> is an associated const, which doe's not match "
      |                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  399 |                      "its 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.

the grammar you used is correct, no need to add a single apostrophe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@CohenArthur, Yeah there is no need to add a single apostrophe. But it would be better to add, then the whole message will be exactly similiar to rustc..

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 %<%s%> is an associated const, which does not match "
Copy link
Member

Choose a reason for hiding this comment

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

the grammar you used is correct, no need to add a single apostrophe?

gcc/rust/typecheck/rust-hir-type-check-implitem.cc Outdated Show resolved Hide resolved
gcc/rust/typecheck/rust-hir-type-check-implitem.cc Outdated Show resolved Hide resolved
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

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>
@CohenArthur CohenArthur added this pull request to the merge queue Jul 27, 2023
Merged via the queue into Rust-GCC:master with commit 245867e Jul 27, 2023
@MahadMuhammad
Copy link
Contributor Author

MahadMuhammad commented Jul 28, 2023

@CohenArthur We accidently merged wrong error message & error code in this PR :(

The error code should be E0438 and previous message was also wrong. For this error code E0323, we need to do some extra work. I'll fix this in some other PR :)

@CohenArthur
Copy link
Member

@CohenArthur We accidently merged wrong error message & error code in this PR :(

The error code should be E0438 and previous message was also wrong. For this error code E0323, we need to do some extra work. I'll fix this in some other PR :)

that's okay, good catch! can you open an issue so we don't forget to address it?

@MahadMuhammad MahadMuhammad mentioned this pull request Jul 28, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
diagnostic diagnostic static analysis enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants