@@ -59,6 +59,17 @@ pub enum AttributeType {
59
59
CrateLevel ,
60
60
}
61
61
62
+ #[ derive( Copy , Clone , PartialEq , Debug ) ]
63
+ #[ allow( dead_code) ]
64
+ pub enum AttributeSafety {
65
+ /// Normal attribute that does not need `#[unsafe(...)]`
66
+ Normal ,
67
+
68
+ /// Unsafe attribute that requires safety obligations
69
+ /// to be discharged
70
+ Unsafe ,
71
+ }
72
+
62
73
#[ derive( Clone , Copy ) ]
63
74
pub enum AttributeGate {
64
75
/// Is gated by a given feature gate, reason
@@ -177,6 +188,18 @@ macro_rules! ungated {
177
188
name: sym:: $attr,
178
189
encode_cross_crate: $encode_cross_crate,
179
190
type_: $typ,
191
+ safety: AttributeSafety :: Normal ,
192
+ template: $tpl,
193
+ gate: Ungated ,
194
+ duplicates: $duplicates,
195
+ }
196
+ } ;
197
+ ( unsafe $attr: ident, $typ: expr, $tpl: expr, $duplicates: expr, $encode_cross_crate: expr $( , ) ?) => {
198
+ BuiltinAttribute {
199
+ name: sym:: $attr,
200
+ encode_cross_crate: $encode_cross_crate,
201
+ type_: $typ,
202
+ safety: AttributeSafety :: Unsafe ,
180
203
template: $tpl,
181
204
gate: Ungated ,
182
205
duplicates: $duplicates,
@@ -190,6 +213,7 @@ macro_rules! gated {
190
213
name: sym:: $attr,
191
214
encode_cross_crate: $encode_cross_crate,
192
215
type_: $typ,
216
+ safety: AttributeSafety :: Normal ,
193
217
template: $tpl,
194
218
duplicates: $duplicates,
195
219
gate: Gated ( Stability :: Unstable , sym:: $gate, $msg, cfg_fn!( $gate) ) ,
@@ -200,6 +224,29 @@ macro_rules! gated {
200
224
name: sym:: $attr,
201
225
encode_cross_crate: $encode_cross_crate,
202
226
type_: $typ,
227
+ safety: AttributeSafety :: Normal ,
228
+ template: $tpl,
229
+ duplicates: $duplicates,
230
+ gate: Gated ( Stability :: Unstable , sym:: $attr, $msg, cfg_fn!( $attr) ) ,
231
+ }
232
+ } ;
233
+ ( unsafe $attr: ident, $typ: expr, $tpl: expr, $duplicates: expr, $encode_cross_crate: expr, $gate: ident, $msg: expr $( , ) ?) => {
234
+ BuiltinAttribute {
235
+ name: sym:: $attr,
236
+ encode_cross_crate: $encode_cross_crate,
237
+ type_: $typ,
238
+ safety: AttributeSafety :: Unsafe ,
239
+ template: $tpl,
240
+ duplicates: $duplicates,
241
+ gate: Gated ( Stability :: Unstable , sym:: $gate, $msg, cfg_fn!( $gate) ) ,
242
+ }
243
+ } ;
244
+ ( unsafe $attr: ident, $typ: expr, $tpl: expr, $duplicates: expr, $encode_cross_crate: expr, $msg: expr $( , ) ?) => {
245
+ BuiltinAttribute {
246
+ name: sym:: $attr,
247
+ encode_cross_crate: $encode_cross_crate,
248
+ type_: $typ,
249
+ safety: AttributeSafety :: Unsafe ,
203
250
template: $tpl,
204
251
duplicates: $duplicates,
205
252
gate: Gated ( Stability :: Unstable , sym:: $attr, $msg, cfg_fn!( $attr) ) ,
@@ -228,6 +275,7 @@ macro_rules! rustc_attr {
228
275
name: sym:: $attr,
229
276
encode_cross_crate: $encode_cross_crate,
230
277
type_: $typ,
278
+ safety: AttributeSafety :: Normal ,
231
279
template: $tpl,
232
280
duplicates: $duplicates,
233
281
gate: Gated ( Stability :: Unstable , sym:: rustc_attrs, $msg, cfg_fn!( rustc_attrs) ) ,
@@ -258,6 +306,7 @@ pub struct BuiltinAttribute {
258
306
/// Otherwise, it can only be used in the local crate.
259
307
pub encode_cross_crate : EncodeCrossCrate ,
260
308
pub type_ : AttributeType ,
309
+ pub safety : AttributeSafety ,
261
310
pub template : AttributeTemplate ,
262
311
pub duplicates : AttributeDuplicates ,
263
312
pub gate : AttributeGate ,
@@ -375,9 +424,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
375
424
) ,
376
425
ungated ! ( no_link, Normal , template!( Word ) , WarnFollowing , EncodeCrossCrate :: No ) ,
377
426
ungated ! ( repr, Normal , template!( List : "C" ) , DuplicatesOk , EncodeCrossCrate :: No ) ,
378
- ungated ! ( export_name, Normal , template!( NameValueStr : "name" ) , FutureWarnPreceding , EncodeCrossCrate :: No ) ,
379
- ungated ! ( link_section, Normal , template!( NameValueStr : "name" ) , FutureWarnPreceding , EncodeCrossCrate :: No ) ,
380
- ungated ! ( no_mangle, Normal , template!( Word ) , WarnFollowing , EncodeCrossCrate :: No ) ,
427
+ ungated ! ( unsafe export_name, Normal , template!( NameValueStr : "name" ) , FutureWarnPreceding , EncodeCrossCrate :: No ) ,
428
+ ungated ! ( unsafe link_section, Normal , template!( NameValueStr : "name" ) , FutureWarnPreceding , EncodeCrossCrate :: No ) ,
429
+ ungated ! ( unsafe no_mangle, Normal , template!( Word ) , WarnFollowing , EncodeCrossCrate :: No ) ,
381
430
ungated ! ( used, Normal , template!( Word , List : "compiler|linker" ) , WarnFollowing , EncodeCrossCrate :: No ) ,
382
431
ungated ! ( link_ordinal, Normal , template!( List : "ordinal" ) , ErrorPreceding , EncodeCrossCrate :: Yes ) ,
383
432
@@ -851,6 +900,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
851
900
// FIXME: This can be `true` once we always use `tcx.is_diagnostic_item`.
852
901
encode_cross_crate : EncodeCrossCrate :: Yes ,
853
902
type_ : Normal ,
903
+ safety : AttributeSafety :: Normal ,
854
904
template : template ! ( NameValueStr : "name" ) ,
855
905
duplicates : ErrorFollowing ,
856
906
gate : Gated (
0 commit comments