Commit 5c4de7f
gccrs: Fix ICE cloning trait functions without return types
Fixes #3972.
Trait functions without an explicit return type can have a null
`return_type` in `TraitFunctionDecl`. When such declarations are copied,
the copy constructor and assignment operator currently try to clone the
return type unconditionally, and this can lead to an ICE.
Handle this case by keeping `nullptr` when there is no return type to
clone. Also add a regression test for the example from #3972.
gcc/rust/ChangeLog:
* hir/tree/rust-hir-item.cc (TraitFunctionDecl::TraitFunctionDecl):
Handle null return types in copy constructor.
(TraitFunctionDecl::operator=): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3972.rs: New test.
Signed-off-by: lishin <lishin1008@gmail.com>1 parent 399c14d commit 5c4de7f
2 files changed
Lines changed: 24 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
630 | 630 | | |
631 | 631 | | |
632 | 632 | | |
633 | | - | |
| 633 | + | |
| 634 | + | |
634 | 635 | | |
635 | 636 | | |
636 | 637 | | |
| |||
644 | 645 | | |
645 | 646 | | |
646 | 647 | | |
647 | | - | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
648 | 651 | | |
649 | 652 | | |
650 | 653 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
0 commit comments