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/base.rs | |
| parent | 30d57abccf7d55e9dd4e36be583c55f6b0090302 (diff) | |
| download | rust-6bff1abf9d3c171d2380aacb8b4c6f52580192b3.tar.gz rust-6bff1abf9d3c171d2380aacb8b4c6f52580192b3.zip | |
mbe: Support `unsafe` attribute rules
Diffstat (limited to 'compiler/rustc_expand/src/base.rs')
| -rw-r--r-- | compiler/rustc_expand/src/base.rs | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 33b712e3aed..810a5a21a05 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -10,7 +10,7 @@ use rustc_ast::attr::{AttributeExt, MarkedAttrs}; use rustc_ast::token::MetaVarKind; use rustc_ast::tokenstream::TokenStream; use rustc_ast::visit::{AssocCtxt, Visitor}; -use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind}; +use rustc_ast::{self as ast, AttrVec, Attribute, HasAttrs, Item, NodeId, PatKind, Safety}; use rustc_data_structures::fx::{FxHashMap, FxIndexMap}; use rustc_data_structures::sync; use rustc_errors::{BufferedEarlyLint, DiagCtxtHandle, ErrorGuaranteed, PResult}; @@ -345,6 +345,21 @@ pub trait AttrProcMacro { annotation: TokenStream, annotated: TokenStream, ) -> Result<TokenStream, ErrorGuaranteed>; + + // Default implementation for safe attributes; override if the attribute can be unsafe. + fn expand_with_safety<'cx>( + &self, + ecx: &'cx mut ExtCtxt<'_>, + safety: Safety, + span: Span, + annotation: TokenStream, + annotated: TokenStream, + ) -> Result<TokenStream, ErrorGuaranteed> { + if let Safety::Unsafe(span) = safety { + ecx.dcx().span_err(span, "unnecessary `unsafe` on safe attribute"); + } + self.expand(ecx, span, annotation, annotated) + } } impl<F> AttrProcMacro for F |
