diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-07-10 14:51:41 +1000 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2024-07-10 14:51:41 +1000 |
| commit | fee152556fda2260a17fa24cea21d18b57c8460d (patch) | |
| tree | 941096aa66c3942d40c74a23a067564e23f0ce11 /compiler/rustc_ast/src/attr/mod.rs | |
| parent | 8a390bae06dbb5686b581797b8f46cb0353dc255 (diff) | |
| download | rust-fee152556fda2260a17fa24cea21d18b57c8460d.tar.gz rust-fee152556fda2260a17fa24cea21d18b57c8460d.zip | |
Rework `Attribute::get_tokens`.
Returning `Vec<TokenTree>` works better for the call sites than returning `TokenStream`.
Diffstat (limited to 'compiler/rustc_ast/src/attr/mod.rs')
| -rw-r--r-- | compiler/rustc_ast/src/attr/mod.rs | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index 088ae9ba441..d2c7b1c0753 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -202,21 +202,18 @@ impl Attribute { } } - // Named `get_tokens` to distinguish it from the `<Attribute as HasTokens>::tokens` method. - pub fn get_tokens(&self) -> TokenStream { - match &self.kind { - AttrKind::Normal(normal) => TokenStream::new( - normal - .tokens - .as_ref() - .unwrap_or_else(|| panic!("attribute is missing tokens: {self:?}")) - .to_attr_token_stream() - .to_token_trees(), - ), - &AttrKind::DocComment(comment_kind, data) => TokenStream::token_alone( + pub fn token_trees(&self) -> Vec<TokenTree> { + match self.kind { + AttrKind::Normal(ref normal) => normal + .tokens + .as_ref() + .unwrap_or_else(|| panic!("attribute is missing tokens: {self:?}")) + .to_attr_token_stream() + .to_token_trees(), + AttrKind::DocComment(comment_kind, data) => vec![TokenTree::token_alone( token::DocComment(comment_kind, self.style, data), self.span, - ), + )], } } } |
