Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-expand/src/attrs.rs')
-rw-r--r--crates/hir-expand/src/attrs.rs19
1 files changed, 8 insertions, 11 deletions
diff --git a/crates/hir-expand/src/attrs.rs b/crates/hir-expand/src/attrs.rs
index e1807cd2e1..5a44018720 100644
--- a/crates/hir-expand/src/attrs.rs
+++ b/crates/hir-expand/src/attrs.rs
@@ -36,6 +36,7 @@ use base_db::Crate;
use cfg::{CfgExpr, CfgOptions};
use either::Either;
use intern::{Interned, Symbol};
+use itertools::Itertools;
use mbe::{DelimiterKind, Punct};
use parser::T;
use smallvec::SmallVec;
@@ -453,10 +454,10 @@ impl Attr {
}
/// #[path(ident)]
- pub fn single_ident_value(&self) -> Option<&tt::Ident> {
+ pub fn single_ident_value(&self) -> Option<tt::Ident> {
match self.input.as_deref()? {
- AttrInput::TokenTree(tt) => match tt.token_trees().flat_tokens() {
- [tt::TokenTree::Leaf(tt::Leaf::Ident(ident))] => Some(ident),
+ AttrInput::TokenTree(tt) => match tt.token_trees().iter().collect_array() {
+ Some([tt::TtElement::Leaf(tt::Leaf::Ident(ident))]) => Some(ident),
_ => None,
},
_ => None,
@@ -492,7 +493,7 @@ fn parse_path_comma_token_tree<'a>(
args.token_trees()
.split(|tt| matches!(tt, tt::TtElement::Leaf(tt::Leaf::Punct(Punct { char: ',', .. }))))
.filter_map(move |tts| {
- let span = tts.flat_tokens().first()?.first_span();
+ let span = tts.first_span()?;
Some((ModPath::from_tt(db, tts)?, span, tts))
})
}
@@ -611,16 +612,12 @@ impl AttrId {
else {
return derive_attr_range;
};
- let (Some(first_tt), Some(last_tt)) =
- (derive_tts.flat_tokens().first(), derive_tts.flat_tokens().last())
+ let (Some(first_span), Some(last_span)) = (derive_tts.first_span(), derive_tts.last_span())
else {
return derive_attr_range;
};
- let start = first_tt.first_span().range.start();
- let end = match last_tt {
- tt::TokenTree::Leaf(it) => it.span().range.end(),
- tt::TokenTree::Subtree(it) => it.delimiter.close.range.end(),
- };
+ let start = first_span.range.start();
+ let end = last_span.range.end();
TextRange::new(start, end)
}
}