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

View file

@ -9,6 +9,8 @@ use drop_bomb::DropBomb;
use either::Either; use either::Either;
use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId}; use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId};
use ra_arena::{map::ArenaMap, Arena}; use ra_arena::{map::ArenaMap, Arena};
use ra_cfg::CfgOptions;
use ra_db::CrateId;
use ra_prof::profile; use ra_prof::profile;
use ra_syntax::{ast, AstNode, AstPtr}; use ra_syntax::{ast, AstNode, AstPtr};
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
@ -24,8 +26,6 @@ use crate::{
src::HasSource, src::HasSource,
AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId, 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 /// 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. /// avoid cyclic queries in crate def map during enum processing.
@ -187,7 +187,7 @@ pub struct Body {
pub item_scope: ItemScope, 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 ExprSource = InFile<ExprPtr>;
pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>; 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> { 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() 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 { 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 src = self.expander.to_source(ptr);
let id = self.make_expr(expr, Ok(src.clone())); let id = self.make_expr(expr, Ok(src.clone()));
self.source_map.expr_map.insert(src, id); self.source_map.expr_map.insert(src, id);
@ -281,7 +280,7 @@ impl ExprCollector<'_> {
ast::Expr::ParenExpr(e) => { ast::Expr::ParenExpr(e) => {
let inner = self.collect_expr_opt(e.expr()); let inner = self.collect_expr_opt(e.expr());
// make the paren expr point to the inner expression as well // 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); self.source_map.expr_map.insert(src, inner);
inner inner
} }

View file

@ -89,9 +89,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
let (_, source_map) = db.body_with_source_map(self.func.into()); let (_, source_map) = db.body_with_source_map(self.func.into());
if let Ok(source_ptr) = source_map.expr_syntax(id) { 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()); let root = source_ptr.file_syntax(db.upcast());
if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { if let ast::Expr::RecordLit(record_lit) = &source_ptr.value.to_node(&root) {
if let Some(field_list) = record_lit.record_field_list() { if let Some(field_list) = record_lit.record_field_list() {
let variant_data = variant_data(db.upcast(), variant_def); let variant_data = variant_data(db.upcast(), variant_def);
let missed_fields = missed_fields let missed_fields = missed_fields
@ -107,7 +106,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
} }
} }
} }
}
fn create_record_pattern_missing_fields_diagnostic( fn create_record_pattern_missing_fields_diagnostic(
&mut self, &mut self,
@ -205,9 +203,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
} }
if let Ok(source_ptr) = source_map.expr_syntax(id) { 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()); let root = source_ptr.file_syntax(db.upcast());
if let ast::Expr::MatchExpr(match_expr) = expr.to_node(&root) { if let ast::Expr::MatchExpr(match_expr) = &source_ptr.value.to_node(&root) {
if let (Some(match_expr), Some(arms)) = if let (Some(match_expr), Some(arms)) =
(match_expr.expr(), match_expr.match_arm_list()) (match_expr.expr(), match_expr.match_arm_list())
{ {
@ -220,7 +217,6 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
} }
} }
} }
}
fn validate_results_in_tail_expr(&mut self, body_id: ExprId, id: ExprId, db: &dyn HirDatabase) { fn validate_results_in_tail_expr(&mut self, body_id: ExprId, id: ExprId, db: &dyn HirDatabase) {
// the mismatch will be on the whole block currently // the mismatch will be on the whole block currently
@ -247,9 +243,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
let (_, source_map) = db.body_with_source_map(self.func.into()); let (_, source_map) = db.body_with_source_map(self.func.into());
if let Ok(source_ptr) = source_map.expr_syntax(id) { if let Ok(source_ptr) = source_map.expr_syntax(id) {
if let Some(expr) = source_ptr.value.left() { self.sink
self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr }); .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() { for (expr, ty) in inference_result.type_of_expr.iter() {
let syntax_ptr = match body_source_map.expr_syntax(expr) { let syntax_ptr = match body_source_map.expr_syntax(expr) {
Ok(sp) => { Ok(sp) => sp.map(|ast| ast.syntax_node_ptr()),
sp.map(|ast| ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()))
}
Err(SyntheticSyntax) => continue, Err(SyntheticSyntax) => continue,
}; };
types.push((syntax_ptr.clone(), ty)); types.push((syntax_ptr.clone(), ty));

View file

@ -189,8 +189,6 @@ impl ast::StructDef {
impl ast::RecordField { impl ast::RecordField {
pub fn for_field_name(field_name: &ast::NameRef) -> Option<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 = let candidate =
field_name.syntax().parent().and_then(ast::RecordField::cast).or_else(|| { field_name.syntax().parent().and_then(ast::RecordField::cast).or_else(|| {
field_name.syntax().ancestors().nth(4).and_then(ast::RecordField::cast) 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> //! [RFC]: <https://github.com/rust-lang/rfcs/pull/2256>
//! [Swift]: <https://github.com/apple/swift/blob/13d593df6f359d0cb2fc81cfaac273297c539455/lib/Syntax/README.md> //! [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_node;
mod syntax_error; mod syntax_error;
mod parsing; mod parsing;

View file

@ -163,10 +163,7 @@ pub fn analysis_stats(
if let Ok(src) = src { if let Ok(src) = src {
let original_file = src.file_id.original_file(db); let original_file = src.file_id.original_file(db);
let line_index = host.analysis().file_line_index(original_file).unwrap(); let line_index = host.analysis().file_line_index(original_file).unwrap();
let text_range = src.value.either( let text_range = src.value.syntax_node_ptr().range();
|it| it.syntax_node_ptr().range(),
|it| it.syntax_node_ptr().range(),
);
let (start, end) = ( let (start, end) = (
line_index.line_col(text_range.start()), line_index.line_col(text_range.start()),
line_index.line_col(text_range.end()), 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 // 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 // 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 root = db.parse_or_expand(src.file_id).unwrap();
let node = src.map(|e| { let node = src.map(|e| e.to_node(&root).syntax().clone());
e.either(
|p| p.to_node(&root).syntax().clone(),
|p| p.to_node(&root).syntax().clone(),
)
});
let original_range = original_range(db, node.as_ref()); let original_range = original_range(db, node.as_ref());
let path = db.file_relative_path(original_range.file_id); let path = db.file_relative_path(original_range.file_id);
let line_index = let line_index =