Skip to content

Commit d0bd31c

Browse files
committed
Auto merge of rust-lang#17698 - Veykril:remove-trace, r=Veykril
internal: Remove unused trace module
2 parents c0fd28b + a335f6f commit d0bd31c

File tree

4 files changed

+46
-127
lines changed

4 files changed

+46
-127
lines changed

src/tools/rust-analyzer/crates/hir-def/src/data/adt.rs

Lines changed: 1 addition & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,10 @@ use bitflags::bitflags;
55
use cfg::CfgOptions;
66
use either::Either;
77

8-
use hir_expand::{
9-
name::{AsName, Name},
10-
InFile,
11-
};
8+
use hir_expand::name::Name;
129
use intern::{sym, Interned};
1310
use la_arena::Arena;
1411
use rustc_abi::{Align, Integer, IntegerType, ReprFlags, ReprOptions};
15-
use syntax::ast::{self, HasName, HasVisibility};
1612
use triomphe::Arc;
1713

1814
use crate::{
@@ -22,9 +18,7 @@ use crate::{
2218
AttrOwner, Field, FieldParent, FieldsShape, ItemTree, ModItem, RawVisibilityId, TreeId,
2319
},
2420
lang_item::LangItem,
25-
lower::LowerCtx,
2621
nameres::diagnostics::{DefDiagnostic, DefDiagnostics},
27-
trace::Trace,
2822
tt::{Delimiter, DelimiterKind, Leaf, Subtree, TokenTree},
2923
type_ref::TypeRef,
3024
visibility::RawVisibility,
@@ -409,64 +403,6 @@ pub enum StructKind {
409403
Unit,
410404
}
411405

412-
// FIXME This is only used for mapping back source now?
413-
pub(crate) fn lower_struct(
414-
db: &dyn DefDatabase,
415-
trace: &mut Trace<FieldData, Either<ast::TupleField, ast::RecordField>>,
416-
ast: &InFile<ast::StructKind>,
417-
krate: CrateId,
418-
item_tree: &ItemTree,
419-
parent: FieldParent,
420-
) -> StructKind {
421-
let ctx = LowerCtx::new(db, ast.file_id);
422-
423-
match &ast.value {
424-
ast::StructKind::Tuple(fl) => {
425-
let cfg_options = &db.crate_graph()[krate].cfg_options;
426-
for (i, fd) in fl.fields().enumerate() {
427-
let attrs = item_tree.attrs(db, krate, AttrOwner::make_field_indexed(parent, i));
428-
if !attrs.is_cfg_enabled(cfg_options) {
429-
continue;
430-
}
431-
432-
trace.alloc(
433-
|| Either::Left(fd.clone()),
434-
|| FieldData {
435-
name: Name::new_tuple_field(i),
436-
type_ref: Interned::new(TypeRef::from_ast_opt(&ctx, fd.ty())),
437-
visibility: RawVisibility::from_ast(db, fd.visibility(), &mut |range| {
438-
ctx.span_map().span_for_range(range).ctx
439-
}),
440-
},
441-
);
442-
}
443-
StructKind::Tuple
444-
}
445-
ast::StructKind::Record(fl) => {
446-
let cfg_options = &db.crate_graph()[krate].cfg_options;
447-
for (i, fd) in fl.fields().enumerate() {
448-
let attrs = item_tree.attrs(db, krate, AttrOwner::make_field_indexed(parent, i));
449-
if !attrs.is_cfg_enabled(cfg_options) {
450-
continue;
451-
}
452-
453-
trace.alloc(
454-
|| Either::Right(fd.clone()),
455-
|| FieldData {
456-
name: fd.name().map(|n| n.as_name()).unwrap_or_else(Name::missing),
457-
type_ref: Interned::new(TypeRef::from_ast_opt(&ctx, fd.ty())),
458-
visibility: RawVisibility::from_ast(db, fd.visibility(), &mut |range| {
459-
ctx.span_map().span_for_range(range).ctx
460-
}),
461-
},
462-
);
463-
}
464-
StructKind::Record
465-
}
466-
_ => StructKind::Unit,
467-
}
468-
}
469-
470406
fn lower_fields(
471407
db: &dyn DefDatabase,
472408
krate: CrateId,

src/tools/rust-analyzer/crates/hir-def/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ pub mod body;
4646
pub mod resolver;
4747

4848
pub mod nameres;
49-
mod trace;
5049

5150
pub mod child_by_source;
5251
pub mod src;

src/tools/rust-analyzer/crates/hir-def/src/src.rs

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ use la_arena::ArenaMap;
66
use syntax::{ast, AstNode, AstPtr};
77

88
use crate::{
9-
data::adt::lower_struct,
109
db::DefDatabase,
11-
item_tree::{FieldParent, ItemTreeNode},
12-
trace::Trace,
10+
item_tree::{AttrOwner, FieldParent, ItemTreeNode},
1311
GenericDefId, ItemTreeLoc, LocalFieldId, LocalLifetimeParamId, LocalTypeOrConstParamId, Lookup,
1412
UseId, VariantId,
1513
};
@@ -156,8 +154,49 @@ impl HasChildSource<LocalFieldId> for VariantId {
156154
)
157155
}
158156
};
159-
let mut trace = Trace::new_for_map();
160-
lower_struct(db, &mut trace, &src, container.krate, &item_tree, parent);
161-
src.with_value(trace.into_map())
157+
158+
let mut map = ArenaMap::new();
159+
match &src.value {
160+
ast::StructKind::Tuple(fl) => {
161+
let cfg_options = &db.crate_graph()[container.krate].cfg_options;
162+
let mut idx = 0;
163+
for (i, fd) in fl.fields().enumerate() {
164+
let attrs = item_tree.attrs(
165+
db,
166+
container.krate,
167+
AttrOwner::make_field_indexed(parent, i),
168+
);
169+
if !attrs.is_cfg_enabled(cfg_options) {
170+
continue;
171+
}
172+
map.insert(
173+
LocalFieldId::from_raw(la_arena::RawIdx::from(idx)),
174+
Either::Left(fd.clone()),
175+
);
176+
idx += 1;
177+
}
178+
}
179+
ast::StructKind::Record(fl) => {
180+
let cfg_options = &db.crate_graph()[container.krate].cfg_options;
181+
let mut idx = 0;
182+
for (i, fd) in fl.fields().enumerate() {
183+
let attrs = item_tree.attrs(
184+
db,
185+
container.krate,
186+
AttrOwner::make_field_indexed(parent, i),
187+
);
188+
if !attrs.is_cfg_enabled(cfg_options) {
189+
continue;
190+
}
191+
map.insert(
192+
LocalFieldId::from_raw(la_arena::RawIdx::from(idx)),
193+
Either::Right(fd.clone()),
194+
);
195+
idx += 1;
196+
}
197+
}
198+
_ => (),
199+
}
200+
InFile::new(src.file_id, map)
162201
}
163202
}

src/tools/rust-analyzer/crates/hir-def/src/trace.rs

Lines changed: 0 additions & 55 deletions
This file was deleted.

0 commit comments

Comments
 (0)