diff options
author | Owen Avery <powerboat9.gamer@gmail.com> | 2025-03-25 18:18:21 -0400 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2025-03-26 14:59:58 +0000 |
commit | 46ed038945beeaf0ec44d4358070dffb08e65772 (patch) | |
tree | 277584fc99e50acebef045975fc85f13d2e64fb2 | |
parent | 510b73dc40fe46644ecf724d49ec1ca8b539d809 (diff) | |
download | gcc-46ed038945beeaf0ec44d4358070dffb08e65772.zip gcc-46ed038945beeaf0ec44d4358070dffb08e65772.tar.gz gcc-46ed038945beeaf0ec44d4358070dffb08e65772.tar.bz2 |
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 <powerboat9.gamer@gmail.com>
-rw-r--r-- | gcc/rust/checks/errors/rust-ast-validation.cc | 2 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-3541-1.rs | 5 | ||||
-rw-r--r-- | gcc/testsuite/rust/compile/issue-3541-2.rs | 3 |
3 files changed, 9 insertions, 1 deletions
diff --git a/gcc/rust/checks/errors/rust-ast-validation.cc b/gcc/rust/checks/errors/rust-ast-validation.cc index 48577b9..b1de1e6 100644 --- a/gcc/rust/checks/errors/rust-ast-validation.cc +++ b/gcc/rust/checks/errors/rust-ast-validation.cc @@ -56,7 +56,7 @@ ASTValidation::visit (AST::LoopLabel &label) void ASTValidation::visit (AST::ConstantItem &const_item) { - if (!const_item.has_expr () && ctx.peek () != Kind::TRAIT_IMPL) + if (!const_item.has_expr () && ctx.peek () != Kind::TRAIT) { rust_error_at (const_item.get_locus (), "associated constant in %<impl%> without body"); diff --git a/gcc/testsuite/rust/compile/issue-3541-1.rs b/gcc/testsuite/rust/compile/issue-3541-1.rs new file mode 100644 index 0000000..6b47b7e --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3541-1.rs @@ -0,0 +1,5 @@ +impl B for u32 { + const BAR: i32; // { dg-error "associated constant in .impl." } +} + +trait B {} diff --git a/gcc/testsuite/rust/compile/issue-3541-2.rs b/gcc/testsuite/rust/compile/issue-3541-2.rs new file mode 100644 index 0000000..9f17eed --- /dev/null +++ b/gcc/testsuite/rust/compile/issue-3541-2.rs @@ -0,0 +1,3 @@ +trait B { + const BAR: i32; +} |