|
1 | 1 | use rustc_ast::token::{Delimiter, TokenKind}; |
2 | 2 | use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing, TokenStream, TokenTree}; |
3 | 3 | use rustc_ast::{ |
4 | | - Attribute, DUMMY_NODE_ID, EiiDecl, EiiImpl, ItemKind, MetaItem, Mutability, Path, StmtKind, |
5 | | - Visibility, ast, |
| 4 | + AttrKind, Attribute, DUMMY_NODE_ID, EiiDecl, EiiImpl, ItemKind, MetaItem, Mutability, Path, |
| 5 | + StmtKind, SyntheticAttr, Visibility, ast, |
6 | 6 | }; |
7 | 7 | use rustc_ast_pretty::pprust::path_to_string; |
8 | 8 | use rustc_expand::base::{Annotatable, ExtCtxt}; |
@@ -200,37 +200,47 @@ fn split_attrs( |
200 | 200 | let mut foreign_item_attributes = ThinVec::new(); |
201 | 201 |
|
202 | 202 | for attr in attrs { |
203 | | - match attr.name() { |
204 | | - // If an eii is marked a lang item, that's because we want to call its declaration, so |
205 | | - // mark the foreign item as the lang item |
206 | | - Some(sym::lang) => foreign_item_attributes.push(attr), |
207 | | - // Deprecating an eii means deprecating the macro and the foreign item |
208 | | - Some(sym::deprecated) => { |
| 203 | + match &attr.kind { |
| 204 | + // Forward synthetic CfgTrace and CfgAttrTrace, these are applicable to both foreign item and macro. |
| 205 | + AttrKind::Synthetic(SyntheticAttr::CfgTrace(_) | SyntheticAttr::CfgAttrTrace(_)) => { |
209 | 206 | foreign_item_attributes.push(attr.clone()); |
210 | 207 | macro_attributes.push(attr); |
211 | 208 | } |
212 | | - // The stability of an EII affects the usage of the macro and calling the foreign item |
213 | | - Some(sym::stable) | Some(sym::unstable) => { |
214 | | - foreign_item_attributes.push(attr.clone()); |
215 | | - macro_attributes.push(attr); |
216 | | - } |
217 | | - // `#[track_caller]` goes on the foreign item only: it's the symbol callers link |
218 | | - // against, so it must carry the flag for call sites to pass the caller location. |
219 | | - // Implementations derive it during codegen (see `EiiImpls` in `codegen_attrs.rs`), |
220 | | - // so it must not be routed onto the default impl here. |
221 | | - Some(sym::track_caller) => { |
222 | | - foreign_item_attributes.push(attr); |
223 | | - } |
224 | 209 | // Doc attributes should be forwarded to the macro and the foreign item, since those are |
225 | 210 | // the two items you interact with as a user. |
226 | 211 | // FIXME: idk yet how EIIs show up in docs, might want to customize |
227 | | - _ if attr.is_doc_comment() => { |
| 212 | + AttrKind::DocComment(_, _) => { |
228 | 213 | foreign_item_attributes.push(attr.clone()); |
229 | 214 | macro_attributes.push(attr); |
230 | 215 | } |
231 | | - Some(sym::eii) => unreachable!("should already be filtered out"), |
232 | | - _ => { |
233 | | - ecx.dcx().emit_err(EiiAttributeNotSupported { span, attr_span: attr.span() }); |
| 216 | + AttrKind::Normal(normal) => { |
| 217 | + match normal.item.name() { |
| 218 | + // If an eii is marked a lang item, that's because we want to call its declaration, so |
| 219 | + // mark the foreign item as the lang item |
| 220 | + Some(sym::lang) => foreign_item_attributes.push(attr), |
| 221 | + // Deprecating an eii means deprecating the macro and the foreign item |
| 222 | + Some(sym::deprecated) => { |
| 223 | + foreign_item_attributes.push(attr.clone()); |
| 224 | + macro_attributes.push(attr); |
| 225 | + } |
| 226 | + // The stability of an EII affects the usage of the macro and calling the foreign item |
| 227 | + Some(sym::stable) | Some(sym::unstable) => { |
| 228 | + foreign_item_attributes.push(attr.clone()); |
| 229 | + macro_attributes.push(attr); |
| 230 | + } |
| 231 | + // `#[track_caller]` goes on the foreign item only: it's the symbol callers link |
| 232 | + // against, so it must carry the flag for call sites to pass the caller location. |
| 233 | + // Implementations derive it during codegen (see `EiiImpls` in `codegen_attrs.rs`), |
| 234 | + // so it must not be routed onto the default impl here. |
| 235 | + Some(sym::track_caller) => { |
| 236 | + foreign_item_attributes.push(attr); |
| 237 | + } |
| 238 | + Some(sym::eii) => unreachable!("should already be filtered out"), |
| 239 | + _ => { |
| 240 | + ecx.dcx() |
| 241 | + .emit_err(EiiAttributeNotSupported { span, attr_span: attr.span() }); |
| 242 | + } |
| 243 | + } |
234 | 244 | } |
235 | 245 | } |
236 | 246 | } |
|
0 commit comments