Fix dead code warnings

This commit is contained in:
Lukas Wirth 2023-12-15 16:12:26 +01:00
parent 96051bc0d8
commit 9197b541c2
4 changed files with 13 additions and 53 deletions

View file

@ -34,7 +34,7 @@ use std::{
use proc_macro_api::{
msg::{
self, deserialize_span_data_index_map, serialize_span_data_index_map, ExpnGlobals,
SpanDataIndexMap, SpanMode, TokenId, CURRENT_API_VERSION,
SpanMode, TokenId, CURRENT_API_VERSION,
},
ProcMacroKind,
};

View file

@ -13,8 +13,6 @@ use crate::server::{
Symbol, SymbolInternerRef, SYMBOL_INTERNER,
};
mod tt {
pub use proc_macro_api::msg::TokenId;
pub use ::tt::*;
pub type Subtree = ::tt::Subtree<super::Span>;
@ -24,11 +22,7 @@ mod tt {
pub type Punct = ::tt::Punct<super::Span>;
pub type Ident = ::tt::Ident<super::Span>;
}
type Group = tt::Subtree;
type TokenTree = tt::TokenTree;
type Punct = tt::Punct;
type Spacing = tt::Spacing;
type Literal = tt::Literal;
type TokenStream = crate::server::TokenStream<Span>;
#[derive(Clone)]
@ -96,14 +90,14 @@ impl server::TokenStream for RaSpanServer {
) -> Self::TokenStream {
match tree {
bridge::TokenTree::Group(group) => {
let group = Group {
let group = tt::Subtree {
delimiter: delim_to_internal(group.delimiter, group.span),
token_trees: match group.stream {
Some(stream) => stream.into_iter().collect(),
None => Vec::new(),
},
};
let tree = TokenTree::from(group);
let tree = tt::TokenTree::from(group);
Self::TokenStream::from_iter(iter::once(tree))
}
@ -113,7 +107,7 @@ impl server::TokenStream for RaSpanServer {
if ident.is_raw { ::tt::SmolStr::from_iter(["r#", &text]) } else { text };
let ident: tt::Ident = tt::Ident { text, span: ident.span };
let leaf = tt::Leaf::from(ident);
let tree = TokenTree::from(leaf);
let tree = tt::TokenTree::from(leaf);
Self::TokenStream::from_iter(iter::once(tree))
}
@ -124,19 +118,21 @@ impl server::TokenStream for RaSpanServer {
});
let literal = tt::Literal { text, span: literal.0.span };
let leaf = tt::Leaf::from(literal);
let tree = TokenTree::from(leaf);
let leaf: ::tt::Leaf<
::tt::SpanData<base_db::span::SpanAnchor, base_db::span::SyntaxContextId>,
> = tt::Leaf::from(literal);
let tree = tt::TokenTree::from(leaf);
Self::TokenStream::from_iter(iter::once(tree))
}
bridge::TokenTree::Punct(p) => {
let punct = tt::Punct {
char: p.ch as char,
spacing: if p.joint { Spacing::Joint } else { Spacing::Alone },
spacing: if p.joint { tt::Spacing::Joint } else { tt::Spacing::Alone },
span: p.span,
};
let leaf = tt::Leaf::from(punct);
let tree = TokenTree::from(leaf);
let tree = tt::TokenTree::from(leaf);
Self::TokenStream::from_iter(iter::once(tree))
}
}
@ -208,7 +204,7 @@ impl server::TokenStream for RaSpanServer {
tt::TokenTree::Leaf(tt::Leaf::Punct(punct)) => {
bridge::TokenTree::Punct(bridge::Punct {
ch: punct.char as u8,
joint: punct.spacing == Spacing::Joint,
joint: punct.spacing == tt::Spacing::Joint,
span: punct.span,
})
}

View file

@ -141,42 +141,6 @@ pub(super) mod token_stream {
::tt::pretty(&self.token_trees)
}
}
fn subtree_replace_spans_with_call_site<S: Copy>(
subtree: tt::Subtree<S>,
call_site: S,
) -> tt::Subtree<S> {
tt::Subtree {
delimiter: tt::Delimiter { open: call_site, close: call_site, ..subtree.delimiter },
token_trees: subtree
.token_trees
.into_iter()
.map(|it| token_tree_replace_spans_with_call_site(it, call_site))
.collect(),
}
}
fn token_tree_replace_spans_with_call_site<S: Copy>(
tt: tt::TokenTree<S>,
call_site: S,
) -> tt::TokenTree<S> {
match tt {
tt::TokenTree::Leaf(leaf) => {
tt::TokenTree::Leaf(leaf_replace_spans_with_call_site(leaf, call_site))
}
tt::TokenTree::Subtree(subtree) => {
tt::TokenTree::Subtree(subtree_replace_spans_with_call_site(subtree, call_site))
}
}
}
fn leaf_replace_spans_with_call_site<S: Copy>(leaf: tt::Leaf<S>, call_site: S) -> tt::Leaf<S> {
match leaf {
tt::Leaf::Literal(lit) => tt::Leaf::Literal(tt::Literal { span: call_site, ..lit }),
tt::Leaf::Punct(punct) => tt::Leaf::Punct(tt::Punct { span: call_site, ..punct }),
tt::Leaf::Ident(ident) => tt::Leaf::Ident(tt::Ident { span: call_site, ..ident }),
}
}
}
impl<S> TokenStreamBuilder<S> {

View file

@ -5,7 +5,7 @@ use base_db::{
FileId,
};
use expect_test::Expect;
use proc_macro_api::msg::{SpanDataIndexMap, TokenId};
use proc_macro_api::msg::TokenId;
use tt::TextRange;
use crate::{dylib, proc_macro_test_dylib_path, ProcMacroSrv};