Skip to content

Commit 25e1865

Browse files
committed
rust: Fix ICE with infer type used in struct attribute
When visiting a struct declaration, add check for when a struct's attribute is declared as an infer type, emitting an error if true. Fixes #3583 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Add check for infer type on struct's attribute. gcc/testsuite/ChangeLog: * rust/compile/infer-type-issue-3583.rs: New test. Signed-off-by: João Novo <joao.c.novo@tecnico.ulisboa.pt>
1 parent cd8412c commit 25e1865

2 files changed

Lines changed: 26 additions & 0 deletions

File tree

gcc/rust/typecheck/rust-hir-type-check-item.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl)
266266
{
267267
TyTy::BaseType *field_type
268268
= TypeCheckType::Resolve (field.get_field_type ());
269+
if (field_type->contains_infer ())
270+
{
271+
rust_error_at (field_type->get_locus (),
272+
"the placeholder %<_%> is not allowed within types on "
273+
"item signatures for structs");
274+
return;
275+
}
269276
auto *ty_field
270277
= new TyTy::StructFieldType (field.get_mappings ().get_hirid (),
271278
field.get_field_name ().as_string (),
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#![feature(no_core)]
2+
#![no_core]
3+
4+
struct Test10 {
5+
a: _, // { dg-error "the placeholder ... is not allowed within types on item" }
6+
}
7+
8+
struct Test11 {
9+
a: _, // { dg-error "the placeholder ... is not allowed within types on item" }
10+
b: i32,
11+
}
12+
13+
struct Test12 {
14+
a: (_, _), // { dg-error "the placeholder ... is not allowed within types on item" }
15+
}
16+
17+
struct Test13 {
18+
a: [_; _], // { dg-error "the placeholder ... is not allowed within types on item" }
19+
}

0 commit comments

Comments
 (0)