Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 37d56da

Browse files
committedAug 17, 2024
Auto merge of #128771 - carbotaniuman:stabilize_unsafe_attr, r=nnethercote
Stabilize `unsafe_attributes` # Stabilization report ## Summary This is a tracking issue for the RFC 3325: unsafe attributes We are stabilizing `#![feature(unsafe_attributes)]`, which makes certain attributes considered 'unsafe', meaning that they must be surrounded by an `unsafe(...)`, as in `#[unsafe(no_mangle)]`. RFC: rust-lang/rfcs#3325 Tracking issue: #123757 ## What is stabilized ### Summary of stabilization Certain attributes will now be designated as unsafe attributes, namely, `no_mangle`, `export_name`, and `link_section` (stable only), and these attributes will need to be called by surrounding them in `unsafe(...)` syntax. On editions prior to 2024, this is simply an edition lint, but it will become a hard error in 2024. This also works in `cfg_attr`, but `unsafe` is not allowed for any other attributes, including proc-macros ones. ```rust #[unsafe(no_mangle)] fn a() {} #[cfg_attr(any(), unsafe(export_name = "c"))] fn b() {} ``` For a table showing the attributes that were considered to be included in the list to require unsafe, and subsequent reasoning about why each such attribute was or was not included, see [this comment here](#124214 (comment)) ## Tests The relevant tests are in `tests/ui/rust-2024/unsafe-attributes` and `tests/ui/attributes/unsafe`.
2 parents feeba19 + de9b5c3 commit 37d56da

37 files changed

+64
-134
lines changed
 

‎compiler/rustc_ast_passes/src/ast_validation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ fn validate_generic_param_order(dcx: DiagCtxtHandle<'_>, generics: &[GenericPara
887887

888888
impl<'a> Visitor<'a> for AstValidator<'a> {
889889
fn visit_attribute(&mut self, attr: &Attribute) {
890-
validate_attr::check_attr(&self.features, &self.session.psess, attr);
890+
validate_attr::check_attr(&self.session.psess, attr);
891891
}
892892

893893
fn visit_ty(&mut self, ty: &'a Ty) {

‎compiler/rustc_ast_passes/src/feature_gate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
559559
gate_all!(mut_ref, "mutable by-reference bindings are experimental");
560560
gate_all!(precise_capturing, "precise captures on `impl Trait` are experimental");
561561
gate_all!(global_registration, "global registration is experimental");
562-
gate_all!(unsafe_attributes, "`#[unsafe()]` markers for attributes are experimental");
563562
gate_all!(return_type_notation, "return type notation is experimental");
564563

565564
if !visitor.features.never_patterns {

‎compiler/rustc_builtin_macros/src/cfg_accessible.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ impl MultiItemModifier for Expander {
4747
) -> ExpandResult<Vec<Annotatable>, Annotatable> {
4848
let template = AttributeTemplate { list: Some("path"), ..Default::default() };
4949
validate_attr::check_builtin_meta_item(
50-
&ecx.ecfg.features,
5150
&ecx.sess.psess,
5251
meta_item,
5352
ast::AttrStyle::Outer,

‎compiler/rustc_builtin_macros/src/derive.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ impl MultiItemModifier for Expander {
3838
let template =
3939
AttributeTemplate { list: Some("Trait1, Trait2, ..."), ..Default::default() };
4040
validate_attr::check_builtin_meta_item(
41-
features,
4241
&sess.psess,
4342
meta_item,
4443
ast::AttrStyle::Outer,

‎compiler/rustc_builtin_macros/src/util.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub(crate) fn check_builtin_macro_attribute(ecx: &ExtCtxt<'_>, meta_item: &MetaI
1717
// All the built-in macro attributes are "words" at the moment.
1818
let template = AttributeTemplate { word: true, ..Default::default() };
1919
validate_attr::check_builtin_meta_item(
20-
&ecx.ecfg.features,
2120
&ecx.sess.psess,
2221
meta_item,
2322
AttrStyle::Outer,

‎compiler/rustc_expand/src/config.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,7 @@ impl<'a> StripUnconfigured<'a> {
265265
/// is in the original source file. Gives a compiler error if the syntax of
266266
/// the attribute is incorrect.
267267
pub(crate) fn expand_cfg_attr(&self, cfg_attr: &Attribute, recursive: bool) -> Vec<Attribute> {
268-
validate_attr::check_attribute_safety(
269-
self.features.unwrap_or(&Features::default()),
270-
&self.sess.psess,
271-
AttributeSafety::Normal,
272-
&cfg_attr,
273-
);
268+
validate_attr::check_attribute_safety(&self.sess.psess, AttributeSafety::Normal, &cfg_attr);
274269

275270
let Some((cfg_predicate, expanded_attrs)) =
276271
rustc_parse::parse_cfg_attr(cfg_attr, &self.sess.psess)
@@ -395,11 +390,7 @@ impl<'a> StripUnconfigured<'a> {
395390
}
396391
};
397392

398-
validate_attr::deny_builtin_meta_unsafety(
399-
self.features.unwrap_or(&Features::default()),
400-
&self.sess.psess,
401-
&meta_item,
402-
);
393+
validate_attr::deny_builtin_meta_unsafety(&self.sess.psess, &meta_item);
403394

404395
(
405396
parse_cfg(&meta_item, self.sess).map_or(true, |meta_item| {

‎compiler/rustc_expand/src/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
18821882
let mut span: Option<Span> = None;
18831883
while let Some(attr) = attrs.next() {
18841884
rustc_ast_passes::feature_gate::check_attribute(attr, self.cx.sess, features);
1885-
validate_attr::check_attr(features, &self.cx.sess.psess, attr);
1885+
validate_attr::check_attr(&self.cx.sess.psess, attr);
18861886

18871887
let current_span = if let Some(sp) = span { sp.to(attr.span) } else { attr.span };
18881888
span = Some(current_span);

‎compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ declare_features! (
392392
(accepted, universal_impl_trait, "1.26.0", Some(34511)),
393393
/// Allows arbitrary delimited token streams in non-macro attributes.
394394
(accepted, unrestricted_attribute_tokens, "1.34.0", Some(55208)),
395+
/// Allows unsafe attributes.
396+
(accepted, unsafe_attributes, "CURRENT_RUSTC_VERSION", Some(123757)),
395397
/// The `unsafe_op_in_unsafe_fn` lint (allowed by default): no longer treat an unsafe function as an unsafe block.
396398
(accepted, unsafe_block_in_unsafe_fn, "1.52.0", Some(71668)),
397399
/// Allows unsafe on extern declarations and safety qualifiers over internal items.

‎compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,8 +622,6 @@ declare_features! (
622622
(unstable, type_changing_struct_update, "1.58.0", Some(86555)),
623623
/// Allows unnamed fields of struct and union type
624624
(incomplete, unnamed_fields, "1.74.0", Some(49804)),
625-
/// Allows unsafe attributes.
626-
(unstable, unsafe_attributes, "1.80.0", Some(123757)),
627625
/// Allows const generic parameters to be defined with types that
628626
/// are not `Sized`, e.g. `fn foo<const N: [u8]>() {`.
629627
(incomplete, unsized_const_params, "CURRENT_RUSTC_VERSION", Some(95174)),

‎compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4971,7 +4971,6 @@ declare_lint! {
49714971
/// ### Example
49724972
///
49734973
/// ```rust
4974-
/// #![feature(unsafe_attributes)]
49754974
/// #![warn(unsafe_attr_outside_unsafe)]
49764975
///
49774976
/// #[no_mangle]

‎compiler/rustc_parse/src/parser/attr.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_ast::token::{self, Delimiter};
44
use rustc_errors::codes::*;
55
use rustc_errors::{Diag, PResult};
66
use rustc_span::symbol::kw;
7-
use rustc_span::{sym, BytePos, Span};
7+
use rustc_span::{BytePos, Span};
88
use thin_vec::ThinVec;
99
use tracing::debug;
1010

@@ -265,7 +265,6 @@ impl<'a> Parser<'a> {
265265
let is_unsafe = this.eat_keyword(kw::Unsafe);
266266
let unsafety = if is_unsafe {
267267
let unsafe_span = this.prev_token.span;
268-
this.psess.gated_spans.gate(sym::unsafe_attributes, unsafe_span);
269268
this.expect(&token::OpenDelim(Delimiter::Parenthesis))?;
270269
ast::Safety::Unsafe(unsafe_span)
271270
} else {
@@ -406,7 +405,6 @@ impl<'a> Parser<'a> {
406405
};
407406
let unsafety = if is_unsafe {
408407
let unsafe_span = self.prev_token.span;
409-
self.psess.gated_spans.gate(sym::unsafe_attributes, unsafe_span);
410408
self.expect(&token::OpenDelim(Delimiter::Parenthesis))?;
411409

412410
ast::Safety::Unsafe(unsafe_span)

‎compiler/rustc_parse/src/validate_attr.rs

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ use rustc_ast::{
77
NestedMetaItem, Safety,
88
};
99
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};
1311
use rustc_session::errors::report_lit_error;
1412
use rustc_session::lint::builtin::{ILL_FORMED_ATTRIBUTE_INPUT, UNSAFE_ATTR_OUTSIDE_UNSAFE};
1513
use rustc_session::lint::BuiltinLintDiag;
@@ -18,7 +16,7 @@ use rustc_span::{sym, BytePos, Span, Symbol};
1816

1917
use crate::{errors, parse_in};
2018

21-
pub fn check_attr(features: &Features, psess: &ParseSess, attr: &Attribute) {
19+
pub fn check_attr(psess: &ParseSess, attr: &Attribute) {
2220
if attr.is_doc_comment() {
2321
return;
2422
}
@@ -28,17 +26,17 @@ pub fn check_attr(features: &Features, psess: &ParseSess, attr: &Attribute) {
2826

2927
// All non-builtin attributes are considered safe
3028
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);
3230

3331
// Check input tokens for built-in and key-value attributes.
3432
match attr_info {
3533
// `rustc_dummy` doesn't have any restrictions specific to built-in attributes.
3634
Some(BuiltinAttribute { name, template, .. }) if *name != sym::rustc_dummy => {
3735
match parse_meta(psess, attr) {
3836
// 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+
}
4240
Err(err) => {
4341
err.emit();
4442
}
@@ -157,16 +155,7 @@ fn is_attr_template_compatible(template: &AttributeTemplate, meta: &ast::MetaIte
157155
}
158156
}
159157

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) {
170159
let attr_item = attr.get_normal_item();
171160

172161
if safety == AttributeSafety::Unsafe {
@@ -215,21 +204,18 @@ pub fn check_attribute_safety(
215204

216205
// Called by `check_builtin_meta_item` and code that manually denies
217206
// `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) {
219208
// This only supports denying unsafety right now - making builtin attributes
220209
// support unsafety will requite us to thread the actual `Attribute` through
221210
// 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() });
228215
}
229216
}
230217

231218
pub fn check_builtin_meta_item(
232-
features: &Features,
233219
psess: &ParseSess,
234220
meta: &MetaItem,
235221
style: ast::AttrStyle,
@@ -246,7 +232,7 @@ pub fn check_builtin_meta_item(
246232
}
247233

248234
if deny_unsafety {
249-
deny_builtin_meta_unsafety(features, psess, meta);
235+
deny_builtin_meta_unsafety(psess, meta);
250236
}
251237
}
252238

‎src/tools/rustfmt/tests/target/unsafe_attributes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
#![feature(unsafe_attributes)]
21
// https://github.com/rust-lang/rust/issues/123757
32
//
43
#![simple_ident]

‎tests/ui/attributes/unsafe/cfg-unsafe-attributes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ build-pass
2-
#![feature(unsafe_attributes)]
32

43
#[cfg_attr(all(), unsafe(no_mangle))]
54
fn a() {}

‎tests/ui/attributes/unsafe/derive-unsafe-attributes.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(unsafe_attributes)]
2-
31
#[derive(unsafe(Debug))]
42
//~^ ERROR: expected identifier, found keyword `unsafe`
53
//~| ERROR: traits in `#[derive(...)]` don't accept arguments

‎tests/ui/attributes/unsafe/derive-unsafe-attributes.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected identifier, found keyword `unsafe`
2-
--> $DIR/derive-unsafe-attributes.rs:3:10
2+
--> $DIR/derive-unsafe-attributes.rs:1:10
33
|
44
LL | #[derive(unsafe(Debug))]
55
| ^^^^^^ expected identifier, found keyword
@@ -10,21 +10,21 @@ LL | #[derive(r#unsafe(Debug))]
1010
| ++
1111

1212
error: traits in `#[derive(...)]` don't accept arguments
13-
--> $DIR/derive-unsafe-attributes.rs:3:16
13+
--> $DIR/derive-unsafe-attributes.rs:1:16
1414
|
1515
LL | #[derive(unsafe(Debug))]
1616
| ^^^^^^^ help: remove the arguments
1717

1818
error: `derive` is not an unsafe attribute
19-
--> $DIR/derive-unsafe-attributes.rs:12:3
19+
--> $DIR/derive-unsafe-attributes.rs:10:3
2020
|
2121
LL | #[unsafe(derive(Debug))]
2222
| ^^^^^^ this is not an unsafe attribute
2323
|
2424
= note: extraneous unsafe is not allowed in attributes
2525

2626
error: expected identifier, found keyword `unsafe`
27-
--> $DIR/derive-unsafe-attributes.rs:3:10
27+
--> $DIR/derive-unsafe-attributes.rs:1:10
2828
|
2929
LL | #[derive(unsafe(Debug))]
3030
| ^^^^^^ expected identifier, found keyword
@@ -36,7 +36,7 @@ LL | #[derive(r#unsafe(Debug))]
3636
| ++
3737

3838
error: expected identifier, found keyword `unsafe`
39-
--> $DIR/derive-unsafe-attributes.rs:3:10
39+
--> $DIR/derive-unsafe-attributes.rs:1:10
4040
|
4141
LL | #[derive(unsafe(Debug))]
4242
| ^^^^^^ expected identifier, found keyword
@@ -48,13 +48,13 @@ LL | #[derive(r#unsafe(Debug))]
4848
| ++
4949

5050
error: cannot find derive macro `r#unsafe` in this scope
51-
--> $DIR/derive-unsafe-attributes.rs:3:10
51+
--> $DIR/derive-unsafe-attributes.rs:1:10
5252
|
5353
LL | #[derive(unsafe(Debug))]
5454
| ^^^^^^
5555

5656
error: cannot find derive macro `r#unsafe` in this scope
57-
--> $DIR/derive-unsafe-attributes.rs:3:10
57+
--> $DIR/derive-unsafe-attributes.rs:1:10
5858
|
5959
LL | #[derive(unsafe(Debug))]
6060
| ^^^^^^

‎tests/ui/attributes/unsafe/double-unsafe-attributes.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(unsafe_attributes)]
2-
31
#[unsafe(unsafe(no_mangle))]
42
//~^ ERROR expected identifier, found keyword `unsafe`
53
//~| ERROR cannot find attribute `r#unsafe` in this scope

‎tests/ui/attributes/unsafe/double-unsafe-attributes.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected identifier, found keyword `unsafe`
2-
--> $DIR/double-unsafe-attributes.rs:3:10
2+
--> $DIR/double-unsafe-attributes.rs:1:10
33
|
44
LL | #[unsafe(unsafe(no_mangle))]
55
| ^^^^^^ expected identifier, found keyword
@@ -10,15 +10,15 @@ LL | #[unsafe(r#unsafe(no_mangle))]
1010
| ++
1111

1212
error: `r#unsafe` is not an unsafe attribute
13-
--> $DIR/double-unsafe-attributes.rs:3:3
13+
--> $DIR/double-unsafe-attributes.rs:1:3
1414
|
1515
LL | #[unsafe(unsafe(no_mangle))]
1616
| ^^^^^^ this is not an unsafe attribute
1717
|
1818
= note: extraneous unsafe is not allowed in attributes
1919

2020
error: cannot find attribute `r#unsafe` in this scope
21-
--> $DIR/double-unsafe-attributes.rs:3:10
21+
--> $DIR/double-unsafe-attributes.rs:1:10
2222
|
2323
LL | #[unsafe(unsafe(no_mangle))]
2424
| ^^^^^^

‎tests/ui/attributes/unsafe/extraneous-unsafe-attributes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ edition: 2024
22
//@ compile-flags: -Zunstable-options
3-
#![feature(unsafe_attributes)]
43

54
#[unsafe(cfg(any()))] //~ ERROR: is not an unsafe attribute
65
fn a() {}

‎tests/ui/attributes/unsafe/extraneous-unsafe-attributes.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,61 @@
11
error: `cfg` is not an unsafe attribute
2-
--> $DIR/extraneous-unsafe-attributes.rs:5:3
2+
--> $DIR/extraneous-unsafe-attributes.rs:4:3
33
|
44
LL | #[unsafe(cfg(any()))]
55
| ^^^^^^ this is not an unsafe attribute
66
|
77
= note: extraneous unsafe is not allowed in attributes
88

99
error: `cfg_attr` is not an unsafe attribute
10-
--> $DIR/extraneous-unsafe-attributes.rs:8:3
10+
--> $DIR/extraneous-unsafe-attributes.rs:7:3
1111
|
1212
LL | #[unsafe(cfg_attr(any(), allow(dead_code)))]
1313
| ^^^^^^ this is not an unsafe attribute
1414
|
1515
= note: extraneous unsafe is not allowed in attributes
1616

1717
error: `test` is not an unsafe attribute
18-
--> $DIR/extraneous-unsafe-attributes.rs:11:3
18+
--> $DIR/extraneous-unsafe-attributes.rs:10:3
1919
|
2020
LL | #[unsafe(test)]
2121
| ^^^^^^ this is not an unsafe attribute
2222
|
2323
= note: extraneous unsafe is not allowed in attributes
2424

2525
error: `ignore` is not an unsafe attribute
26-
--> $DIR/extraneous-unsafe-attributes.rs:14:3
26+
--> $DIR/extraneous-unsafe-attributes.rs:13:3
2727
|
2828
LL | #[unsafe(ignore = "test")]
2929
| ^^^^^^ this is not an unsafe attribute
3030
|
3131
= note: extraneous unsafe is not allowed in attributes
3232

3333
error: `should_panic` is not an unsafe attribute
34-
--> $DIR/extraneous-unsafe-attributes.rs:17:3
34+
--> $DIR/extraneous-unsafe-attributes.rs:16:3
3535
|
3636
LL | #[unsafe(should_panic(expected = "test"))]
3737
| ^^^^^^ this is not an unsafe attribute
3838
|
3939
= note: extraneous unsafe is not allowed in attributes
4040

4141
error: `macro_use` is not an unsafe attribute
42-
--> $DIR/extraneous-unsafe-attributes.rs:20:3
42+
--> $DIR/extraneous-unsafe-attributes.rs:19:3
4343
|
4444
LL | #[unsafe(macro_use)]
4545
| ^^^^^^ this is not an unsafe attribute
4646
|
4747
= note: extraneous unsafe is not allowed in attributes
4848

4949
error: `macro_export` is not an unsafe attribute
50-
--> $DIR/extraneous-unsafe-attributes.rs:22:7
50+
--> $DIR/extraneous-unsafe-attributes.rs:21:7
5151
|
5252
LL | #[unsafe(macro_export)]
5353
| ^^^^^^ this is not an unsafe attribute
5454
|
5555
= note: extraneous unsafe is not allowed in attributes
5656

5757
error: `used` is not an unsafe attribute
58-
--> $DIR/extraneous-unsafe-attributes.rs:28:3
58+
--> $DIR/extraneous-unsafe-attributes.rs:27:3
5959
|
6060
LL | #[unsafe(used)]
6161
| ^^^^^^ this is not an unsafe attribute

‎tests/ui/attributes/unsafe/proc-unsafe-attributes.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(unsafe_attributes)]
2-
31
#[unsafe(proc_macro)]
42
//~^ ERROR: is not an unsafe attribute
53
//~| ERROR attribute is only usable with crates of the `proc-macro` crate type

‎tests/ui/attributes/unsafe/proc-unsafe-attributes.stderr

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
error[E0452]: malformed lint attribute input
2-
--> $DIR/proc-unsafe-attributes.rs:28:16
2+
--> $DIR/proc-unsafe-attributes.rs:26:16
33
|
44
LL | #[unsafe(allow(unsafe(dead_code)))]
55
| ^^^^^^^^^^^^^^^^^ bad attribute argument
66

77
error[E0452]: malformed lint attribute input
8-
--> $DIR/proc-unsafe-attributes.rs:28:16
8+
--> $DIR/proc-unsafe-attributes.rs:26:16
99
|
1010
LL | #[unsafe(allow(unsafe(dead_code)))]
1111
| ^^^^^^^^^^^^^^^^^ bad attribute argument
1212
|
1313
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1414

1515
error: `proc_macro` is not an unsafe attribute
16-
--> $DIR/proc-unsafe-attributes.rs:3:3
16+
--> $DIR/proc-unsafe-attributes.rs:1:3
1717
|
1818
LL | #[unsafe(proc_macro)]
1919
| ^^^^^^ this is not an unsafe attribute
2020
|
2121
= note: extraneous unsafe is not allowed in attributes
2222

2323
error: `proc_macro_derive` is not an unsafe attribute
24-
--> $DIR/proc-unsafe-attributes.rs:9:3
24+
--> $DIR/proc-unsafe-attributes.rs:7:3
2525
|
2626
LL | #[unsafe(proc_macro_derive(Foo))]
2727
| ^^^^^^ this is not an unsafe attribute
2828
|
2929
= note: extraneous unsafe is not allowed in attributes
3030

3131
error: expected identifier, found keyword `unsafe`
32-
--> $DIR/proc-unsafe-attributes.rs:14:21
32+
--> $DIR/proc-unsafe-attributes.rs:12:21
3333
|
3434
LL | #[proc_macro_derive(unsafe(Foo))]
3535
| ^^^^^^ expected identifier, found keyword
@@ -40,31 +40,31 @@ LL | #[proc_macro_derive(r#unsafe(Foo))]
4040
| ++
4141

4242
error: `proc_macro_attribute` is not an unsafe attribute
43-
--> $DIR/proc-unsafe-attributes.rs:19:3
43+
--> $DIR/proc-unsafe-attributes.rs:17:3
4444
|
4545
LL | #[unsafe(proc_macro_attribute)]
4646
| ^^^^^^ this is not an unsafe attribute
4747
|
4848
= note: extraneous unsafe is not allowed in attributes
4949

5050
error: `allow` is not an unsafe attribute
51-
--> $DIR/proc-unsafe-attributes.rs:24:3
51+
--> $DIR/proc-unsafe-attributes.rs:22:3
5252
|
5353
LL | #[unsafe(allow(dead_code))]
5454
| ^^^^^^ this is not an unsafe attribute
5555
|
5656
= note: extraneous unsafe is not allowed in attributes
5757

5858
error: `allow` is not an unsafe attribute
59-
--> $DIR/proc-unsafe-attributes.rs:28:3
59+
--> $DIR/proc-unsafe-attributes.rs:26:3
6060
|
6161
LL | #[unsafe(allow(unsafe(dead_code)))]
6262
| ^^^^^^ this is not an unsafe attribute
6363
|
6464
= note: extraneous unsafe is not allowed in attributes
6565

6666
error: expected identifier, found keyword `unsafe`
67-
--> $DIR/proc-unsafe-attributes.rs:28:16
67+
--> $DIR/proc-unsafe-attributes.rs:26:16
6868
|
6969
LL | #[unsafe(allow(unsafe(dead_code)))]
7070
| ^^^^^^ expected identifier, found keyword
@@ -75,39 +75,39 @@ LL | #[unsafe(allow(r#unsafe(dead_code)))]
7575
| ++
7676

7777
error: the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type
78-
--> $DIR/proc-unsafe-attributes.rs:3:1
78+
--> $DIR/proc-unsafe-attributes.rs:1:1
7979
|
8080
LL | #[unsafe(proc_macro)]
8181
| ^^^^^^^^^^^^^^^^^^^^^
8282

8383
error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type
84-
--> $DIR/proc-unsafe-attributes.rs:9:1
84+
--> $DIR/proc-unsafe-attributes.rs:7:1
8585
|
8686
LL | #[unsafe(proc_macro_derive(Foo))]
8787
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8888

8989
error: the `#[proc_macro_derive]` attribute is only usable with crates of the `proc-macro` crate type
90-
--> $DIR/proc-unsafe-attributes.rs:14:1
90+
--> $DIR/proc-unsafe-attributes.rs:12:1
9191
|
9292
LL | #[proc_macro_derive(unsafe(Foo))]
9393
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9494

9595
error: the `#[proc_macro_attribute]` attribute is only usable with crates of the `proc-macro` crate type
96-
--> $DIR/proc-unsafe-attributes.rs:19:1
96+
--> $DIR/proc-unsafe-attributes.rs:17:1
9797
|
9898
LL | #[unsafe(proc_macro_attribute)]
9999
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
100100

101101
error[E0452]: malformed lint attribute input
102-
--> $DIR/proc-unsafe-attributes.rs:28:16
102+
--> $DIR/proc-unsafe-attributes.rs:26:16
103103
|
104104
LL | #[unsafe(allow(unsafe(dead_code)))]
105105
| ^^^^^^^^^^^^^^^^^ bad attribute argument
106106
|
107107
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
108108

109109
error[E0452]: malformed lint attribute input
110-
--> $DIR/proc-unsafe-attributes.rs:28:16
110+
--> $DIR/proc-unsafe-attributes.rs:26:16
111111
|
112112
LL | #[unsafe(allow(unsafe(dead_code)))]
113113
| ^^^^^^^^^^^^^^^^^ bad attribute argument

‎tests/ui/attributes/unsafe/unsafe-attributes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ build-pass
2-
#![feature(unsafe_attributes)]
32

43
#[unsafe(no_mangle)]
54
fn a() {}

‎tests/ui/attributes/unsafe/unsafe-safe-attribute.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(unsafe_attributes)]
2-
31
#[unsafe(repr(C))] //~ ERROR: is not an unsafe attribute
42
struct Foo {}
53

‎tests/ui/attributes/unsafe/unsafe-safe-attribute.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `repr` is not an unsafe attribute
2-
--> $DIR/unsafe-safe-attribute.rs:3:3
2+
--> $DIR/unsafe-safe-attribute.rs:1:3
33
|
44
LL | #[unsafe(repr(C))]
55
| ^^^^^^ this is not an unsafe attribute

‎tests/ui/attributes/unsafe/unsafe-safe-attribute_diagnostic.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(unsafe_attributes)]
2-
31
#[unsafe(diagnostic::on_unimplemented( //~ ERROR: is not an unsafe attribute
42
message = "testing",
53
))]

‎tests/ui/attributes/unsafe/unsafe-safe-attribute_diagnostic.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: `diagnostic::on_unimplemented` is not an unsafe attribute
2-
--> $DIR/unsafe-safe-attribute_diagnostic.rs:3:3
2+
--> $DIR/unsafe-safe-attribute_diagnostic.rs:1:3
33
|
44
LL | #[unsafe(diagnostic::on_unimplemented(
55
| ^^^^^^ this is not an unsafe attribute

‎tests/ui/feature-gates/feature-gate-unsafe-attributes.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

‎tests/ui/feature-gates/feature-gate-unsafe-attributes.stderr

Lines changed: 0 additions & 13 deletions
This file was deleted.

‎tests/ui/rust-2024/unsafe-attributes/in_2024_compatibility.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#![deny(rust_2024_compatibility)]
2-
#![feature(unsafe_attributes)]
32

43
#[no_mangle]
54
//~^ ERROR: unsafe attribute used without unsafe

‎tests/ui/rust-2024/unsafe-attributes/in_2024_compatibility.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unsafe attribute used without unsafe
2-
--> $DIR/in_2024_compatibility.rs:4:3
2+
--> $DIR/in_2024_compatibility.rs:3:3
33
|
44
LL | #[no_mangle]
55
| ^^^^^^^^^ usage of unsafe attribute

‎tests/ui/rust-2024/unsafe-attributes/unsafe-attribute-marked.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//@[edition2024] compile-flags: -Zunstable-options
55
//@ check-pass
66

7-
#![feature(unsafe_attributes)]
87

98
#[unsafe(no_mangle)]
109
extern "C" fn foo() {}

‎tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.fixed

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ run-rustfix
2-
#![feature(unsafe_attributes)]
32
#![deny(unsafe_attr_outside_unsafe)]
43

54
macro_rules! tt {

‎tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ run-rustfix
2-
#![feature(unsafe_attributes)]
32
#![deny(unsafe_attr_outside_unsafe)]
43

54
macro_rules! tt {

‎tests/ui/rust-2024/unsafe-attributes/unsafe-attributes-fix.stderr

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error: unsafe attribute used without unsafe
2-
--> $DIR/unsafe-attributes-fix.rs:44:6
2+
--> $DIR/unsafe-attributes-fix.rs:43:6
33
|
44
LL | tt!([no_mangle]);
55
| ^^^^^^^^^ usage of unsafe attribute
66
|
77
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2024!
88
= note: for more information, see issue #123757 <https://github.com/rust-lang/rust/issues/123757>
99
note: the lint level is defined here
10-
--> $DIR/unsafe-attributes-fix.rs:3:9
10+
--> $DIR/unsafe-attributes-fix.rs:2:9
1111
|
1212
LL | #![deny(unsafe_attr_outside_unsafe)]
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -17,7 +17,7 @@ LL | tt!([unsafe(no_mangle)]);
1717
| +++++++ +
1818

1919
error: unsafe attribute used without unsafe
20-
--> $DIR/unsafe-attributes-fix.rs:14:11
20+
--> $DIR/unsafe-attributes-fix.rs:13:11
2121
|
2222
LL | #[$e]
2323
| ^^ usage of unsafe attribute
@@ -34,7 +34,7 @@ LL | #[unsafe($e)]
3434
| +++++++ +
3535

3636
error: unsafe attribute used without unsafe
37-
--> $DIR/unsafe-attributes-fix.rs:48:7
37+
--> $DIR/unsafe-attributes-fix.rs:47:7
3838
|
3939
LL | meta!(no_mangle);
4040
| ^^^^^^^^^ usage of unsafe attribute
@@ -47,7 +47,7 @@ LL | meta!(unsafe(no_mangle));
4747
| +++++++ +
4848

4949
error: unsafe attribute used without unsafe
50-
--> $DIR/unsafe-attributes-fix.rs:51:8
50+
--> $DIR/unsafe-attributes-fix.rs:50:8
5151
|
5252
LL | meta2!(export_name = "baw");
5353
| ^^^^^^^^^^^ usage of unsafe attribute
@@ -60,7 +60,7 @@ LL | meta2!(unsafe(export_name = "baw"));
6060
| +++++++ +
6161

6262
error: unsafe attribute used without unsafe
63-
--> $DIR/unsafe-attributes-fix.rs:23:11
63+
--> $DIR/unsafe-attributes-fix.rs:22:11
6464
|
6565
LL | #[$e = $l]
6666
| ^^ usage of unsafe attribute
@@ -77,7 +77,7 @@ LL | #[unsafe($e = $l)]
7777
| +++++++ +
7878

7979
error: unsafe attribute used without unsafe
80-
--> $DIR/unsafe-attributes-fix.rs:56:3
80+
--> $DIR/unsafe-attributes-fix.rs:55:3
8181
|
8282
LL | #[no_mangle]
8383
| ^^^^^^^^^ usage of unsafe attribute

‎tests/ui/rust-2024/unsafe-attributes/unsafe-attributes.edition2024.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: unsafe attribute used without unsafe
2-
--> $DIR/unsafe-attributes.rs:9:3
2+
--> $DIR/unsafe-attributes.rs:8:3
33
|
44
LL | #[no_mangle]
55
| ^^^^^^^^^ usage of unsafe attribute

‎tests/ui/rust-2024/unsafe-attributes/unsafe-attributes.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
//@[edition2024] edition:2024
55
//@[edition2024] compile-flags: -Zunstable-options
66

7-
#![feature(unsafe_attributes)]
87

98
#[no_mangle] //[edition2024]~ ERROR: unsafe attribute used without unsafe
109
extern "C" fn foo() {}

0 commit comments

Comments
 (0)
Please sign in to comment.