Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion gcc/rust/typecheck/rust-hir-type-check-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,13 @@ TypeCheckExpr::visit (HIR::TupleIndexExpr &expr)
}

TyTy::ADTType *adt = static_cast<TyTy::ADTType *> (resolved);
rust_assert (!adt->is_enum ());
if (!adt->is_tuple_struct ())
{
rust_error_at (expr.get_locus (),
"expected tuple or tuple struct, found %qs",
adt->get_name ().c_str ());
return;
}
rust_assert (adt->number_of_variants () == 1);

TyTy::VariantDef *variant = adt->get_variants ().at (0);
Expand Down
15 changes: 15 additions & 0 deletions gcc/testsuite/rust/compile/tuple_index_on_non_tuple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
enum E {
V(usize),
}

struct S {
field: i32,
}

fn main() {
let e = E::V(0);
let _ = e.0; // { dg-error "expected tuple or tuple struct, found 'E'" }

let s = S { field: 0 };
let _ = s.0; // { dg-error "expected tuple or tuple struct, found 'S'" }
}
Loading