@@ -67,69 +67,60 @@ using Attrs = Values::Attributes;
6767
6868// https://doc.rust-lang.org/stable/nightly-rustc/src/rustc_feature/builtin_attrs.rs.html#248
6969static const BuiltinAttrDefinition __definitions[]
70- = {{Attrs::INLINE, CODE_GENERATION},
71- {Attrs::COLD, CODE_GENERATION},
72- {Attrs::CFG, EXPANSION},
73- {Attrs::CFG_ATTR, EXPANSION},
74- {Attrs::DERIVE_ATTR, EXPANSION},
75- {Attrs::DEPRECATED, STATIC_ANALYSIS},
76- {Attrs::ALLOW, STATIC_ANALYSIS},
77- {Attrs::ALLOW_INTERNAL_UNSTABLE, STATIC_ANALYSIS},
78- {Attrs::DOC, HIR_LOWERING},
79- {Attrs::MUST_USE, STATIC_ANALYSIS},
80- {Attrs::LANG, HIR_LOWERING},
81- {Attrs::LINK_NAME, CODE_GENERATION},
82- {Attrs::LINK_SECTION, CODE_GENERATION},
83- {Attrs::NO_MANGLE, CODE_GENERATION},
84- {Attrs::REPR, CODE_GENERATION},
85- {Attrs::RUSTC_BUILTIN_MACRO, EXPANSION},
86- {Attrs::RUSTC_MACRO_TRANSPARENCY, EXPANSION},
87- {Attrs::PATH, EXPANSION},
88- {Attrs::MACRO_USE, NAME_RESOLUTION},
89- {Attrs::MACRO_EXPORT, NAME_RESOLUTION},
90- {Attrs::PROC_MACRO, EXPANSION},
91- {Attrs::PROC_MACRO_DERIVE, EXPANSION},
92- {Attrs::PROC_MACRO_ATTRIBUTE, EXPANSION},
93-
94- {Attrs::DERIVE, EXPANSION},
70+ = {{Attrs::INLINE, CODE_GENERATION, false },
71+ {Attrs::COLD, CODE_GENERATION, true },
72+ {Attrs::CFG, EXPANSION, true },
73+ {Attrs::CFG_ATTR, EXPANSION, true },
74+ {Attrs::DERIVE_ATTR, EXPANSION, false },
75+ {Attrs::DEPRECATED, STATIC_ANALYSIS, true },
76+ {Attrs::ALLOW, STATIC_ANALYSIS, true },
77+ {Attrs::ALLOW_INTERNAL_UNSTABLE, STATIC_ANALYSIS, false },
78+ {Attrs::DOC, HIR_LOWERING, true },
79+ {Attrs::MUST_USE, STATIC_ANALYSIS, true },
80+ {Attrs::LANG, HIR_LOWERING, false },
81+ {Attrs::LINK_NAME, CODE_GENERATION, true },
82+ {Attrs::LINK_SECTION, CODE_GENERATION, true },
83+ {Attrs::NO_MANGLE, CODE_GENERATION, true },
84+ {Attrs::REPR, CODE_GENERATION, false },
85+ {Attrs::RUSTC_BUILTIN_MACRO, EXPANSION, true },
86+ {Attrs::RUSTC_MACRO_TRANSPARENCY, EXPANSION, true },
87+ {Attrs::PATH, EXPANSION, false },
88+ {Attrs::MACRO_USE, NAME_RESOLUTION, true },
89+ {Attrs::MACRO_EXPORT, NAME_RESOLUTION, true },
90+ {Attrs::PROC_MACRO, EXPANSION, true },
91+ {Attrs::PROC_MACRO_DERIVE, EXPANSION, true },
92+ {Attrs::PROC_MACRO_ATTRIBUTE, EXPANSION, true },
9593 // FIXME: This is not implemented yet, see
9694 // https://github.com/Rust-GCC/gccrs/issues/1475
97- {Attrs::TARGET_FEATURE, CODE_GENERATION},
95+ {Attrs::TARGET_FEATURE, CODE_GENERATION, false },
9896 // From now on, these are reserved by the compiler and gated through
9997 // #![feature(rustc_attrs)]
100- {Attrs::RUSTC_DEPRECATED, STATIC_ANALYSIS},
101- {Attrs::RUSTC_INHERIT_OVERFLOW_CHECKS, CODE_GENERATION},
102- {Attrs::STABLE, STATIC_ANALYSIS},
103- {Attrs::UNSTABLE, STATIC_ANALYSIS},
104-
98+ {Attrs::RUSTC_DEPRECATED, STATIC_ANALYSIS, true },
99+ {Attrs::RUSTC_INHERIT_OVERFLOW_CHECKS, CODE_GENERATION, true },
100+ {Attrs::STABLE, STATIC_ANALYSIS, true },
101+ {Attrs::UNSTABLE, STATIC_ANALYSIS, true },
105102 // assuming we keep these for static analysis
106- {Attrs::RUSTC_PROMOTABLE, CODE_GENERATION},
107- {Attrs::RUSTC_CONST_STABLE, STATIC_ANALYSIS},
108- {Attrs::RUSTC_CONST_UNSTABLE, STATIC_ANALYSIS},
109- {Attrs::RUSTC_ALLOW_CONST_FN_UNSTABLE, STATIC_ANALYSIS},
110- {Attrs::PRELUDE_IMPORT, NAME_RESOLUTION},
111- {Attrs::TRACK_CALLER, CODE_GENERATION},
112- {Attrs::RUSTC_SPECIALIZATION_TRAIT, TYPE_CHECK},
113- {Attrs::RUSTC_UNSAFE_SPECIALIZATION_MARKER, TYPE_CHECK},
114- {Attrs::RUSTC_RESERVATION_IMPL, TYPE_CHECK},
115- {Attrs::RUSTC_PAREN_SUGAR, TYPE_CHECK},
116- {Attrs::RUSTC_NONNULL_OPTIMIZATION_GUARANTEED, TYPE_CHECK},
117-
118- {Attrs::RUSTC_LAYOUT_SCALAR_VALID_RANGE_START, CODE_GENERATION},
119-
103+ {Attrs::RUSTC_PROMOTABLE, CODE_GENERATION, true },
104+ {Attrs::RUSTC_CONST_STABLE, STATIC_ANALYSIS, true },
105+ {Attrs::RUSTC_CONST_UNSTABLE, STATIC_ANALYSIS, true },
106+ {Attrs::RUSTC_ALLOW_CONST_FN_UNSTABLE, STATIC_ANALYSIS, true },
107+ {Attrs::PRELUDE_IMPORT, NAME_RESOLUTION, true },
108+ {Attrs::TRACK_CALLER, CODE_GENERATION, true },
109+ {Attrs::RUSTC_SPECIALIZATION_TRAIT, TYPE_CHECK, true },
110+ {Attrs::RUSTC_UNSAFE_SPECIALIZATION_MARKER, TYPE_CHECK, true },
111+ {Attrs::RUSTC_RESERVATION_IMPL, TYPE_CHECK, true },
112+ {Attrs::RUSTC_PAREN_SUGAR, TYPE_CHECK, true },
113+ {Attrs::RUSTC_NONNULL_OPTIMIZATION_GUARANTEED, TYPE_CHECK, true },
114+ {Attrs::RUSTC_LAYOUT_SCALAR_VALID_RANGE_START, CODE_GENERATION, true },
120115 // TODO: be careful about calling functions marked with this?
121- {Attrs::RUSTC_ARGS_REQUIRED_CONST, CODE_GENERATION},
122-
123- {Attrs::PRELUDE_IMPORT, NAME_RESOLUTION},
124-
125- {Attrs::RUSTC_DIAGNOSTIC_ITEM, STATIC_ANALYSIS},
126- {Attrs::RUSTC_ON_UNIMPLEMENTED, STATIC_ANALYSIS},
127-
128- {Attrs::FUNDAMENTAL, TYPE_CHECK},
129- {Attrs::NON_EXHAUSTIVE, TYPE_CHECK},
130- {Attrs::RUSTFMT, EXTERNAL},
131-
132- {Attrs::TEST, CODE_GENERATION}};
116+ {Attrs::RUSTC_ARGS_REQUIRED_CONST, CODE_GENERATION, true },
117+ {Attrs::PRELUDE_IMPORT, NAME_RESOLUTION, true },
118+ {Attrs::RUSTC_DIAGNOSTIC_ITEM, STATIC_ANALYSIS, true },
119+ {Attrs::RUSTC_ON_UNIMPLEMENTED, STATIC_ANALYSIS, true },
120+ {Attrs::FUNDAMENTAL, TYPE_CHECK, true },
121+ {Attrs::NON_EXHAUSTIVE, TYPE_CHECK, true },
122+ {Attrs::RUSTFMT, EXTERNAL, true },
123+ {Attrs::TEST, CODE_GENERATION, false }};
133124
134125BuiltinAttributeMappings *
135126BuiltinAttributeMappings::get ()
@@ -326,6 +317,26 @@ check_proc_macro_non_root (AST::AttrVec attributes, location_t loc)
326317 }
327318}
328319
320+ void
321+ AttributeChecker::check_inner_attribute (const AST::Attribute &attribute)
322+ {
323+ BuiltinAttrDefinition result;
324+
325+ if (!is_builtin (attribute, result))
326+ return ;
327+
328+ if (!result.can_be_inner )
329+ rust_error_at (attribute.get_locus (),
330+ " attribute cannot be used at crate level" );
331+ }
332+
333+ void
334+ AttributeChecker::check_inner_attributes (const AST::AttrVec &attributes)
335+ {
336+ for (auto &attr : attributes)
337+ check_inner_attribute (attr);
338+ }
339+
329340void
330341AttributeChecker::check_attribute (const AST::Attribute &attribute)
331342{
@@ -356,15 +367,6 @@ AttributeChecker::check_attribute (const AST::Attribute &attribute)
356367 check_doc_attribute (attribute);
357368}
358369
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-
368370void
369371AttributeChecker::check_attributes (const AST::AttrVec &attributes)
370372{
0 commit comments