From: Yap Zhi Heng <[email protected]>
Fixes Rust-GCC/gccrs#5082
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-pattern.cc (visit
(HIR::TupleStructPattern)):
Unify pattern_ty with the expected type before checking fields.
Signed-off-by: Yap Zhi Heng <[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/009865ec86703db7ef8d3a3c2fdc354938fe97d8
The commit has been mentioned in the following issue(s):
- Rust-GCC/gccrs#5082: https://github.com/Rust-GCC/gccrs/issues/5082
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/5133
.../typecheck/rust-hir-type-check-pattern.cc | 13 ++++++++++--
gcc/testsuite/rust/compile/issues/5082.rs | 21 +++++++++++++++++++
2 files changed, 32 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/issues/5082.rs
diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
index 26f3c0c68..933e0fb8c 100644
--- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
+++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc
@@ -171,8 +171,17 @@ TypeCheckPattern::visit (HIR::TupleStructPattern &pattern)
return;
}
- infered = pattern_ty;
- TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (infered);
+ infered = unify_site (pattern.get_mappings ().get_hirid (),
+ TyTy::TyWithLocation (parent),
+ TyTy::TyWithLocation (pattern_ty, pattern.get_locus ()),
+ pattern.get_locus ());
+ if (infered->get_kind () == TyTy::TypeKind::ERROR)
+ {
+ return;
+ }
+
+ TyTy::BaseType *resolved = infered->destructure ();
+ TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (resolved);
TyTy::VariantDef *variant = nullptr;
if (adt->is_enum ())
diff --git a/gcc/testsuite/rust/compile/issues/5082.rs
b/gcc/testsuite/rust/compile/issues/5082.rs
new file mode 100644
index 000000000..6f4d921a8
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issues/5082.rs
@@ -0,0 +1,21 @@
+#![feature(no_core, lang_items)]
+#![no_core]
+
+#[lang = "sized"]
+pub trait Sized {}
+
+enum Option<T> {
+ None,
+ Some(T),
+}
+fn check_tuple(x: Option<(u32, u32)>) {
+ // { dg-warning "function is never used: .check_tuple." "" { target *-*-*
} .-1 }
+ match x {
+ Option::Some((a, b)) => {
+ let _: u32 = a;
+ let _: u32 = b;
+ }
+ Option::None => {}
+ }
+}
+fn main() {}
--
2.56.1