From: Egas Ribeiro <[email protected]>
When lowering a function to HIR with a refutable pattern in its
parameter pattern, we were ICE'ing due to a lack of checks for invalid
refutable patterns. Fix this by erroring on invalid patterns while
lowering a function.
Fixes Rust-GCC/gccrs#3919
gcc/rust/ChangeLog:
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): added
refutable pattern checks for function params.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3919-ice-func-parms.rs: New test.
Signed-off-by: Egas Ribeiro <[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/593fb1594a708a200a5129ff1191f7fede04d3c2
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4501
gcc/rust/hir/rust-ast-lower-item.cc | 19 +++++++++++++++++++
.../rust/compile/issue-3919-ice-func-parms.rs | 4 ++++
2 files changed, 23 insertions(+)
create mode 100644 gcc/testsuite/rust/compile/issue-3919-ice-func-parms.rs
diff --git a/gcc/rust/hir/rust-ast-lower-item.cc
b/gcc/rust/hir/rust-ast-lower-item.cc
index 2d3d021f8..96b6aefbc 100644
--- a/gcc/rust/hir/rust-ast-lower-item.cc
+++ b/gcc/rust/hir/rust-ast-lower-item.cc
@@ -455,6 +455,25 @@ ASTLoweringItem::visit (AST::Function &function)
auto translated_pattern = std::unique_ptr<HIR::Pattern> (
ASTLoweringPattern::translate (param.get_pattern ()));
+
+ switch (param.get_pattern ().get_pattern_kind ())
+ {
+ case AST::Pattern::Kind::Identifier:
+ case AST::Pattern::Kind::Wildcard:
+ case AST::Pattern::Kind::Tuple:
+ case AST::Pattern::Kind::Struct:
+ case AST::Pattern::Kind::TupleStruct:
+ case AST::Pattern::Kind::Reference:
+ case AST::Pattern::Kind::Grouped:
+ case AST::Pattern::Kind::Slice:
+ case AST::Pattern::Kind::Rest:
+ break;
+ default:
+ rust_error_at (param.get_locus (),
+ "refutable pattern in function argument");
+ continue;
+ }
+
auto translated_type = std::unique_ptr<HIR::Type> (
ASTLoweringType::translate (param.get_type ()));
diff --git a/gcc/testsuite/rust/compile/issue-3919-ice-func-parms.rs
b/gcc/testsuite/rust/compile/issue-3919-ice-func-parms.rs
new file mode 100644
index 000000000..3305762bb
--- /dev/null
+++ b/gcc/testsuite/rust/compile/issue-3919-ice-func-parms.rs
@@ -0,0 +1,4 @@
+#![feature(no_core)]
+#![no_core]
+
+fn func(1: i32) {} // { dg-error "refutable pattern in function argument" }
base-commit: de7dffce247c236349b418215c820ecb8965b090
--
2.53.0