Skip to content

Commit 0aece75

Browse files
committed
Remove dead code
1 parent 7a39bc3 commit 0aece75

File tree

8 files changed

+40
-55
lines changed

8 files changed

+40
-55
lines changed

crates/ra_hir/src/source_analyzer.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,7 @@ fn scope_for_offset(
317317
if source.file_id != offset.file_id {
318318
return None;
319319
}
320-
let syntax_node_ptr =
321-
source.value.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr());
320+
let syntax_node_ptr = source.value.syntax_node_ptr();
322321
Some((syntax_node_ptr, scope))
323322
})
324323
// find containing scope
@@ -397,8 +396,7 @@ fn adjust(
397396
if source.file_id != file_id {
398397
return None;
399398
}
400-
let syntax_node_ptr =
401-
source.value.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr());
399+
let syntax_node_ptr = source.value.syntax_node_ptr();
402400
Some((syntax_node_ptr, scope))
403401
})
404402
.map(|(ptr, scope)| (ptr.range(), scope))

crates/ra_hir_def/src/body.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ use drop_bomb::DropBomb;
99
use either::Either;
1010
use hir_expand::{ast_id_map::AstIdMap, hygiene::Hygiene, AstId, HirFileId, InFile, MacroDefId};
1111
use ra_arena::{map::ArenaMap, Arena};
12+
use ra_cfg::CfgOptions;
13+
use ra_db::CrateId;
1214
use ra_prof::profile;
1315
use ra_syntax::{ast, AstNode, AstPtr};
1416
use rustc_hash::FxHashMap;
@@ -24,8 +26,6 @@ use crate::{
2426
src::HasSource,
2527
AsMacroCall, DefWithBodyId, HasModule, Lookup, ModuleId,
2628
};
27-
use ra_cfg::CfgOptions;
28-
use ra_db::CrateId;
2929

3030
/// A subser of Exander that only deals with cfg attributes. We only need it to
3131
/// avoid cyclic queries in crate def map during enum processing.
@@ -187,7 +187,7 @@ pub struct Body {
187187
pub item_scope: ItemScope,
188188
}
189189

190-
pub type ExprPtr = Either<AstPtr<ast::Expr>, AstPtr<ast::RecordField>>;
190+
pub type ExprPtr = AstPtr<ast::Expr>;
191191
pub type ExprSource = InFile<ExprPtr>;
192192

193193
pub type PatPtr = Either<AstPtr<ast::Pat>, AstPtr<ast::SelfParam>>;
@@ -285,7 +285,7 @@ impl BodySourceMap {
285285
}
286286

287287
pub fn node_expr(&self, node: InFile<&ast::Expr>) -> Option<ExprId> {
288-
let src = node.map(|it| Either::Left(AstPtr::new(it)));
288+
let src = node.map(|it| AstPtr::new(it));
289289
self.expr_map.get(&src).cloned()
290290
}
291291

crates/ra_hir_def/src/body/lower.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ impl ExprCollector<'_> {
101101
}
102102

103103
fn alloc_expr(&mut self, expr: Expr, ptr: AstPtr<ast::Expr>) -> ExprId {
104-
let ptr = Either::Left(ptr);
105104
let src = self.expander.to_source(ptr);
106105
let id = self.make_expr(expr, Ok(src.clone()));
107106
self.source_map.expr_map.insert(src, id);
@@ -281,7 +280,7 @@ impl ExprCollector<'_> {
281280
ast::Expr::ParenExpr(e) => {
282281
let inner = self.collect_expr_opt(e.expr());
283282
// make the paren expr point to the inner expression as well
284-
let src = self.expander.to_source(Either::Left(syntax_ptr));
283+
let src = self.expander.to_source(syntax_ptr);
285284
self.source_map.expr_map.insert(src, inner);
286285
inner
287286
}

crates/ra_hir_ty/src/expr.rs

Lines changed: 25 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -89,21 +89,19 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
8989
let (_, source_map) = db.body_with_source_map(self.func.into());
9090

9191
if let Ok(source_ptr) = source_map.expr_syntax(id) {
92-
if let Some(expr) = source_ptr.value.as_ref().left() {
93-
let root = source_ptr.file_syntax(db.upcast());
94-
if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) {
95-
if let Some(field_list) = record_lit.record_field_list() {
96-
let variant_data = variant_data(db.upcast(), variant_def);
97-
let missed_fields = missed_fields
98-
.into_iter()
99-
.map(|idx| variant_data.fields()[idx].name.clone())
100-
.collect();
101-
self.sink.push(MissingFields {
102-
file: source_ptr.file_id,
103-
field_list: AstPtr::new(&field_list),
104-
missed_fields,
105-
})
106-
}
92+
let root = source_ptr.file_syntax(db.upcast());
93+
if let ast::Expr::RecordLit(record_lit) = &source_ptr.value.to_node(&root) {
94+
if let Some(field_list) = record_lit.record_field_list() {
95+
let variant_data = variant_data(db.upcast(), variant_def);
96+
let missed_fields = missed_fields
97+
.into_iter()
98+
.map(|idx| variant_data.fields()[idx].name.clone())
99+
.collect();
100+
self.sink.push(MissingFields {
101+
file: source_ptr.file_id,
102+
field_list: AstPtr::new(&field_list),
103+
missed_fields,
104+
})
107105
}
108106
}
109107
}
@@ -205,18 +203,16 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
205203
}
206204

207205
if let Ok(source_ptr) = source_map.expr_syntax(id) {
208-
if let Some(expr) = source_ptr.value.as_ref().left() {
209-
let root = source_ptr.file_syntax(db.upcast());
210-
if let ast::Expr::MatchExpr(match_expr) = expr.to_node(&root) {
211-
if let (Some(match_expr), Some(arms)) =
212-
(match_expr.expr(), match_expr.match_arm_list())
213-
{
214-
self.sink.push(MissingMatchArms {
215-
file: source_ptr.file_id,
216-
match_expr: AstPtr::new(&match_expr),
217-
arms: AstPtr::new(&arms),
218-
})
219-
}
206+
let root = source_ptr.file_syntax(db.upcast());
207+
if let ast::Expr::MatchExpr(match_expr) = &source_ptr.value.to_node(&root) {
208+
if let (Some(match_expr), Some(arms)) =
209+
(match_expr.expr(), match_expr.match_arm_list())
210+
{
211+
self.sink.push(MissingMatchArms {
212+
file: source_ptr.file_id,
213+
match_expr: AstPtr::new(&match_expr),
214+
arms: AstPtr::new(&arms),
215+
})
220216
}
221217
}
222218
}
@@ -247,9 +243,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> {
247243
let (_, source_map) = db.body_with_source_map(self.func.into());
248244

249245
if let Ok(source_ptr) = source_map.expr_syntax(id) {
250-
if let Some(expr) = source_ptr.value.left() {
251-
self.sink.push(MissingOkInTailExpr { file: source_ptr.file_id, expr });
252-
}
246+
self.sink
247+
.push(MissingOkInTailExpr { file: source_ptr.file_id, expr: source_ptr.value });
253248
}
254249
}
255250
}

crates/ra_hir_ty/src/tests.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ fn infer_with_mismatches(content: &str, include_mismatches: bool) -> String {
8282

8383
for (expr, ty) in inference_result.type_of_expr.iter() {
8484
let syntax_ptr = match body_source_map.expr_syntax(expr) {
85-
Ok(sp) => {
86-
sp.map(|ast| ast.either(|it| it.syntax_node_ptr(), |it| it.syntax_node_ptr()))
87-
}
85+
Ok(sp) => sp.map(|ast| ast.syntax_node_ptr()),
8886
Err(SyntheticSyntax) => continue,
8987
};
9088
types.push((syntax_ptr.clone(), ty));

crates/ra_syntax/src/ast/extensions.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,6 @@ impl ast::StructDef {
189189

190190
impl ast::RecordField {
191191
pub fn for_field_name(field_name: &ast::NameRef) -> Option<ast::RecordField> {
192-
eprintln!("field_name = {}", field_name);
193-
dbg!(field_name.syntax().ancestors().nth(6));
194192
let candidate =
195193
field_name.syntax().parent().and_then(ast::RecordField::cast).or_else(|| {
196194
field_name.syntax().ancestors().nth(4).and_then(ast::RecordField::cast)

crates/ra_syntax/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
//! [RFC]: <https://github.com/rust-lang/rfcs/pull/2256>
2020
//! [Swift]: <https://github.com/apple/swift/blob/13d593df6f359d0cb2fc81cfaac273297c539455/lib/Syntax/README.md>
2121
22+
#[allow(unused)]
23+
macro_rules! eprintln {
24+
($($tt:tt)*) => { stdx::eprintln!($($tt)*) };
25+
}
26+
2227
mod syntax_node;
2328
mod syntax_error;
2429
mod parsing;

crates/rust-analyzer/src/cli/analysis_stats.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,7 @@ pub fn analysis_stats(
163163
if let Ok(src) = src {
164164
let original_file = src.file_id.original_file(db);
165165
let line_index = host.analysis().file_line_index(original_file).unwrap();
166-
let text_range = src.value.either(
167-
|it| it.syntax_node_ptr().range(),
168-
|it| it.syntax_node_ptr().range(),
169-
);
166+
let text_range = src.value.syntax_node_ptr().range();
170167
let (start, end) = (
171168
line_index.line_col(text_range.start()),
172169
line_index.line_col(text_range.end()),
@@ -192,12 +189,7 @@ pub fn analysis_stats(
192189
// FIXME: it might be nice to have a function (on Analysis?) that goes from Source<T> -> (LineCol, LineCol) directly
193190
// But also, we should just turn the type mismatches into diagnostics and provide these
194191
let root = db.parse_or_expand(src.file_id).unwrap();
195-
let node = src.map(|e| {
196-
e.either(
197-
|p| p.to_node(&root).syntax().clone(),
198-
|p| p.to_node(&root).syntax().clone(),
199-
)
200-
});
192+
let node = src.map(|e| e.to_node(&root).syntax().clone());
201193
let original_range = original_range(db, node.as_ref());
202194
let path = db.file_relative_path(original_range.file_id);
203195
let line_index =

0 commit comments

Comments
 (0)