Skip to content

Commit 46ed038

Browse files
powerboat9P-E-P
authored andcommitted
Fix validation of constant items
gcc/rust/ChangeLog: * checks/errors/rust-ast-validation.cc (ASTValidation::visit): Allow constant items lacking expressions if and only if they're associated with a trait definition, not a trait implementation. gcc/testsuite/ChangeLog: * rust/compile/issue-3541-1.rs: New test. * rust/compile/issue-3541-2.rs: Likewise. Signed-off-by: Owen Avery <[email protected]>
1 parent 510b73d commit 46ed038

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

gcc/rust/checks/errors/rust-ast-validation.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ ASTValidation::visit (AST::LoopLabel &label)
5656
void
5757
ASTValidation::visit (AST::ConstantItem &const_item)
5858
{
59-
if (!const_item.has_expr () && ctx.peek () != Kind::TRAIT_IMPL)
59+
if (!const_item.has_expr () && ctx.peek () != Kind::TRAIT)
6060
{
6161
rust_error_at (const_item.get_locus (),
6262
"associated constant in %<impl%> without body");
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
impl B for u32 {
2+
const BAR: i32; // { dg-error "associated constant in .impl." }
3+
}
4+
5+
trait B {}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait B {
2+
const BAR: i32;
3+
}

0 commit comments

Comments
 (0)