From: Ashwani Kumar Kamal <[email protected]>
Deprecated attributes need to be checked and proper errors
should be produced on bad arguments.
gcc/rust/ChangeLog:
* util/rust-attributes.cc: New function to handle deprecated attribute
checking
Signed-off-by: Ashwani Kumar Kamal <[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/d74c8b4692568bbfc647ef13ac46050d0a53b0f2
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4327
gcc/rust/util/rust-attributes.cc | 93 ++++++++++++++++++++++++++++++++
1 file changed, 93 insertions(+)
diff --git a/gcc/rust/util/rust-attributes.cc b/gcc/rust/util/rust-attributes.cc
index 70f26e7ce..ea6d1cd17 100644
--- a/gcc/rust/util/rust-attributes.cc
+++ b/gcc/rust/util/rust-attributes.cc
@@ -277,6 +277,97 @@ check_doc_attribute (const AST::Attribute &attribute)
}
}
+static void
+check_deprecated_attribute (const AST::Attribute &attribute)
+{
+ const auto &input = attribute.get_attr_input ();
+
+ if (input.get_attr_input_type () != AST::AttrInput::META_ITEM)
+ return;
+
+ auto &meta = static_cast<const AST::AttrInputMetaItemContainer &> (input);
+
+ for (auto ¤t : meta.get_items ())
+ {
+ switch (current->get_kind ())
+ {
+ case AST::MetaItemInner::Kind::MetaItem:
+ {
+ auto *meta_item = static_cast<AST::MetaItem *> (current.get ());
+
+ switch (meta_item->get_item_kind ())
+ {
+ case AST::MetaItem::ItemKind::NameValueStr:
+ {
+ auto *nv = static_cast<AST::MetaNameValueStr *> (meta_item);
+
+ const std::string key = nv->get_name ().as_string ();
+
+ if (key != "since" && key != "note")
+ {
+ rust_error_at (nv->get_locus (), "unknown meta item %qs",
+ key.c_str ());
+ rust_inform (nv->get_locus (),
+ "expected one of %<since%>, %<note%>");
+ }
+ }
+ break;
+
+ case AST::MetaItem::ItemKind::Path:
+ {
+ // #[deprecated(a,a)]
+ auto *p = static_cast<AST::MetaItemPath *> (meta_item);
+
+ std::string ident = p->get_path ().as_string ();
+
+ rust_error_at (p->get_locus (), "unknown meta item %qs",
+ ident.c_str ());
+ rust_inform (p->get_locus (),
+ "expected one of %<since%>, %<note%>");
+ }
+ break;
+
+ case AST::MetaItem::ItemKind::Word:
+ {
+ // #[deprecated("a")]
+ auto *w = static_cast<AST::MetaWord *> (meta_item);
+
+ rust_error_at (
+ w->get_locus (),
+ "item in %<deprecated%> must be a key/value pair");
+ }
+ break;
+
+ case AST::MetaItem::ItemKind::PathExpr:
+ {
+ // #[deprecated(since=a)]
+ auto *px = static_cast<AST::MetaItemPathExpr *> (meta_item);
+
+ rust_error_at (
+ px->get_locus (),
+ "expected unsuffixed literal or identifier, found %qs",
+ px->get_expr ().as_string ().c_str ());
+ }
+ break;
+
+ case AST::MetaItem::ItemKind::Seq:
+ case AST::MetaItem::ItemKind::ListPaths:
+ case AST::MetaItem::ItemKind::ListNameValueStr:
+ default:
+ gcc_unreachable ();
+ break;
+ }
+ }
+ break;
+
+ case AST::MetaItemInner::Kind::LitExpr:
+ default:
+ gcc_unreachable ();
+ break;
+ }
+ }
+}
+
static bool
is_proc_macro_type (const AST::Attribute &attribute)
{
@@ -370,6 +461,8 @@ AttributeChecker::check_attribute (const AST::Attribute
&attribute)
// and costly
if (result.name == Attrs::DOC)
check_doc_attribute (attribute);
+ else if (result.name == Attrs::DEPRECATED)
+ check_deprecated_attribute (attribute);
}
void
base-commit: 9f4e0804d721956925ca42f8f22513949bc5c16a
--
2.52.0