diff options
| author | Josh Triplett <josh@joshtriplett.org> | 2025-09-14 16:17:51 +0800 |
|---|---|---|
| committer | Josh Triplett <josh@joshtriplett.org> | 2025-10-01 16:19:39 -0700 |
| commit | 6bff1abf9d3c171d2380aacb8b4c6f52580192b3 (patch) | |
| tree | a13db6b80e9dc6bc5614cea3033c99c9469884d3 /compiler/rustc_expand/src/expand.rs | |
| parent | 30d57abccf7d55e9dd4e36be583c55f6b0090302 (diff) | |
| download | rust-6bff1abf9d3c171d2380aacb8b4c6f52580192b3.tar.gz rust-6bff1abf9d3c171d2380aacb8b4c6f52580192b3.zip | |
mbe: Support `unsafe` attribute rules
Diffstat (limited to 'compiler/rustc_expand/src/expand.rs')
| -rw-r--r-- | compiler/rustc_expand/src/expand.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 172bc3d1d9f..a035896d554 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -812,11 +812,12 @@ impl<'a, 'b> MacroExpander<'a, 'b> { _ => item.to_tokens(), }; let attr_item = attr.get_normal_item(); + let safety = attr_item.unsafety; if let AttrArgs::Eq { .. } = attr_item.args { self.cx.dcx().emit_err(UnsupportedKeyValue { span }); } let inner_tokens = attr_item.args.inner_tokens(); - match expander.expand(self.cx, span, inner_tokens, tokens) { + match expander.expand_with_safety(self.cx, safety, span, inner_tokens, tokens) { Ok(tok_result) => { let fragment = self.parse_ast_fragment( tok_result, @@ -882,6 +883,9 @@ impl<'a, 'b> MacroExpander<'a, 'b> { } } } else if let SyntaxExtensionKind::NonMacroAttr = ext { + if let ast::Safety::Unsafe(span) = attr.get_normal_item().unsafety { + self.cx.dcx().span_err(span, "unnecessary `unsafe` on safe attribute"); + } // `-Zmacro-stats` ignores these because they don't do any real expansion. self.cx.expanded_inert_attrs.mark(&attr); item.visit_attrs(|attrs| attrs.insert(pos, attr)); |
