@@ -13,7 +13,7 @@ use crate::{
13
13
AstId , BuiltinAttrExpander , BuiltinDeriveExpander , BuiltinFnLikeExpander , EagerCallInfo ,
14
14
EagerExpander , EditionedFileId , ExpandError , ExpandResult , ExpandTo , HirFileId , MacroCallId ,
15
15
MacroCallKind , MacroCallLoc , MacroDefId , MacroDefKind ,
16
- attrs:: { AttrId , collect_attrs} ,
16
+ attrs:: { AttrId , AttrInput , RawAttrs , collect_attrs} ,
17
17
builtin:: pseudo_derive_attr_expansion,
18
18
cfg_process,
19
19
declarative:: DeclarativeMacroExpander ,
@@ -241,30 +241,36 @@ pub fn expand_speculative(
241
241
242
242
let attr_arg = match loc. kind {
243
243
MacroCallKind :: Attr { invoc_attr_index, .. } => {
244
- let attr = if loc. def . is_attribute_derive ( ) {
244
+ if loc. def . is_attribute_derive ( ) {
245
245
// for pseudo-derive expansion we actually pass the attribute itself only
246
- ast:: Attr :: cast ( speculative_args. clone ( ) )
246
+ ast:: Attr :: cast ( speculative_args. clone ( ) ) . and_then ( |attr| attr. token_tree ( ) ) . map (
247
+ |token_tree| {
248
+ let mut tree = syntax_node_to_token_tree (
249
+ token_tree. syntax ( ) ,
250
+ span_map,
251
+ span,
252
+ DocCommentDesugarMode :: ProcMacro ,
253
+ ) ;
254
+ * tree. top_subtree_delimiter_mut ( ) = tt:: Delimiter :: invisible_spanned ( span) ;
255
+ tree
256
+ } ,
257
+ )
247
258
} else {
248
259
// Attributes may have an input token tree, build the subtree and map for this as well
249
260
// then try finding a token id for our token if it is inside this input subtree.
250
261
let item = ast:: Item :: cast ( speculative_args. clone ( ) ) ?;
251
- collect_attrs ( & item)
252
- . nth ( invoc_attr_index. ast_index ( ) )
253
- . and_then ( |x| Either :: left ( x. 1 ) )
254
- } ?;
255
- match attr. token_tree ( ) {
256
- Some ( token_tree) => {
257
- let mut tree = syntax_node_to_token_tree (
258
- token_tree. syntax ( ) ,
259
- span_map,
260
- span,
261
- DocCommentDesugarMode :: ProcMacro ,
262
- ) ;
263
- * tree. top_subtree_delimiter_mut ( ) = tt:: Delimiter :: invisible_spanned ( span) ;
264
-
265
- Some ( tree)
266
- }
267
- _ => None ,
262
+ let attrs = RawAttrs :: new_expanded ( db, & item, span_map, loc. krate . cfg_options ( db) ) ;
263
+ attrs. iter ( ) . find ( |attr| attr. id == invoc_attr_index) . and_then ( |attr| {
264
+ match attr. input . as_deref ( ) ? {
265
+ AttrInput :: TokenTree ( tt) => {
266
+ let mut attr_arg = tt. clone ( ) ;
267
+ attr_arg. top_subtree_delimiter_mut ( ) . kind =
268
+ tt:: DelimiterKind :: Invisible ;
269
+ Some ( attr_arg)
270
+ }
271
+ AttrInput :: Literal ( _) => None ,
272
+ }
273
+ } )
268
274
}
269
275
}
270
276
_ => None ,
0 commit comments