From: lishin <[email protected]>
Fixes Rust-GCC/gccrs#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 Rust-GCC/gccrs#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 <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/5c4de7f38e474c58dca99aa723199b7b9578aa56
The commit has been mentioned in the following issue(s):
- Rust-GCC/gccrs#3972: https://github.com/Rust-GCC/gccrs/issues/3972
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4532
gcc/rust/hir/tree/rust-hir-item.cc | 7 +++++--
gcc/testsuite/rust/compile/issue-3972.rs | 19 +++++++++++++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-3972.rs
diff --git a/gcc/rust/hir/tree/rust-hir-item.cc
b/gcc/rust/hir/tree/rust-hir-item.cc
index 5e5d9b783..309118cff 100644
--- a/gcc/rust/hir/tree/rust-hir-item.cc
+++ b/gcc/rust/hir/tree/rust-hir-item.cc
@@ -630,7 +630,8 @@ TraitFunctionDecl::TraitFunctionDecl (
TraitFunctionDecl::TraitFunctionDecl (TraitFunctionDecl const &other)
: qualifiers (other.qualifiers), function_name (other.function_name),
function_params (other.function_params),
- return_type (other.return_type->clone_type ()),
+ return_type (other.return_type != nullptr ? other.return_type->clone_type
()
+ : nullptr),
where_clause (other.where_clause), self (other.self)
{
generic_params.reserve (other.generic_params.size ());
@@ -644,7 +645,9 @@ TraitFunctionDecl::operator= (TraitFunctionDecl const
&other)
function_name = other.function_name;
qualifiers = other.qualifiers;
function_params = other.function_params;
- return_type = other.return_type->clone_type ();
+ return_type
+ = other.return_type != nullptr ? other.return_type->clone_type () :
nullptr;
+
where_clause = other.where_clause;
self = other.self;
diff --git a/gcc/testsuite/rust/compile/issue-3972.rs
b/gcc/testsuite/rust/compile/issue-3972.rs
new file mode 100644
index 000000000..466efc364
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3972.rs
@@ -0,0 +1,19 @@
+// { dg-options "-frust-compile-until=lowering" }
+#![feature(no_core)]
+#![no_core]
+
+struct Expr<const N: u32>;
+
+trait Trait0 {
+ fn required(
+ _: Expr<
+ {
+ trait Trait0 {
+ fn required();
+ }
+
+ 0
+ },
+ >,
+ );
+}
base-commit: 399c14dba6efd5951d95e06bdf402aa6df3f688e
--
2.54.0