Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 2c6ce48

Browse files
committed
Remove Delimier::dummy_invisible
1 parent 4ec8123 commit 2c6ce48

File tree

5 files changed

+24
-25
lines changed

5 files changed

+24
-25
lines changed

crates/hir-expand/src/attrs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl RawAttrs {
120120
let attrs =
121121
parts.enumerate().take(1 << AttrId::CFG_ATTR_BITS).filter_map(|(idx, attr)| {
122122
let tree = Subtree {
123-
delimiter: tt::Delimiter::dummy_invisible(),
123+
delimiter: tt::Delimiter::invisible_spanned(attr.first()?.first_span()),
124124
token_trees: attr.to_vec(),
125125
};
126126
Attr::from_tt(db, &tree, index.with_cfg_attr(idx))
@@ -282,7 +282,7 @@ impl Attr {
282282
// FIXME: This is necessarily a hack. It'd be nice if we could avoid allocation
283283
// here or maybe just parse a mod path from a token tree directly
284284
let subtree = tt::Subtree {
285-
delimiter: tt::Delimiter::dummy_invisible(),
285+
delimiter: tt::Delimiter::invisible_spanned(tts.first()?.first_span()),
286286
token_trees: tts.to_vec(),
287287
};
288288
let (parse, span_map) =

crates/hir-expand/src/builtin_fn_macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn line_expand(
154154
// Note that `line!` and `column!` will never be implemented properly, as they are by definition
155155
// not incremental
156156
ExpandResult::ok(tt::Subtree {
157-
delimiter: tt::Delimiter::dummy_invisible(),
157+
delimiter: tt::Delimiter::invisible_spanned(span),
158158
token_trees: vec![tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
159159
text: "0u32".into(),
160160
span,
@@ -206,7 +206,7 @@ fn assert_expand(
206206
let expanded = match &*args {
207207
[cond, panic_args @ ..] => {
208208
let comma = tt::Subtree {
209-
delimiter: tt::Delimiter::dummy_invisible(),
209+
delimiter: tt::Delimiter::invisible_spanned(span),
210210
token_trees: vec![tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct {
211211
char: ',',
212212
spacing: tt::Spacing::Alone,
@@ -631,7 +631,7 @@ fn include_bytes_expand(
631631
) -> ExpandResult<tt::Subtree> {
632632
// FIXME: actually read the file here if the user asked for macro expansion
633633
let res = tt::Subtree {
634-
delimiter: tt::Delimiter::dummy_invisible(),
634+
delimiter: tt::Delimiter::invisible_spanned(span),
635635
token_trees: vec![tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
636636
text: r#"b"""#.into(),
637637
span,

crates/mbe/src/expander/matcher.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ fn match_meta_var<S: Span>(
797797
return input.expect_fragment(parser::PrefixEntryPoint::Expr).map(|tt| {
798798
tt.map(|tt| match tt {
799799
tt::TokenTree::Leaf(leaf) => tt::Subtree {
800-
delimiter: tt::Delimiter::dummy_invisible(),
800+
delimiter: tt::Delimiter::invisible_spanned(*leaf.span()),
801801
token_trees: vec![leaf.into()],
802802
},
803803
tt::TokenTree::Subtree(mut s) => {
@@ -831,7 +831,7 @@ fn match_meta_var<S: Span>(
831831
match neg {
832832
None => lit.into(),
833833
Some(neg) => tt::TokenTree::Subtree(tt::Subtree {
834-
delimiter: tt::Delimiter::dummy_invisible(),
834+
delimiter: tt::Delimiter::invisible_spanned(*literal.span()),
835835
token_trees: vec![neg, lit.into()],
836836
}),
837837
}
@@ -960,11 +960,13 @@ impl<S: Span> TtIter<'_, S> {
960960
self.expect_lifetime()
961961
} else {
962962
let puncts = self.expect_glued_punct()?;
963+
let delimiter = tt::Delimiter {
964+
open: puncts.first().unwrap().span,
965+
close: puncts.last().unwrap().span,
966+
kind: tt::DelimiterKind::Invisible,
967+
};
963968
let token_trees = puncts.into_iter().map(|p| tt::Leaf::Punct(p).into()).collect();
964-
Ok(tt::TokenTree::Subtree(tt::Subtree {
965-
delimiter: tt::Delimiter::dummy_invisible(),
966-
token_trees,
967-
}))
969+
Ok(tt::TokenTree::Subtree(tt::Subtree { delimiter, token_trees }))
968970
}
969971
} else {
970972
self.next().ok_or(()).cloned()
@@ -979,7 +981,11 @@ impl<S: Span> TtIter<'_, S> {
979981
let ident = self.expect_ident_or_underscore()?;
980982

981983
Ok(tt::Subtree {
982-
delimiter: tt::Delimiter::dummy_invisible(),
984+
delimiter: tt::Delimiter {
985+
open: punct.span,
986+
close: ident.span,
987+
kind: tt::DelimiterKind::Invisible,
988+
},
983989
token_trees: vec![
984990
tt::Leaf::Punct(*punct).into(),
985991
tt::Leaf::Ident(ident.clone()).into(),

crates/mbe/src/expander/transcriber.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ fn expand_subtree<S: Span>(
318318
let tts = arena.drain(start_elements..).collect();
319319
ExpandResult {
320320
value: tt::Subtree {
321-
delimiter: delimiter.unwrap_or_else(tt::Delimiter::dummy_invisible),
321+
delimiter: delimiter.unwrap_or_else(|| tt::Delimiter::invisible_spanned(ctx.call_site)),
322322
token_trees: tts,
323323
},
324324
err,
@@ -408,7 +408,7 @@ fn expand_repeat<S: Span>(
408408
return ExpandResult {
409409
value: Fragment::Tokens(
410410
tt::Subtree {
411-
delimiter: tt::Delimiter::dummy_invisible(),
411+
delimiter: tt::Delimiter::invisible_spanned(ctx.call_site),
412412
token_trees: vec![],
413413
}
414414
.into(),

crates/tt/src/lib.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ impl<S: Span> TokenTree<S> {
6262
TokenTree::Subtree(s) => s,
6363
}
6464
}
65-
pub fn subtree_or_wrap2(self, span: DelimSpan<S>) -> Subtree<S> {
65+
66+
pub fn first_span(&self) -> S {
6667
match self {
67-
TokenTree::Leaf(_) => Subtree {
68-
delimiter: Delimiter::invisible_delim_spanned(span),
69-
token_trees: vec![self],
70-
},
71-
TokenTree::Subtree(s) => s,
68+
TokenTree::Leaf(l) => *l.span(),
69+
TokenTree::Subtree(s) => s.delimiter.open,
7270
}
7371
}
7472
}
@@ -141,11 +139,6 @@ impl<S: Span> Delimiter<S> {
141139
pub const DUMMY_INVISIBLE: Self =
142140
Self { open: S::DUMMY, close: S::DUMMY, kind: DelimiterKind::Invisible };
143141

144-
// FIXME should not exist
145-
pub const fn dummy_invisible() -> Self {
146-
Self::DUMMY_INVISIBLE
147-
}
148-
149142
pub const fn invisible_spanned(span: S) -> Self {
150143
Delimiter { open: span, close: span, kind: DelimiterKind::Invisible }
151144
}

0 commit comments

Comments
 (0)