-
Notifications
You must be signed in to change notification settings - Fork 207
expand: Add error check if derive has wrong item #4359
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
base: master
Are you sure you want to change the base?
Conversation
786575e to
57ad8d3
Compare
|
Hello, thanks for your contribution! Small nitpick on the Changelog part... Does not target a specific "item". You could be more precise using: |
ff0806a to
9e84d88
Compare
|
@dkm hello, commit message regarding changelog changed . thanks |
11bd185 to
475edf5
Compare
|
I realized there might be a potential false positive with If I am going to verify this locally by adding a test case for a tuple struct. If it fails, I will update |
Thanks! |
9cee832 to
eb4177c
Compare
|
@dkm hello, I reverted the extra Kind check since Open for review . thankyou |
|
@P-E-P please review . thankyou . |
|
@CohenArthur please review . thankyou . |
P-E-P
left a comment
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 don't really get what this PR brings on the table. Sure there is a new fancy helper function, but it has a side effect, we're emitting an error. Moving the error out of that helper means it becomes so short a function may not even be worth it anymore.
The check was already there so we didn't get anything from that.
We do get a new test which is a bit more complete compared to rust/compile/issue-3971.rs.
Am I missing something ?
|
introducing helper function does have a side effect . why i did what i did ? the ICE was solved in #4211 but issue #3875 was still open with comments suggesting a helper function , also test was missing
thankyou |
I think we should definitely keep the test, but I wouldn't keep the rest of the changes. |
f4ee91d to
207332f
Compare
|
@P-E-P no this pr only adds the test . thankyou. |
| // { dg-options "-w" } | ||
|
|
||
| #[derive(Clone)] // { dg-error "derive may only be applied to structs, enums and unions" } | ||
| fn foo() {} // { dg-excess-errors "" } |
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 wonder, maybe you could remove those dg-excess-errors if you declare Clone. Have you tried putting those traits ?
| fn foo() {} // { dg-excess-errors "" } | |
| #![feature(lang_items)] | |
| fn foo() {} | |
| #[lang = "sized"] | |
| pub trait Sized {} | |
| #[lang = "clone"] | |
| pub trait Clone: Sized {} |
Excess errors should usually be avoided as they'll catch any errors, and this means that if the compiler's behavior change in the future they won't catch an error change and things may break silently.
a3e1065 to
ea8c59e
Compare
ea8c59e to
e86d43c
Compare
This patch adds a regression test ensuring that deriving on invalid items (such as functions or traits) triggers a diagnostic error instead of an Internal Compiler Error (ICE). It also verifies that Tuple Structs are accepted as valid targets for derivation. Fixes Rust-GCC#3875 gcc/testsuite/ChangeLog: * rust/compile/issue-3875.rs: New test. Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>
e86d43c to
ab1d19a
Compare
The DeriveVisitor previously dispatched calls to specific handlers (like DeriveClone) without validating the input item type. This caused internal compiler errors (ICEs) when users attempted to derive traits on invalid items like functions or traits, as the handlers assumed the input was a struct, enum, or union.
This patch adds a validation predicate to the DeriveVisitor to reject invalid items gracefully with a diagnostic error before dispatching.
Fixes #3875
gcc/rust/ChangeLog:
gcc/testsuite/ChangeLog:
make check-rustpasses locallyclang-formatgcc/testsuite/rust/