Skip to content

Commit 4c7749e

Browse files
committed
Auto merge of #145086 - jdonszelmann:revert-allow-internal-unsafe, r=Kobzol
Revert "Port `#[allow_internal_unsafe]` to the new attribute system" This reverts commit 4f7a6ac (PR: #144857) r? `@Kobzol` cc: `@scrabsha` clean revert it seems :3
2 parents ffb9d94 + 866bc26 commit 4c7749e

File tree

10 files changed

+23
-82
lines changed

10 files changed

+23
-82
lines changed

compiler/rustc_attr_parsing/src/attributes/macro_attrs.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,3 @@ impl<S: Stage> AttributeParser<S> for MacroUseParser {
113113
Some(AttributeKind::MacroUse { span: self.first_span?, arguments: self.state })
114114
}
115115
}
116-
117-
pub(crate) struct AllowInternalUnsafeParser;
118-
119-
impl<S: Stage> NoArgsAttributeParser<S> for AllowInternalUnsafeParser {
120-
const PATH: &[Symbol] = &[sym::allow_internal_unsafe];
121-
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Ignore;
122-
const CREATE: fn(Span) -> AttributeKind = |span| AttributeKind::AllowInternalUnsafe(span);
123-
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ use crate::attributes::lint_helpers::{
3333
AsPtrParser, AutomaticallyDerivedParser, PassByValueParser, PubTransparentParser,
3434
};
3535
use crate::attributes::loop_match::{ConstContinueParser, LoopMatchParser};
36-
use crate::attributes::macro_attrs::{
37-
AllowInternalUnsafeParser, MacroEscapeParser, MacroUseParser,
38-
};
36+
use crate::attributes::macro_attrs::{MacroEscapeParser, MacroUseParser};
3937
use crate::attributes::must_use::MustUseParser;
4038
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
4139
use crate::attributes::non_exhaustive::NonExhaustiveParser;
@@ -180,7 +178,6 @@ attribute_parsers!(
180178
Single<SkipDuringMethodDispatchParser>,
181179
Single<TransparencyParser>,
182180
Single<WithoutArgs<AllowIncoherentImplParser>>,
183-
Single<WithoutArgs<AllowInternalUnsafeParser>>,
184181
Single<WithoutArgs<AsPtrParser>>,
185182
Single<WithoutArgs<AutomaticallyDerivedParser>>,
186183
Single<WithoutArgs<CoherenceIsCoreParser>>,

compiler/rustc_expand/src/base.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,10 @@ impl SyntaxExtension {
905905
find_attr!(attrs, AttributeKind::AllowInternalUnstable(i, _) => i)
906906
.map(|i| i.as_slice())
907907
.unwrap_or_default();
908-
let allow_internal_unsafe = find_attr!(attrs, AttributeKind::AllowInternalUnsafe(_));
908+
// FIXME(jdonszelman): allow_internal_unsafe isn't yet new-style
909+
// let allow_internal_unsafe = find_attr!(attrs, AttributeKind::AllowInternalUnsafe);
910+
let allow_internal_unsafe =
911+
ast::attr::find_by_name(attrs, sym::allow_internal_unsafe).is_some();
909912

910913
let local_inner_macros = ast::attr::find_by_name(attrs, sym::macro_export)
911914
.and_then(|macro_export| macro_export.meta_item_list())

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,6 @@ pub enum AttributeKind {
249249
/// Represents `#[rustc_allow_incoherent_impl]`.
250250
AllowIncoherentImpl(Span),
251251

252-
/// Represents `#[allow_internal_unsafe]`.
253-
AllowInternalUnsafe(Span),
254-
255252
/// Represents `#[allow_internal_unstable]`.
256253
AllowInternalUnstable(ThinVec<(Symbol, Span)>, Span),
257254

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ impl AttributeKind {
1616
Align { .. } => No,
1717
AllowConstFnUnstable(..) => No,
1818
AllowIncoherentImpl(..) => No,
19-
AllowInternalUnsafe(..) => Yes,
2019
AllowInternalUnstable(..) => Yes,
2120
AsPtr(..) => Yes,
2221
AutomaticallyDerived(..) => Yes,

compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414
//! [`crate::late_lint_methods!`] invocation in `lib.rs`.
1515
1616
use std::fmt::Write;
17-
use std::slice;
1817

1918
use ast::token::TokenKind;
2019
use rustc_abi::BackendRepr;
2120
use rustc_ast::tokenstream::{TokenStream, TokenTree};
2221
use rustc_ast::visit::{FnCtxt, FnKind};
2322
use rustc_ast::{self as ast, *};
2423
use rustc_ast_pretty::pprust::expr_to_string;
25-
use rustc_attr_parsing::AttributeParser;
2624
use rustc_errors::{Applicability, LintDiagnostic};
2725
use rustc_feature::GateIssue;
2826
use rustc_hir as hir;
@@ -251,16 +249,7 @@ impl UnsafeCode {
251249

252250
impl EarlyLintPass for UnsafeCode {
253251
fn check_attribute(&mut self, cx: &EarlyContext<'_>, attr: &ast::Attribute) {
254-
if AttributeParser::parse_limited(
255-
cx.builder.sess(),
256-
slice::from_ref(attr),
257-
sym::allow_internal_unsafe,
258-
attr.span,
259-
DUMMY_NODE_ID,
260-
Some(cx.builder.features()),
261-
)
262-
.is_some()
263-
{
252+
if attr.has_name(sym::allow_internal_unsafe) {
264253
self.report_unsafe(cx, attr.span, BuiltinUnsafe::AllowInternalUnsafe);
265254
}
266255
}

compiler/rustc_passes/messages.ftl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ passes_allow_incoherent_impl =
2929
`rustc_allow_incoherent_impl` attribute should be applied to impl items
3030
.label = the only currently supported targets are inherent methods
3131
32-
passes_macro_only_attribute =
32+
passes_allow_internal_unstable =
3333
attribute should be applied to a macro
3434
.label = not a macro
3535

compiler/rustc_passes/src/check_attr.rs

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
207207
Attribute::Parsed(AttributeKind::ConstContinue(attr_span)) => {
208208
self.check_const_continue(hir_id, *attr_span, target)
209209
}
210-
Attribute::Parsed(AttributeKind::AllowInternalUnsafe(attr_span)) => {
211-
self.check_allow_internal_unsafe(hir_id, *attr_span, span, target, attrs)
212-
}
213210
Attribute::Parsed(AttributeKind::AllowInternalUnstable(_, first_span)) => {
214211
self.check_allow_internal_unstable(hir_id, *first_span, span, target, attrs)
215212
}
@@ -416,6 +413,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
416413
// internal
417414
| sym::prelude_import
418415
| sym::panic_handler
416+
| sym::allow_internal_unsafe
419417
| sym::lang
420418
| sym::needs_allocator
421419
| sym::default_lib_allocator
@@ -2214,49 +2212,14 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22142212

22152213
/// Outputs an error for `#[allow_internal_unstable]` which can only be applied to macros.
22162214
/// (Allows proc_macro functions)
2217-
fn check_allow_internal_unstable(
2218-
&self,
2219-
hir_id: HirId,
2220-
attr_span: Span,
2221-
span: Span,
2222-
target: Target,
2223-
attrs: &[Attribute],
2224-
) {
2225-
self.check_macro_only_attr(
2226-
hir_id,
2227-
attr_span,
2228-
span,
2229-
target,
2230-
attrs,
2231-
"allow_internal_unstable",
2232-
)
2233-
}
2234-
2235-
/// Outputs an error for `#[allow_internal_unsafe]` which can only be applied to macros.
2236-
/// (Allows proc_macro functions)
2237-
fn check_allow_internal_unsafe(
2238-
&self,
2239-
hir_id: HirId,
2240-
attr_span: Span,
2241-
span: Span,
2242-
target: Target,
2243-
attrs: &[Attribute],
2244-
) {
2245-
self.check_macro_only_attr(hir_id, attr_span, span, target, attrs, "allow_internal_unsafe")
2246-
}
2247-
2248-
/// Outputs an error for attributes that can only be applied to macros, such as
2249-
/// `#[allow_internal_unsafe]` and `#[allow_internal_unstable]`.
2250-
/// (Allows proc_macro functions)
22512215
// FIXME(jdonszelmann): if possible, move to attr parsing
2252-
fn check_macro_only_attr(
2216+
fn check_allow_internal_unstable(
22532217
&self,
22542218
hir_id: HirId,
22552219
attr_span: Span,
22562220
span: Span,
22572221
target: Target,
22582222
attrs: &[Attribute],
2259-
attr_name: &str,
22602223
) {
22612224
match target {
22622225
Target::Fn => {
@@ -2275,14 +2238,18 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22752238
// erroneously allowed it and some crates used it accidentally, to be compatible
22762239
// with crates depending on them, we can't throw an error here.
22772240
Target::Field | Target::Arm => {
2278-
self.inline_attr_str_error_without_macro_def(hir_id, attr_span, attr_name);
2241+
self.inline_attr_str_error_without_macro_def(
2242+
hir_id,
2243+
attr_span,
2244+
"allow_internal_unstable",
2245+
);
22792246
return;
22802247
}
22812248
// otherwise continue out of the match
22822249
_ => {}
22832250
}
22842251

2285-
self.tcx.dcx().emit_err(errors::MacroOnlyAttribute { attr_span, span });
2252+
self.tcx.dcx().emit_err(errors::AllowInternalUnstable { attr_span, span });
22862253
}
22872254

22882255
/// Checks if the items on the `#[debugger_visualizer]` attribute are valid.

compiler/rustc_passes/src/errors.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,8 @@ pub(crate) struct UsedStatic {
643643
}
644644

645645
#[derive(Diagnostic)]
646-
#[diag(passes_macro_only_attribute)]
647-
pub(crate) struct MacroOnlyAttribute {
646+
#[diag(passes_allow_internal_unstable)]
647+
pub(crate) struct AllowInternalUnstable {
648648
#[primary_span]
649649
pub attr_span: Span,
650650
#[label]

tests/ui/attributes/malformed-attrs.stderr

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ LL - #[macro_export = 18]
145145
LL + #[macro_export]
146146
|
147147

148+
error: malformed `allow_internal_unsafe` attribute input
149+
--> $DIR/malformed-attrs.rs:213:1
150+
|
151+
LL | #[allow_internal_unsafe = 1]
152+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[allow_internal_unsafe]`
153+
148154
error: the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type
149155
--> $DIR/malformed-attrs.rs:96:1
150156
|
@@ -555,15 +561,6 @@ error: valid forms for the attribute are `#[macro_use(name1, name2, ...)]` and `
555561
LL | #[macro_use = 1]
556562
| ^^^^^^^^^^^^^^^^
557563

558-
error[E0565]: malformed `allow_internal_unsafe` attribute input
559-
--> $DIR/malformed-attrs.rs:213:1
560-
|
561-
LL | #[allow_internal_unsafe = 1]
562-
| ^^^^^^^^^^^^^^^^^^^^^^^^---^
563-
| | |
564-
| | didn't expect any arguments here
565-
| help: must be of the form: `#[allow_internal_unsafe]`
566-
567564
error[E0565]: malformed `type_const` attribute input
568565
--> $DIR/malformed-attrs.rs:140:5
569566
|

0 commit comments

Comments
 (0)