@@ -13,7 +13,7 @@ use crate::{
1313 AstId , BuiltinAttrExpander , BuiltinDeriveExpander , BuiltinFnLikeExpander , EagerCallInfo ,
1414 EagerExpander , EditionedFileId , ExpandError , ExpandResult , ExpandTo , HirFileId , MacroCallId ,
1515 MacroCallKind , MacroCallLoc , MacroDefId , MacroDefKind ,
16- attrs:: { AttrId , collect_attrs} ,
16+ attrs:: { AttrId , AttrInput , RawAttrs , collect_attrs} ,
1717 builtin:: pseudo_derive_attr_expansion,
1818 cfg_process,
1919 declarative:: DeclarativeMacroExpander ,
@@ -241,30 +241,36 @@ pub fn expand_speculative(
241241
242242 let attr_arg = match loc. kind {
243243 MacroCallKind :: Attr { invoc_attr_index, .. } => {
244- let attr = if loc. def . is_attribute_derive ( ) {
244+ if loc. def . is_attribute_derive ( ) {
245245 // 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+ )
247258 } else {
248259 // Attributes may have an input token tree, build the subtree and map for this as well
249260 // then try finding a token id for our token if it is inside this input subtree.
250261 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+ } )
268274 }
269275 }
270276 _ => None ,
0 commit comments