-
Notifications
You must be signed in to change notification settings - Fork 157
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
Add error message for E0532 #3118
Conversation
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc: Emit E0532 when trying to reference a Tuple or Struct variant using a non Tuple or Struct pattern. gcc/testsuite/ChangeLog: * rust/compile/issue-2324-1.rs: add test for E0532 with tuple enum variant * rust/compile/issue-2324-2.rs: add test for E0532 with struct enum variant Signed-off-by: Liam Naddell <[email protected]>
91ee735
to
1231ee6
Compare
d378385
to
2fd3eac
Compare
I can see why. Honestly as long as the error code is correct the message doesn't need to match rustc's message exactly. Let's keep it like this, if we want to match rustc's message in the future we won't have to change it, furthermore rustc may get a better error message for this error specifically in the future. Moreover keeping the error message as is will get it in line with the error code https://doc.rust-lang.org/stable/error_codes/E0533.html. |
I'm inclined to agree, it's probably best to leave it as is |
Thanks @liamnaddell for fixing the issue. I agree to @P-E-P
I spent quite a time to making Furthermore, the tool I am working on to convert |
rust_error_at ( | ||
pattern.get_final_segment ().get_locus (), ErrorCode::E0532, | ||
"expected unit struct, unit variant or constant, found tuple variant"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This error message seems incorrect. found tuple variant
should be changed to found %s variant
. I will fix this in #3125
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this. I only put it in because its what rustc uses
rust_assert (infered->get_kind () == TyTy::TypeKind::ADT); | ||
TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (infered); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it is okay that patterns reference non-ADT const items.
fn print_on_failure(state: &State) { | ||
match *state { | ||
State::Succeeded => (), | ||
State::Failed => (), // { dg-error "expected unit struct, unit variant or constant, found tuple variant" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be found struct variant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this should say "found unit variant"
Since State::Failed is a unit variant, but we needed the struct variant State::Failed { x:y}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are also right too. I feel a bit weird for this message.
We (and rustc) should rethink about this message :)
I took the error message from rustc, but I really don't like it. Isn't the error message the direct opposite of the problem?
Rustc error message: expected unit struct, unit variant or constant, found tuple variant
I want something like: referenced type is a non-unit enum variant, consider specifying the relevant variant fields
Fixes #2324 , addresses #2553
make check-rust
passes locallyclang-format
gcc/testsuite/rust/
Adds error message for E0532