From: Philip Herron <[email protected]>
Fixes Rust-GCC#1617
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): check
valid
gcc/testsuite/ChangeLog:
* rust/compile/issue-4617.rs: New test.
Signed-off-by: Philip Herron <[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/206d052f0c25feb613d28fcd71877db7db089c14
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4661
gcc/rust/typecheck/rust-hir-type-check-item.cc | 8 +++++---
gcc/testsuite/rust/compile/issue-4617.rs | 8 ++++++++
2 files changed, 13 insertions(+), 3 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issue-4617.rs
diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc
b/gcc/rust/typecheck/rust-hir-type-check-item.cc
index 055ce2b28..065615a23 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-item.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc
@@ -421,9 +421,11 @@ TypeCheckItem::visit (HIR::Enum &enum_decl)
{
TyTy::VariantDef *field_type
= TypeCheckEnumItem::Resolve (*variant, discriminant_value);
-
- discriminant_value++;
- variants.push_back (field_type);
+ if (field_type)
+ {
+ discriminant_value++;
+ variants.push_back (field_type);
+ }
}
// Check for zero-variant enum compatibility
diff --git a/gcc/testsuite/rust/compile/issue-4617.rs
b/gcc/testsuite/rust/compile/issue-4617.rs
new file mode 100644
index 000000000..202310071
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-4617.rs
@@ -0,0 +1,8 @@
+#![feature(no_core)]
+#![no_core]
+
+struct Apple;
+
+enum Delicious {
+ ApplePie = Apple::PIE, // { dg-error "failed to resolve path segment using
an impl Probe" }
+}
base-commit: 407b7e6c52619bb81e201293a52819bbe22d9c8e
--
2.54.0