Auto merge of #128771 - carbotaniuman:stabilize_unsafe_attr, r=nnethe… · rust-lang/rust@37d56da (original) (raw)
`@@ -7,9 +7,7 @@ use rustc_ast::{
`
7
7
`NestedMetaItem, Safety,
`
8
8
`};
`
9
9
`use rustc_errors::{Applicability, FatalError, PResult};
`
10
``
`-
use rustc_feature::{
`
11
``
`-
AttributeSafety, AttributeTemplate, BuiltinAttribute, Features, BUILTIN_ATTRIBUTE_MAP,
`
12
``
`-
};
`
``
10
`+
use rustc_feature::{AttributeSafety, AttributeTemplate, BuiltinAttribute, BUILTIN_ATTRIBUTE_MAP};
`
13
11
`use rustc_session::errors::report_lit_error;
`
14
12
`use rustc_session::lint::builtin::{ILL_FORMED_ATTRIBUTE_INPUT, UNSAFE_ATTR_OUTSIDE_UNSAFE};
`
15
13
`use rustc_session::lint::BuiltinLintDiag;
`
`@@ -18,7 +16,7 @@ use rustc_span::{sym, BytePos, Span, Symbol};
`
18
16
``
19
17
`use crate::{errors, parse_in};
`
20
18
``
21
``
`-
pub fn check_attr(features: &Features, psess: &ParseSess, attr: &Attribute) {
`
``
19
`+
pub fn check_attr(psess: &ParseSess, attr: &Attribute) {
`
22
20
`if attr.is_doc_comment() {
`
23
21
`return;
`
24
22
`}
`
`@@ -28,17 +26,17 @@ pub fn check_attr(features: &Features, psess: &ParseSess, attr: &Attribute) {
`
28
26
``
29
27
`// All non-builtin attributes are considered safe
`
30
28
`let safety = attr_info.map(|x| x.safety).unwrap_or(AttributeSafety::Normal);
`
31
``
`-
check_attribute_safety(features, psess, safety, attr);
`
``
29
`+
check_attribute_safety(psess, safety, attr);
`
32
30
``
33
31
`// Check input tokens for built-in and key-value attributes.
`
34
32
`match attr_info {
`
35
33
`` // rustc_dummy
doesn't have any restrictions specific to built-in attributes.
``
36
34
`Some(BuiltinAttribute { name, template, .. }) if *name != sym::rustc_dummy => {
`
37
35
`match parse_meta(psess, attr) {
`
38
36
`// Don't check safety again, we just did that
`
39
``
`-
Ok(meta) => check_builtin_meta_item(
`
40
``
`-
features, psess, &meta, attr.style, *name, *template, false,
`
41
``
`-
),
`
``
37
`+
Ok(meta) => {
`
``
38
`+
check_builtin_meta_item(psess, &meta, attr.style, *name, *template, false)
`
``
39
`+
}
`
42
40
`Err(err) => {
`
43
41
` err.emit();
`
44
42
`}
`
`@@ -157,16 +155,7 @@ fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaIte
`
157
155
`}
`
158
156
`}
`
159
157
``
160
``
`-
pub fn check_attribute_safety(
`
161
``
`-
features: &Features,
`
162
``
`-
psess: &ParseSess,
`
163
``
`-
safety: AttributeSafety,
`
164
``
`-
attr: &Attribute,
`
165
``
`-
) {
`
166
``
`-
if !features.unsafe_attributes {
`
167
``
`-
return;
`
168
``
`-
}
`
169
``
-
``
158
`+
pub fn check_attribute_safety(psess: &ParseSess, safety: AttributeSafety, attr: &Attribute) {
`
170
159
`let attr_item = attr.get_normal_item();
`
171
160
``
172
161
`if safety == AttributeSafety::Unsafe {
`
`@@ -215,21 +204,18 @@ pub fn check_attribute_safety(
`
215
204
``
216
205
`` // Called by check_builtin_meta_item
and code that manually denies
``
217
206
`` // unsafe(...)
in cfg
``
218
``
`-
pub fn deny_builtin_meta_unsafety(features: &Features, psess: &ParseSess, meta: &MetaItem) {
`
``
207
`+
pub fn deny_builtin_meta_unsafety(psess: &ParseSess, meta: &MetaItem) {
`
219
208
`// This only supports denying unsafety right now - making builtin attributes
`
220
209
`` // support unsafety will requite us to thread the actual Attribute
through
``
221
210
`// for the nice diagnostics.
`
222
``
`-
if features.unsafe_attributes {
`
223
``
`-
if let Safety::Unsafe(unsafe_span) = meta.unsafety {
`
224
``
`-
psess
`
225
``
`-
.dcx()
`
226
``
`-
.emit_err(errors::InvalidAttrUnsafe { span: unsafe_span, name: meta.path.clone() });
`
227
``
`-
}
`
``
211
`+
if let Safety::Unsafe(unsafe_span) = meta.unsafety {
`
``
212
`+
psess
`
``
213
`+
.dcx()
`
``
214
`+
.emit_err(errors::InvalidAttrUnsafe { span: unsafe_span, name: meta.path.clone() });
`
228
215
`}
`
229
216
`}
`
230
217
``
231
218
`pub fn check_builtin_meta_item(
`
232
``
`-
features: &Features,
`
233
219
`psess: &ParseSess,
`
234
220
`meta: &MetaItem,
`
235
221
`style: ast::AttrStyle,
`
`@@ -246,7 +232,7 @@ pub fn check_builtin_meta_item(
`
246
232
`}
`
247
233
``
248
234
`if deny_unsafety {
`
249
``
`-
deny_builtin_meta_unsafety(features, psess, meta);
`
``
235
`+
deny_builtin_meta_unsafety(psess, meta);
`
250
236
`}
`
251
237
`}
`
252
238
``