@@ -90,8 +90,6 @@ static const BuiltinAttrDefinition __definitions[]
9090 {Attrs::PROC_MACRO, EXPANSION},
9191 {Attrs::PROC_MACRO_DERIVE, EXPANSION},
9292 {Attrs::PROC_MACRO_ATTRIBUTE, EXPANSION},
93-
94- {Attrs::DERIVE, EXPANSION},
9593 // FIXME: This is not implemented yet, see
9694 // https://github.com/Rust-GCC/gccrs/issues/1475
9795 {Attrs::TARGET_FEATURE, CODE_GENERATION},
@@ -101,7 +99,6 @@ static const BuiltinAttrDefinition __definitions[]
10199 {Attrs::RUSTC_INHERIT_OVERFLOW_CHECKS, CODE_GENERATION},
102100 {Attrs::STABLE, STATIC_ANALYSIS},
103101 {Attrs::UNSTABLE, STATIC_ANALYSIS},
104-
105102 // assuming we keep these for static analysis
106103 {Attrs::RUSTC_PROMOTABLE, CODE_GENERATION},
107104 {Attrs::RUSTC_CONST_STABLE, STATIC_ANALYSIS},
@@ -114,23 +111,22 @@ static const BuiltinAttrDefinition __definitions[]
114111 {Attrs::RUSTC_RESERVATION_IMPL, TYPE_CHECK},
115112 {Attrs::RUSTC_PAREN_SUGAR, TYPE_CHECK},
116113 {Attrs::RUSTC_NONNULL_OPTIMIZATION_GUARANTEED, TYPE_CHECK},
117-
118114 {Attrs::RUSTC_LAYOUT_SCALAR_VALID_RANGE_START, CODE_GENERATION},
119-
120115 // TODO: be careful about calling functions marked with this?
121116 {Attrs::RUSTC_ARGS_REQUIRED_CONST, CODE_GENERATION},
122-
123117 {Attrs::PRELUDE_IMPORT, NAME_RESOLUTION},
124-
125118 {Attrs::RUSTC_DIAGNOSTIC_ITEM, STATIC_ANALYSIS},
126119 {Attrs::RUSTC_ON_UNIMPLEMENTED, STATIC_ANALYSIS},
127-
128120 {Attrs::FUNDAMENTAL, TYPE_CHECK},
129121 {Attrs::NON_EXHAUSTIVE, TYPE_CHECK},
130122 {Attrs::RUSTFMT, EXTERNAL},
131-
132123 {Attrs::TEST, CODE_GENERATION}};
133124
125+ static const std::set<std::string> __outer_attributes
126+ = {Attrs::INLINE, Attrs::DERIVE_ATTR, Attrs::ALLOW_INTERNAL_UNSTABLE,
127+ Attrs::LANG, Attrs::REPR, Attrs::PATH,
128+ Attrs::TARGET_FEATURE, Attrs::TEST};
129+
134130BuiltinAttributeMappings *
135131BuiltinAttributeMappings::get ()
136132{
@@ -326,6 +322,26 @@ check_proc_macro_non_root (AST::AttrVec attributes, location_t loc)
326322 }
327323}
328324
325+ void
326+ AttributeChecker::check_inner_attribute (const AST::Attribute &attribute)
327+ {
328+ BuiltinAttrDefinition result;
329+
330+ if (!is_builtin (attribute, result))
331+ return ;
332+
333+ if (__outer_attributes.find (result.name ) != __outer_attributes.end ())
334+ rust_error_at (attribute.get_locus (),
335+ " attribute cannot be used at crate level" );
336+ }
337+
338+ void
339+ AttributeChecker::check_inner_attributes (const AST::AttrVec &attributes)
340+ {
341+ for (auto &attr : attributes)
342+ check_inner_attribute (attr);
343+ }
344+
329345void
330346AttributeChecker::check_attribute (const AST::Attribute &attribute)
331347{
@@ -356,15 +372,6 @@ AttributeChecker::check_attribute (const AST::Attribute &attribute)
356372 check_doc_attribute (attribute);
357373}
358374
359- void
360- AttributeChecker::check_inner_attributes (const AST::AttrVec &attributes)
361- {
362- for (auto &attr : attributes)
363- if (attr.is_derive ())
364- rust_error_at (attr.get_locus (),
365- " derive attribute cannot be used at crate level" );
366- }
367-
368375void
369376AttributeChecker::check_attributes (const AST::AttrVec &attributes)
370377{
0 commit comments