Commit 9cee832
committed
expand: Add error check if derive has wrong item
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 `validate_item` to the DeriveVisitor
to reject invalid items gracefully with a diagnostic error before dispatching.
Fixes #3875
gcc/rust/ChangeLog:
* expand/rust-derive.h (DeriveVisitor::validate_item): Add prototype.
* expand/rust-derive.cc (DeriveVisitor::derive): Use visitor validation.
(DeriveVisitor::validate_item): New function to check item kind.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3875.rs: New test.
Signed-off-by: Jayant Chauhan <0001jayant@gmail.com>1 parent c35ffdb commit 9cee832
File tree
3 files changed
+30
-7
lines changed- gcc
- rust/expand
- testsuite/rust/compile
3 files changed
+30
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
| 43 | + | |
47 | 44 | | |
48 | | - | |
49 | | - | |
50 | | - | |
| 45 | + | |
51 | 46 | | |
52 | 47 | | |
53 | 48 | | |
| |||
159 | 154 | | |
160 | 155 | | |
161 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
162 | 172 | | |
163 | 173 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
74 | 75 | | |
75 | 76 | | |
76 | 77 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
0 commit comments