File tree 3 files changed +16
-20
lines changed
3 files changed +16
-20
lines changed Original file line number Diff line number Diff line change @@ -202,21 +202,18 @@ impl Attribute {
202
202
}
203
203
}
204
204
205
- // Named `get_tokens` to distinguish it from the `<Attribute as HasTokens>::tokens` method.
206
- pub fn get_tokens ( & self ) -> TokenStream {
207
- match & self . kind {
208
- AttrKind :: Normal ( normal) => TokenStream :: new (
209
- normal
210
- . tokens
211
- . as_ref ( )
212
- . unwrap_or_else ( || panic ! ( "attribute is missing tokens: {self:?}" ) )
213
- . to_attr_token_stream ( )
214
- . to_token_trees ( ) ,
215
- ) ,
216
- & AttrKind :: DocComment ( comment_kind, data) => TokenStream :: token_alone (
205
+ pub fn token_trees ( & self ) -> Vec < TokenTree > {
206
+ match self . kind {
207
+ AttrKind :: Normal ( ref normal) => normal
208
+ . tokens
209
+ . as_ref ( )
210
+ . unwrap_or_else ( || panic ! ( "attribute is missing tokens: {self:?}" ) )
211
+ . to_attr_token_stream ( )
212
+ . to_token_trees ( ) ,
213
+ AttrKind :: DocComment ( comment_kind, data) => vec ! [ TokenTree :: token_alone(
217
214
token:: DocComment ( comment_kind, self . style, data) ,
218
215
self . span,
219
- ) ,
216
+ ) ] ,
220
217
}
221
218
}
222
219
}
Original file line number Diff line number Diff line change @@ -225,11 +225,12 @@ impl AttrTokenStream {
225
225
// properly implemented - we always synthesize fake tokens,
226
226
// so we never reach this code.
227
227
228
- let mut stream = TokenStream :: default ( ) ;
228
+ let mut tts = vec ! [ ] ;
229
229
for inner_attr in inner_attrs {
230
- stream . push_stream ( inner_attr. get_tokens ( ) ) ;
230
+ tts . extend ( inner_attr. token_trees ( ) ) ;
231
231
}
232
- stream. push_stream ( delim_tokens. clone ( ) ) ;
232
+ tts. extend ( delim_tokens. 0 . iter ( ) . cloned ( ) ) ;
233
+ let stream = TokenStream :: new ( tts) ;
233
234
* tree = TokenTree :: Delimited ( * span, * spacing, * delim, stream) ;
234
235
found = true ;
235
236
break ;
@@ -242,7 +243,7 @@ impl AttrTokenStream {
242
243
) ;
243
244
}
244
245
for attr in outer_attrs {
245
- res. extend ( attr. get_tokens ( ) . 0 . iter ( ) . cloned ( ) ) ;
246
+ res. extend ( attr. token_trees ( ) ) ;
246
247
}
247
248
res. extend ( target_tokens) ;
248
249
}
Original file line number Diff line number Diff line change @@ -292,8 +292,6 @@ impl<'a> StripUnconfigured<'a> {
292
292
attr : & Attribute ,
293
293
( item, item_span) : ( ast:: AttrItem , Span ) ,
294
294
) -> Attribute {
295
- let orig_tokens = attr. get_tokens ( ) ;
296
-
297
295
// We are taking an attribute of the form `#[cfg_attr(pred, attr)]`
298
296
// and producing an attribute of the form `#[attr]`. We
299
297
// have captured tokens for `attr` itself, but we need to
@@ -302,7 +300,7 @@ impl<'a> StripUnconfigured<'a> {
302
300
303
301
// Use the `#` in `#[cfg_attr(pred, attr)]` as the `#` token
304
302
// for `attr` when we expand it to `#[attr]`
305
- let mut orig_trees = orig_tokens . trees ( ) ;
303
+ let mut orig_trees = attr . token_trees ( ) . into_iter ( ) ;
306
304
let TokenTree :: Token ( pound_token @ Token { kind : TokenKind :: Pound , .. } , _) =
307
305
orig_trees. next ( ) . unwrap ( ) . clone ( )
308
306
else {
You can’t perform that action at this time.
0 commit comments