Skip to content

Commit 593fb15

Browse files
rioguCohenArthur
authored andcommitted
rust: Fix ICE in function_set_parameters
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 #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 <egas.g.ribeiro@tecnico.ulisboa.pt>
1 parent de7dffc commit 593fb15

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

gcc/rust/hir/rust-ast-lower-item.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,6 +455,25 @@ ASTLoweringItem::visit (AST::Function &function)
455455

456456
auto translated_pattern = std::unique_ptr<HIR::Pattern> (
457457
ASTLoweringPattern::translate (param.get_pattern ()));
458+
459+
switch (param.get_pattern ().get_pattern_kind ())
460+
{
461+
case AST::Pattern::Kind::Identifier:
462+
case AST::Pattern::Kind::Wildcard:
463+
case AST::Pattern::Kind::Tuple:
464+
case AST::Pattern::Kind::Struct:
465+
case AST::Pattern::Kind::TupleStruct:
466+
case AST::Pattern::Kind::Reference:
467+
case AST::Pattern::Kind::Grouped:
468+
case AST::Pattern::Kind::Slice:
469+
case AST::Pattern::Kind::Rest:
470+
break;
471+
default:
472+
rust_error_at (param.get_locus (),
473+
"refutable pattern in function argument");
474+
continue;
475+
}
476+
458477
auto translated_type = std::unique_ptr<HIR::Type> (
459478
ASTLoweringType::translate (param.get_type ()));
460479

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
4+
fn func(1: i32) {} // { dg-error "refutable pattern in function argument" }

0 commit comments

Comments
 (0)