Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir_def/src/attr.rs')
-rw-r--r--crates/hir_def/src/attr.rs52
1 files changed, 25 insertions, 27 deletions
diff --git a/crates/hir_def/src/attr.rs b/crates/hir_def/src/attr.rs
index fd45eccf5a..711062c713 100644
--- a/crates/hir_def/src/attr.rs
+++ b/crates/hir_def/src/attr.rs
@@ -723,34 +723,32 @@ impl Attr {
/// to derive macros.
///
/// Returns `None` when the attribute does not have a well-formed `#[derive]` attribute input.
- pub(crate) fn parse_derive(&self) -> Option<impl Iterator<Item = ModPath>> {
- if let Some(AttrInput::TokenTree(args, _)) = self.input.as_deref() {
- if args.delimiter_kind() != Some(DelimiterKind::Parenthesis) {
- return None;
- }
- let mut counter = 0;
- let paths = args
- .token_trees
- .iter()
- .group_by(move |tt| {
- if let tt::TokenTree::Leaf(tt::Leaf::Punct(Punct { char: ',', .. })) = tt {
- counter += 1;
- }
- counter
- })
- .into_iter()
- .map(|(_, tts)| {
- let segments = tts.filter_map(|tt| match tt {
- tt::TokenTree::Leaf(tt::Leaf::Ident(id)) => Some(id.as_name()),
- _ => None,
- });
- ModPath::from_segments(PathKind::Plain, segments)
- })
- .collect::<Vec<_>>();
-
- return Some(paths.into_iter());
+ pub(crate) fn parse_derive(&self) -> Option<impl Iterator<Item = ModPath> + '_> {
+ let args = match self.input.as_deref() {
+ Some(AttrInput::TokenTree(args, _)) => args,
+ _ => return None,
+ };
+
+ if args.delimiter_kind() != Some(DelimiterKind::Parenthesis) {
+ return None;
}
- None
+ let paths = args
+ .token_trees
+ .iter()
+ .group_by(|tt| {
+ matches!(tt, tt::TokenTree::Leaf(tt::Leaf::Punct(Punct { char: ',', .. })))
+ })
+ .into_iter()
+ .map(|(_, tts)| {
+ let segments = tts.filter_map(|tt| match tt {
+ tt::TokenTree::Leaf(tt::Leaf::Ident(id)) => Some(id.as_name()),
+ _ => None,
+ });
+ ModPath::from_segments(PathKind::Plain, segments)
+ })
+ .collect::<Vec<_>>();
+
+ return Some(paths.into_iter());
}
pub fn string_value(&self) -> Option<&SmolStr> {