minor: drop dead code

This commit is contained in:
Aleksey Kladov 2022-01-02 19:03:38 +03:00
parent 2e34a5e2e9
commit 174c439c56
2 changed files with 3 additions and 16 deletions

View File

@ -215,6 +215,8 @@ fn parse_or_expand(db: &dyn AstDatabase, file_id: HirFileId) -> Option<SyntaxNod
match file_id.0 { match file_id.0 {
HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()), HirFileIdRepr::FileId(file_id) => Some(db.parse(file_id).tree().syntax().clone()),
HirFileIdRepr::MacroFile(macro_file) => { HirFileIdRepr::MacroFile(macro_file) => {
// FIXME: Note how we convert from `Parse` to `SyntaxNode` here,
// forgetting about parse errors.
db.parse_macro_expansion(macro_file).value.map(|(it, _)| it.syntax_node()) db.parse_macro_expansion(macro_file).value.map(|(it, _)| it.syntax_node())
} }
} }

View File

@ -1,7 +1,7 @@
//! Conversions between [`SyntaxNode`] and [`tt::TokenTree`]. //! Conversions between [`SyntaxNode`] and [`tt::TokenTree`].
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use stdx::{never, non_empty_vec::NonEmptyVec}; use stdx::non_empty_vec::NonEmptyVec;
use syntax::{ use syntax::{
ast::{self, make::tokens::doc_comment}, ast::{self, make::tokens::doc_comment},
AstToken, Parse, PreorderWithTokens, SmolStr, SyntaxElement, SyntaxKind, AstToken, Parse, PreorderWithTokens, SmolStr, SyntaxElement, SyntaxKind,
@ -66,10 +66,6 @@ pub fn token_tree_to_syntax_node(
parser::Step::Error { msg } => tree_sink.error(msg.to_string()), parser::Step::Error { msg } => tree_sink.error(msg.to_string()),
} }
} }
if never!(tree_sink.roots.len() != 1) {
return Err(ExpandError::ConversionError);
}
//FIXME: would be cool to report errors
let (parse, range_map) = tree_sink.finish(); let (parse, range_map) = tree_sink.finish();
Ok((parse, range_map)) Ok((parse, range_map))
} }
@ -614,10 +610,6 @@ struct TtTreeSink<'a> {
text_pos: TextSize, text_pos: TextSize,
inner: SyntaxTreeBuilder, inner: SyntaxTreeBuilder,
token_map: TokenMap, token_map: TokenMap,
// Number of roots
// Use for detect ill-form tree which is not single root
roots: smallvec::SmallVec<[usize; 1]>,
} }
impl<'a> TtTreeSink<'a> { impl<'a> TtTreeSink<'a> {
@ -628,7 +620,6 @@ impl<'a> TtTreeSink<'a> {
open_delims: FxHashMap::default(), open_delims: FxHashMap::default(),
text_pos: 0.into(), text_pos: 0.into(),
inner: SyntaxTreeBuilder::default(), inner: SyntaxTreeBuilder::default(),
roots: smallvec::SmallVec::new(),
token_map: TokenMap::default(), token_map: TokenMap::default(),
} }
} }
@ -733,16 +724,10 @@ impl<'a> TtTreeSink<'a> {
fn start_node(&mut self, kind: SyntaxKind) { fn start_node(&mut self, kind: SyntaxKind) {
self.inner.start_node(kind); self.inner.start_node(kind);
match self.roots.last_mut() {
None | Some(0) => self.roots.push(1),
Some(n) => *n += 1,
};
} }
fn finish_node(&mut self) { fn finish_node(&mut self) {
self.inner.finish_node(); self.inner.finish_node();
*self.roots.last_mut().unwrap() -= 1;
} }
fn error(&mut self, error: String) { fn error(&mut self, error: String) {