Remove dead code

This commit is contained in:
Aleksey Kladov 2020-04-11 19:25:33 +02:00
parent 7a39bc3ba2
commit 0aece75cdd
8 changed files with 40 additions and 55 deletions

View file

@ -317,8 +317,7 @@ fn scope_for_offset(
if source.file_id != offset.file_id {
return None;
}
let syntax_node_ptr =
source.value.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr());
let syntax_node_ptr = source.value.syntax_node_ptr();
Some((syntax_node_ptr, scope))
})
// find containing scope
@ -397,8 +396,7 @@ fn adjust(
if source.file_id != file_id {
return None;
}
let syntax_node_ptr =
source.value.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr());
let syntax_node_ptr = source.value.syntax_node_ptr();
Some((syntax_node_ptr, scope))
})
.map(|(ptr, scope)| (ptr.range(), scope))

View file

@ -9,6 +9,8 @@ use drop_bomb::DropBomb;
use either::Either;
use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId};
use ra_arena::{map::ArenaMap, Arena};
use ra_cfg::CfgOptions;
use ra_db::CrateId;
use ra_prof::profile;
use ra_syntax::{ast, AstNode, AstPtr};
use rustc_hash::FxHashMap;
@ -24,8 +26,6 @@ use crate::{
src::HasSource,
AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId,
};
use ra_cfg::CfgOptions;
use ra_db::CrateId;
/// A subser of Exander that only deals with cfg attributes. We only need it to
/// avoid cyclic queries in crate def map during enum processing.
@ -187,7 +187,7 @@ pub struct Body {
pub item_scope: ItemScope,
}
pub type ExprPtr = Either<AstPtr<ast::Expr>, AstPtr<ast::RecordField>>;
pub type ExprPtr = AstPtr<ast::Expr>;
pub type ExprSource = InFile<ExprPtr>;
pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>;
@ -285,7 +285,7 @@ impl BodySourceMap {
}
pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
let src = node.map(|it| Either::Left(AstPtr::new(it)));
let src = node.map(|it| AstPtr::new(it));
self.expr_map.get(&src).cloned()
}

View file

@ -101,7 +101,6 @@ impl ExprCollector<'_> {
}
fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
let ptr = Either::Left(ptr);
let src = self.expander.to_source(ptr);
let id = self.make_expr(expr, Ok(src.clone()));
self.source_map.expr_map.insert(src, id);
@ -281,7 +280,7 @@ impl ExprCollector<'_> {
ast::Expr::ParenExpr(e) => {
let inner = self.collect_expr_opt(e.expr());
// make the paren expr point to the inner expression as well
let src = self.expander.to_source(Either::Left(syntax_ptr));
let src = self.expander.to_source(syntax_ptr);
self.source_map.expr_map.insert(src, inner);
inner
}

View file

@ -89,21 +89,19 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
let (_, source_map) = db.body_with_source_map(self.func.into());
if let Ok(source_ptr) = source_map.expr_syntax(id) {
if let Some(expr) = source_ptr.value.as_ref().left() {
let root = source_ptr.file_syntax(db.upcast());
if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) {
if let Some(field_list) = record_lit.record_field_list() {
let variant_data = variant_data(db.upcast(), variant_def);
let missed_fields = missed_fields
.into_iter()
.map(|idx| variant_data.fields()[idx].name.clone())
.collect();
self.sink.push(MissingFields {
file: source_ptr.file_id,
field_list: AstPtr::new(&field_list),
missed_fields,
})
}
let root = source_ptr.file_syntax(db.upcast());
if let ast::Expr::RecordLit(record_lit) = &source_ptr.value.to_node(&root) {
if let Some(field_list) = record_lit.record_field_list() {
let variant_data = variant_data(db.upcast(), variant_def);
let missed_fields = missed_fields
.into_iter()
.map(|idx| variant_data.fields()[idx].name.clone())
.collect();
self.sink.push(MissingFields {
file: source_ptr.file_id,
field_list: AstPtr::new(&field_list),
missed_fields,
})
}
}
}
@ -205,18 +203,16 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
}
if let Ok(source_ptr) = source_map.expr_syntax(id) {
if let Some(expr) = source_ptr.value.as_ref().left() {
let root = source_ptr.file_syntax(db.upcast());
if let ast::Expr::MatchExpr(match_expr) = expr.to_node(&root) {
if let (Some(match_expr), Some(arms)) =
(match_expr.expr(), match_expr.match_arm_list())
{
self.sink.push(MissingMatchArms {
file: source_ptr.file_id,
match_expr: AstPtr::new(&match_expr),
arms: AstPtr::new(&arms),
})
}
let root = source_ptr.file_syntax(db.upcast());
if let ast::Expr::MatchExpr(match_expr) = &source_ptr.value.to_node(&root) {
if let (Some(match_expr), Some(arms)) =
(match_expr.expr(), match_expr.match_arm_list())
{
self.sink.push(MissingMatchArms {
file: source_ptr.file_id,
match_expr: AstPtr::new(&match_expr),
arms: AstPtr::new(&arms),
})
}
}
}
@ -247,9 +243,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
let (_, source_map) = db.body_with_source_map(self.func.into());
if let Ok(source_ptr) = source_map.expr_syntax(id) {
if let Some(expr) = source_ptr.value.left() {
self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr });
}
self.sink
.push(MissingOkInTailExpr { file: source_ptr.file_id, expr: source_ptr.value });
}
}
}

View file

@ -82,9 +82,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
for (expr, ty) in inference_result.type_of_expr.iter() {
let syntax_ptr = match body_source_map.expr_syntax(expr) {
Ok(sp) => {
sp.map(|ast| ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()))
}
Ok(sp) => sp.map(|ast| ast.syntax_node_ptr()),
Err(SyntheticSyntax) => continue,
};
types.push((syntax_ptr.clone(), ty));

View file

@ -189,8 +189,6 @@ impl ast::StructDef {
impl ast::RecordField {
pub fn for_field_name(field_name: &ast::NameRef) -> Option<ast::RecordField> {
eprintln!("field_name = {}", field_name);
dbg!(field_name.syntax().ancestors().nth(6));
let candidate =
field_name.syntax().parent().and_then(ast::RecordField::cast).or_else(|| {
field_name.syntax().ancestors().nth(4).and_then(ast::RecordField::cast)

View file

@ -19,6 +19,11 @@
//! [RFC]: <https://github.com/rust-lang/rfcs/pull/2256>
//! [Swift]: <https://github.com/apple/swift/blob/13d593df6f359d0cb2fc81cfaac273297c539455/lib/Syntax/README.md>
#[allow(unused)]
macro_rules! eprintln {
($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
}
mod syntax_node;
mod syntax_error;
mod parsing;

View file

@ -163,10 +163,7 @@ pub fn analysis_stats(
if let Ok(src) = src {
let original_file = src.file_id.original_file(db);
let line_index = host.analysis().file_line_index(original_file).unwrap();
let text_range = src.value.either(
|it| it.syntax_node_ptr().range(),
|it| it.syntax_node_ptr().range(),
);
let text_range = src.value.syntax_node_ptr().range();
let (start, end) = (
line_index.line_col(text_range.start()),
line_index.line_col(text_range.end()),
@ -192,12 +189,7 @@ pub fn analysis_stats(
// FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly
// But also, we should just turn the type mismatches into diagnostics and provide these
let root = db.parse_or_expand(src.file_id).unwrap();
let node = src.map(|e| {
e.either(
|p| p.to_node(&root).syntax().clone(),
|p| p.to_node(&root).syntax().clone(),
)
});
let node = src.map(|e| e.to_node(&root).syntax().clone());
let original_range = original_range(db, node.as_ref());
let path = db.file_relative_path(original_range.file_id);
let line_index =