Skip to content

Commit 027a1de

Browse files
committed
[DO NOT MERGE] diff against previous #[allow_internal_unsafe] attempt
1 parent c6d132a commit 027a1de

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,6 +1310,7 @@ impl AttributeExt for Attribute {
13101310
Attribute::Parsed(AttributeKind::Ignore { span, .. }) => *span,
13111311
Attribute::Parsed(AttributeKind::ShouldPanic { span, .. }) => *span,
13121312
Attribute::Parsed(AttributeKind::AutomaticallyDerived(span)) => *span,
1313+
Attribute::Parsed(AttributeKind::AllowInternalUnsafe(span)) => *span,
13131314
a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"),
13141315
}
13151316
}

compiler/rustc_lint/src/builtin.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
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;
@@ -250,21 +249,6 @@ impl UnsafeCode {
250249
}
251250

252251
impl EarlyLintPass for UnsafeCode {
253-
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-
{
264-
self.report_unsafe(cx, attr.span, BuiltinUnsafe::AllowInternalUnsafe);
265-
}
266-
}
267-
268252
#[inline]
269253
fn check_expr(&mut self, cx: &EarlyContext<'_>, e: &ast::Expr) {
270254
if let ast::ExprKind::Block(ref blk, _) = e.kind {
@@ -323,6 +307,19 @@ impl EarlyLintPass for UnsafeCode {
323307
}
324308
}
325309

310+
ast::ItemKind::MacroDef(..) => {
311+
if let Some(attr) = AttributeParser::parse_limited(
312+
cx.builder.sess(),
313+
&it.attrs,
314+
sym::allow_internal_unsafe,
315+
it.span,
316+
DUMMY_NODE_ID,
317+
Some(cx.builder.features()),
318+
) {
319+
self.report_unsafe(cx, attr.span(), BuiltinUnsafe::AllowInternalUnsafe);
320+
}
321+
}
322+
326323
_ => {}
327324
}
328325
}

0 commit comments

Comments
 (0)