Skip to content

Commit 7208108

Browse files
committed
attributes: Add class for sharing methods on attributes.
gcc/rust/ChangeLog: * util/rust-attributes.h (class Attributes): New. * util/rust-attributes.cc: Implement Attributes::is_known(). * ast/rust-collect-lang-items.cc (is_known_attribute): Remove. (get_lang_item_attr): Call Attributes::is_known() instead. * hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_outer_attributes): Likewise. (ASTLoweringBase::is_known_attribute): Remove.
1 parent 6b7e055 commit 7208108

File tree

4 files changed

+18
-20
lines changed

4 files changed

+18
-20
lines changed

gcc/rust/ast/rust-collect-lang-items.cc

+1-12
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,14 @@
2727
namespace Rust {
2828
namespace AST {
2929

30-
// FIXME: Before merging: De-duplicate with function in rust-ast-lower-base.cc
31-
bool
32-
is_known_attribute (const std::string &attribute_path)
33-
{
34-
const auto &lookup
35-
= Analysis::BuiltinAttributeMappings::get ()->lookup_builtin (
36-
attribute_path);
37-
38-
return !lookup.is_error ();
39-
}
40-
4130
template <typename T>
4231
tl::optional<LangItem::Kind>
4332
get_lang_item_attr (const T &maybe_lang_item)
4433
{
4534
for (const auto &attr : maybe_lang_item.get_outer_attrs ())
4635
{
4736
const auto &str_path = attr.get_path ().as_string ();
48-
if (!is_known_attribute (str_path))
37+
if (!Analysis::Attributes::is_known (str_path))
4938
{
5039
rust_error_at (attr.get_locus (), "unknown attribute");
5140
continue;

gcc/rust/hir/rust-ast-lower-base.cc

+2-8
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "rust-diagnostics.h"
2626
#include "rust-item.h"
2727
#include "rust-system.h"
28+
#include "rust-attributes.h"
2829

2930
namespace Rust {
3031
namespace HIR {
@@ -751,7 +752,7 @@ ASTLoweringBase::handle_outer_attributes (const ItemWrapper &item)
751752
for (const auto &attr : item.get_outer_attrs ())
752753
{
753754
const auto &str_path = attr.get_path ().as_string ();
754-
if (!is_known_attribute (str_path))
755+
if (!Analysis::Attributes::is_known (str_path))
755756
{
756757
rust_error_at (attr.get_locus (), "unknown attribute");
757758
continue;
@@ -814,13 +815,6 @@ ASTLoweringBase::handle_lang_item_attribute (const ItemWrapper &item,
814815
rust_error_at (attr.get_locus (), "unknown lang item");
815816
}
816817

817-
bool
818-
ASTLoweringBase::is_known_attribute (const std::string &attribute_path) const
819-
{
820-
const auto &lookup = attr_mappings->lookup_builtin (attribute_path);
821-
return !lookup.is_error ();
822-
}
823-
824818
bool
825819
ASTLoweringBase::attribute_handled_in_another_pass (
826820
const std::string &attribute_path) const

gcc/rust/util/rust-attributes.cc

+9
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@
2929
namespace Rust {
3030
namespace Analysis {
3131

32+
bool
33+
Attributes::is_known (const std::string &attribute_path)
34+
{
35+
const auto &lookup
36+
= BuiltinAttributeMappings::get ()->lookup_builtin (attribute_path);
37+
38+
return !lookup.is_error ();
39+
}
40+
3241
using Attrs = Values::Attributes;
3342

3443
// https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_feature/builtin_attrs.rs.html#248

gcc/rust/util/rust-attributes.h

+6
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
namespace Rust {
2626
namespace Analysis {
2727

28+
class Attributes
29+
{
30+
public:
31+
static bool is_known (const std::string &attribute_path);
32+
};
33+
2834
enum CompilerPass
2935
{
3036
UNKNOWN,

0 commit comments

Comments
 (0)