mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 04:53:34 +00:00
Remove Delimier::dummy_invisible
This commit is contained in:
parent
4ec81230db
commit
2c6ce480e3
5 changed files with 24 additions and 25 deletions
|
@ -120,7 +120,7 @@ impl RawAttrs {
|
|||
let attrs =
|
||||
parts.enumerate().take(1 << AttrId::CFG_ATTR_BITS).filter_map(|(idx, attr)| {
|
||||
let tree = Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
delimiter: tt::Delimiter::invisible_spanned(attr.first()?.first_span()),
|
||||
token_trees: attr.to_vec(),
|
||||
};
|
||||
Attr::from_tt(db, &tree, index.with_cfg_attr(idx))
|
||||
|
@ -282,7 +282,7 @@ impl Attr {
|
|||
// FIXME: This is necessarily a hack. It'd be nice if we could avoid allocation
|
||||
// here or maybe just parse a mod path from a token tree directly
|
||||
let subtree = tt::Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
delimiter: tt::Delimiter::invisible_spanned(tts.first()?.first_span()),
|
||||
token_trees: tts.to_vec(),
|
||||
};
|
||||
let (parse, span_map) =
|
||||
|
|
|
@ -154,7 +154,7 @@ fn line_expand(
|
|||
// Note that `line!` and `column!` will never be implemented properly, as they are by definition
|
||||
// not incremental
|
||||
ExpandResult::ok(tt::Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
delimiter: tt::Delimiter::invisible_spanned(span),
|
||||
token_trees: vec![tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
|
||||
text: "0u32".into(),
|
||||
span,
|
||||
|
@ -206,7 +206,7 @@ fn assert_expand(
|
|||
let expanded = match &*args {
|
||||
[cond, panic_args @ ..] => {
|
||||
let comma = tt::Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
delimiter: tt::Delimiter::invisible_spanned(span),
|
||||
token_trees: vec![tt::TokenTree::Leaf(tt::Leaf::Punct(tt::Punct {
|
||||
char: ',',
|
||||
spacing: tt::Spacing::Alone,
|
||||
|
@ -631,7 +631,7 @@ fn include_bytes_expand(
|
|||
) -> ExpandResult<tt::Subtree> {
|
||||
// FIXME: actually read the file here if the user asked for macro expansion
|
||||
let res = tt::Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
delimiter: tt::Delimiter::invisible_spanned(span),
|
||||
token_trees: vec![tt::TokenTree::Leaf(tt::Leaf::Literal(tt::Literal {
|
||||
text: r#"b"""#.into(),
|
||||
span,
|
||||
|
|
|
@ -797,7 +797,7 @@ fn match_meta_var<S: Span>(
|
|||
return input.expect_fragment(parser::PrefixEntryPoint::Expr).map(|tt| {
|
||||
tt.map(|tt| match tt {
|
||||
tt::TokenTree::Leaf(leaf) => tt::Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
delimiter: tt::Delimiter::invisible_spanned(*leaf.span()),
|
||||
token_trees: vec![leaf.into()],
|
||||
},
|
||||
tt::TokenTree::Subtree(mut s) => {
|
||||
|
@ -831,7 +831,7 @@ fn match_meta_var<S: Span>(
|
|||
match neg {
|
||||
None => lit.into(),
|
||||
Some(neg) => tt::TokenTree::Subtree(tt::Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
delimiter: tt::Delimiter::invisible_spanned(*literal.span()),
|
||||
token_trees: vec![neg, lit.into()],
|
||||
}),
|
||||
}
|
||||
|
@ -960,11 +960,13 @@ impl<S: Span> TtIter<'_, S> {
|
|||
self.expect_lifetime()
|
||||
} else {
|
||||
let puncts = self.expect_glued_punct()?;
|
||||
let delimiter = tt::Delimiter {
|
||||
open: puncts.first().unwrap().span,
|
||||
close: puncts.last().unwrap().span,
|
||||
kind: tt::DelimiterKind::Invisible,
|
||||
};
|
||||
let token_trees = puncts.into_iter().map(|p| tt::Leaf::Punct(p).into()).collect();
|
||||
Ok(tt::TokenTree::Subtree(tt::Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
token_trees,
|
||||
}))
|
||||
Ok(tt::TokenTree::Subtree(tt::Subtree { delimiter, token_trees }))
|
||||
}
|
||||
} else {
|
||||
self.next().ok_or(()).cloned()
|
||||
|
@ -979,7 +981,11 @@ impl<S: Span> TtIter<'_, S> {
|
|||
let ident = self.expect_ident_or_underscore()?;
|
||||
|
||||
Ok(tt::Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
delimiter: tt::Delimiter {
|
||||
open: punct.span,
|
||||
close: ident.span,
|
||||
kind: tt::DelimiterKind::Invisible,
|
||||
},
|
||||
token_trees: vec![
|
||||
tt::Leaf::Punct(*punct).into(),
|
||||
tt::Leaf::Ident(ident.clone()).into(),
|
||||
|
|
|
@ -318,7 +318,7 @@ fn expand_subtree<S: Span>(
|
|||
let tts = arena.drain(start_elements..).collect();
|
||||
ExpandResult {
|
||||
value: tt::Subtree {
|
||||
delimiter: delimiter.unwrap_or_else(tt::Delimiter::dummy_invisible),
|
||||
delimiter: delimiter.unwrap_or_else(|| tt::Delimiter::invisible_spanned(ctx.call_site)),
|
||||
token_trees: tts,
|
||||
},
|
||||
err,
|
||||
|
@ -408,7 +408,7 @@ fn expand_repeat<S: Span>(
|
|||
return ExpandResult {
|
||||
value: Fragment::Tokens(
|
||||
tt::Subtree {
|
||||
delimiter: tt::Delimiter::dummy_invisible(),
|
||||
delimiter: tt::Delimiter::invisible_spanned(ctx.call_site),
|
||||
token_trees: vec![],
|
||||
}
|
||||
.into(),
|
||||
|
|
|
@ -62,13 +62,11 @@ impl<S: Span> TokenTree<S> {
|
|||
TokenTree::Subtree(s) => s,
|
||||
}
|
||||
}
|
||||
pub fn subtree_or_wrap2(self, span: DelimSpan<S>) -> Subtree<S> {
|
||||
|
||||
pub fn first_span(&self) -> S {
|
||||
match self {
|
||||
TokenTree::Leaf(_) => Subtree {
|
||||
delimiter: Delimiter::invisible_delim_spanned(span),
|
||||
token_trees: vec![self],
|
||||
},
|
||||
TokenTree::Subtree(s) => s,
|
||||
TokenTree::Leaf(l) => *l.span(),
|
||||
TokenTree::Subtree(s) => s.delimiter.open,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -141,11 +139,6 @@ impl<S: Span> Delimiter<S> {
|
|||
pub const DUMMY_INVISIBLE: Self =
|
||||
Self { open: S::DUMMY, close: S::DUMMY, kind: DelimiterKind::Invisible };
|
||||
|
||||
// FIXME should not exist
|
||||
pub const fn dummy_invisible() -> Self {
|
||||
Self::DUMMY_INVISIBLE
|
||||
}
|
||||
|
||||
pub const fn invisible_spanned(span: S) -> Self {
|
||||
Delimiter { open: span, close: span, kind: DelimiterKind::Invisible }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue