@@ -277,6 +277,102 @@ check_doc_attribute (const AST::Attribute &attribute)
277277 }
278278}
279279
280+ static void
281+ check_deprecated_attribute (const AST::Attribute &attribute)
282+ {
283+ const auto &input = attribute.get_attr_input ();
284+
285+ if (input.get_attr_input_type () != AST::AttrInput::META_ITEM)
286+ return ;
287+
288+ auto &meta = static_cast <const AST::AttrInputMetaItemContainer &> (input);
289+
290+ for (auto ¤t : meta.get_items ())
291+ {
292+ switch (current->get_kind ())
293+ {
294+ case AST::MetaItemInner::Kind::MetaItem:
295+ {
296+ auto *meta_item =
297+ static_cast <AST::MetaItem *> (current.get ());
298+
299+ switch (meta_item->get_item_kind ())
300+ {
301+ case AST::MetaItem::ItemKind::NameValueStr:
302+ {
303+ auto *nv =
304+ static_cast <AST::MetaNameValueStr *> (meta_item);
305+
306+ const std::string key = nv->get_name ().as_string ();
307+
308+ if (key != " since" && key != " note" )
309+ {
310+ rust_error_at (nv->get_locus (),
311+ " unknown meta item %qs" ,
312+ key.c_str ());
313+ rust_inform (nv->get_locus (),
314+ " expected one of %<'since'%>, %<'note'%>" );
315+ }
316+ }
317+ break ;
318+
319+ case AST::MetaItem::ItemKind::Path:
320+ {
321+ // #[deprecated(a,a)]
322+ auto *p =
323+ static_cast <AST::MetaItemPath *> (meta_item);
324+
325+ std::string ident = p->get_path ().as_string ();
326+
327+ rust_error_at (p->get_locus (),
328+ " unknown meta item %qs" ,
329+ ident.c_str ());
330+ rust_inform (p->get_locus (),
331+ " expected one of %<'since'%>, %<'note'%>" );
332+ }
333+ break ;
334+
335+ case AST::MetaItem::ItemKind::Word:
336+ {
337+ // #[deprecated("a")]
338+ auto *w =
339+ static_cast <AST::MetaWord *> (meta_item);
340+
341+ rust_error_at (w->get_locus (),
342+ " item in %<'deprecated'%> must be a key/value pair" );
343+ }
344+ break ;
345+
346+ case AST::MetaItem::ItemKind::PathExpr:
347+ {
348+ // #[deprecated(since=a)]
349+ auto *px =
350+ static_cast <AST::MetaItemPathExpr *> (meta_item);
351+
352+ rust_error_at (px->get_locus (),
353+ " expected unsuffixed literal or identifier, found %qs" ,
354+ px->get_expr ().as_string ().c_str ());
355+ }
356+ break ;
357+
358+ case AST::MetaItem::ItemKind::Seq:
359+ case AST::MetaItem::ItemKind::ListPaths:
360+ case AST::MetaItem::ItemKind::ListNameValueStr:
361+ default :
362+ gcc_unreachable ();
363+ break ;
364+ }
365+ }
366+ break ;
367+
368+ case AST::MetaItemInner::Kind::LitExpr:
369+ default :
370+ gcc_unreachable ();
371+ break ;
372+ }
373+ }
374+ }
375+
280376static bool
281377is_proc_macro_type (const AST::Attribute &attribute)
282378{
@@ -370,6 +466,8 @@ AttributeChecker::check_attribute (const AST::Attribute &attribute)
370466 // and costly
371467 if (result.name == Attrs::DOC)
372468 check_doc_attribute (attribute);
469+ else if (result.name == Attrs::DEPRECATED)
470+ check_deprecated_attribute (attribute);
373471}
374472
375473void
0 commit comments