From: Wesley Lewis <[email protected]>
Fixes Rust-GCC/gccrs#4938
gcc/rust/ChangeLog:
* checks/errors/rust-attribute-checker.cc
(AttributeChecker::visit): Added check.
gcc/testsuite/ChangeLog:
* rust/compile/wrong_meta_list_delims.rs: Added new test.
Signed-off-by: Wesley Lewis <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/9da0928a773255c416009474f512ab3f7cdbb8c9
The commit has been mentioned in the following issue(s):
- Rust-GCC/gccrs#4938: https://github.com/Rust-GCC/gccrs/issues/4938
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4994
.../checks/errors/rust-attribute-checker.cc | 26 +++++++++++++++++--
.../rust/compile/wrong_meta_list_delims.rs | 12 +++++++++
2 files changed, 36 insertions(+), 2 deletions(-)
create mode 100644 gcc/testsuite/rust/compile/wrong_meta_list_delims.rs
diff --git a/gcc/rust/checks/errors/rust-attribute-checker.cc
b/gcc/rust/checks/errors/rust-attribute-checker.cc
index 4580aa256..5a98cf883 100644
--- a/gcc/rust/checks/errors/rust-attribute-checker.cc
+++ b/gcc/rust/checks/errors/rust-attribute-checker.cc
@@ -94,8 +94,30 @@ AttributeChecker::visit (AST::Token &)
{}
void
-AttributeChecker::visit (AST::DelimTokenTree &)
-{}
+AttributeChecker::visit (AST::DelimTokenTree &ttree)
+{
+ // Checking if the DelimTokenTree contains '('
+ // or something else. If something else, then error
+ const auto &token_stream = ttree.to_token_stream ();
+ for (auto &token : token_stream)
+ {
+ switch (token.get ()->get_id ())
+ {
+ case TokenId::LEFT_PAREN:
+ // correct case
+ break;
+ case TokenId::LEFT_CURLY:
+ case TokenId::LEFT_SQUARE:
+ rust_error_at (token.get ()->get_locus (),
+ "wrong meta list delimiters");
+ rust_inform (token.get ()->get_locus (),
+ "the delimiters should be %<(%> and %<)%>");
+ break;
+ default:
+ break;
+ }
+ }
+}
void
AttributeChecker::visit (AST::IdentifierExpr &)
diff --git a/gcc/testsuite/rust/compile/wrong_meta_list_delims.rs
b/gcc/testsuite/rust/compile/wrong_meta_list_delims.rs
new file mode 100644
index 000000000..ddef3b87d
--- /dev/null
+++ b/gcc/testsuite/rust/compile/wrong_meta_list_delims.rs
@@ -0,0 +1,12 @@
+// { dg-additional-options "-frust-compat-version=1.84" }
+
+// check if the delimiters used for attributes is `(` and not either of `{`
`[`
+
+#![feature(no_core)]
+#![no_core]
+
+#[allow{unused}] // { dg-error "wrong meta list delimiters" "" { target *-*-*
} }
+struct A {}
+
+#[allow[unused]] // { dg-error "wrong meta list delimiters" "" { target *-*-*
} }
+struct B {}
\ No newline at end of file
base-commit: fc0c9e3326124b300cb2ad918629ca469eaa7ade
--
2.55.0