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