-
Notifications
You must be signed in to change notification settings - Fork 173
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
Fix Issue 3351: Shared discriminator having the same value< #3458
base: master
Are you sure you want to change the base?
Conversation
redundant header include, i have noticed, will fix after review |
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.
Fantastic work i've left you comments for style. The error message using %< etc will fix the warnings that are introduced.
I don't think you should need the changes to rust-compile-item.cc but left me know if removing it causes an issue for you
I think in theory we might need a guard in your code where check_variant_record_collision needs to check if this has been checked before because you will get duplicate warnings here for example:
#[lang="sized"]
trait Sized {}
enum Greeting<T> {
Hi(T),
Bye
}
fn test() {
let a = Greeting::<i32>::Hi(123);
let b = Greeting::<f32>::Bye;
}
So I think lets get this first part merged. Then you will need to start tracking the HIR::Enum def-id on the TyTy::ADTType and you can keep a map in the backend if this DefID has already been checked to solve the above problem.
c59acb0
to
08229bd
Compare
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.
LGTM nice work
08229bd
to
b910edb
Compare
thank you for your guidance! |
|
||
rich_location r (line_table, type.get_locus ()); | ||
std::string assigned_here_msg | ||
= "`" + std::to_string (discriminant_integer) + "`" + " assigned here"; |
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.
There are more backquote here, GCC probably does't complain about those because they are not in the format string. I'm unsure if we should change them.
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 can change it to %qlld via format string i think? The reason i did it this way is because different platform has different width for HOST WIDTH INT and im not sure if the final answer would be %qlld or %qld or if there is any complication if HWI is only %d and we use %qlld
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.
Yeah, I'm kinda torn on the subject. Raw back quotes don't play well with different locales, this is not only a matter of style.
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.
Would HOST_WIDE_INT_PRINT_DEC
work?
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 it could work for rust_error_at,
for add_fixit_replace()
they dont take formatting arguments, is there a way to create a standalone formatting string in the codebase without explicitly using snprintf?
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.
Maybe use normal quotation marks (
"
) instead of`
and include aTODO
comment, so we're more likely to notice and fix this in the future
i will opt for this. fix coming soon
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.
Actually, wait, we have rust_open_quote
and rust_close_quote
-- that should do the trick
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.
Oh, wait, check out expand_message
in rust-diagnostics.cc
-- that should be what you're looking for
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.
Oh, wait, check out
expand_message
inrust-diagnostics.cc
-- that should be what you're looking for
the function is only in rust-diagnostics.cc, im not sure if i should move it to the header to use it solely for rust-compile-type.cc?
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.
You could make it not-static
and add a declaration to rust-diagnostics.h
gcc/testsuite/ChangeLog: * rust/compile/shared_discriminator_enum.rs: New test.
gcc/rust/ChangeLog: * backend/rust-compile-item.cc (CompileItem::visit): Use HIR::Enum visit * backend/rust-compile-item.h: Fix clash of enum shared discriminant * backend/rust-compile-type.cc (check_variant_record_collision): Likewise. (TyTyResolveCompile::visit): Early return if fail enum check * rust-diagnostics.cc (expand_message): non-static now. * rust-diagnostics.h (RUST_ATTRIBUTE_GCC_DIAG): non-static expand msg (expand_message): likewise.
Fixes #3351
Overriding on the compile item visitor, I am not sure if this is the right way to go?