Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d085ade

Browse files
committed
Remove dead test code
1 parent d2f8eae commit d085ade

File tree

10 files changed

+40
-40
lines changed

10 files changed

+40
-40
lines changed

crates/hir-def/src/data/adt.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,9 @@ impl StructData {
191191
let krate = loc.container.krate;
192192
let item_tree = loc.id.item_tree(db);
193193
let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into());
194-
let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone();
194+
let cfg_options = db.crate_graph()[krate].cfg_options.clone();
195195

196-
let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into());
196+
let attrs = item_tree.attrs(db, krate, ModItem::from(loc.id.value).into());
197197

198198
let mut flags = StructFlags::NO_FLAGS;
199199
if attrs.by_key("rustc_has_incoherent_inherent_impls").exists() {
@@ -248,9 +248,9 @@ impl StructData {
248248
let krate = loc.container.krate;
249249
let item_tree = loc.id.item_tree(db);
250250
let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into());
251-
let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone();
251+
let cfg_options = db.crate_graph()[krate].cfg_options.clone();
252252

253-
let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into());
253+
let attrs = item_tree.attrs(db, krate, ModItem::from(loc.id.value).into());
254254
let mut flags = StructFlags::NO_FLAGS;
255255
if attrs.by_key("rustc_has_incoherent_inherent_impls").exists() {
256256
flags |= StructFlags::IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPL;

crates/hir-def/src/db.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
298298
}
299299
};
300300

301-
// FIXME: The def site spans here are wrong, those should point to the name, not the whole ast node
302301
match id {
303302
MacroId::Macro2Id(it) => {
304303
let loc: Macro2Loc = it.lookup(db);
@@ -310,9 +309,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
310309
kind: kind(loc.expander, loc.id.file_id(), makro.ast_id.upcast()),
311310
local_inner: false,
312311
allow_internal_unsafe: loc.allow_internal_unsafe,
313-
span: db
314-
.span_map(loc.id.file_id())
315-
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
312+
span: makro.def_site,
316313
edition: loc.edition,
317314
}
318315
}
@@ -328,9 +325,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
328325
allow_internal_unsafe: loc
329326
.flags
330327
.contains(MacroRulesLocFlags::ALLOW_INTERNAL_UNSAFE),
331-
span: db
332-
.span_map(loc.id.file_id())
333-
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
328+
span: makro.def_site,
334329
edition: loc.edition,
335330
}
336331
}
@@ -348,6 +343,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
348343
),
349344
local_inner: false,
350345
allow_internal_unsafe: false,
346+
// FIXME: This is wrong, this should point to the name
351347
span: db
352348
.span_map(loc.id.file_id())
353349
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),

crates/hir-def/src/item_tree.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -790,7 +790,6 @@ pub struct MacroCall {
790790
pub path: Interned<ModPath>,
791791
pub ast_id: FileAstId<ast::MacroCall>,
792792
pub expand_to: ExpandTo,
793-
// FIXME: We need to move this out. It invalidates the item tree when typing inside the macro call.
794793
pub call_site: Span,
795794
}
796795

@@ -799,6 +798,7 @@ pub struct MacroRules {
799798
/// The name of the declared macro.
800799
pub name: Name,
801800
pub ast_id: FileAstId<ast::MacroRules>,
801+
pub def_site: Span,
802802
}
803803

804804
/// "Macros 2.0" macro definition.
@@ -807,6 +807,7 @@ pub struct Macro2 {
807807
pub name: Name,
808808
pub visibility: RawVisibilityId,
809809
pub ast_id: FileAstId<ast::MacroDef>,
810+
pub def_site: Span,
810811
}
811812

812813
impl Use {

crates/hir-def/src/item_tree/lower.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -572,20 +572,22 @@ impl<'a> Ctx<'a> {
572572
}
573573

574574
fn lower_macro_rules(&mut self, m: &ast::MacroRules) -> Option<FileItemTreeId<MacroRules>> {
575-
let name = m.name().map(|it| it.as_name())?;
575+
let name = m.name()?;
576+
let def_site = self.span_map().span_for_range(name.syntax().text_range());
576577
let ast_id = self.source_ast_id_map.ast_id(m);
577578

578-
let res = MacroRules { name, ast_id };
579+
let res = MacroRules { name: name.as_name(), ast_id, def_site };
579580
Some(id(self.data().macro_rules.alloc(res)))
580581
}
581582

582583
fn lower_macro_def(&mut self, m: &ast::MacroDef) -> Option<FileItemTreeId<Macro2>> {
583-
let name = m.name().map(|it| it.as_name())?;
584+
let name = m.name()?;
585+
let def_site = self.span_map().span_for_range(name.syntax().text_range());
584586

585587
let ast_id = self.source_ast_id_map.ast_id(m);
586588
let visibility = self.lower_visibility(m);
587589

588-
let res = Macro2 { name, ast_id, visibility };
590+
let res = Macro2 { name: name.as_name(), ast_id, visibility, def_site };
589591
Some(id(self.data().macro_defs.alloc(res)))
590592
}
591593

crates/hir-def/src/item_tree/pretty.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,23 @@ impl Printer<'_> {
498498
wln!(self, "{}!(...);", path.display(self.db.upcast()));
499499
}
500500
ModItem::MacroRules(it) => {
501-
let MacroRules { name, ast_id } = &self.tree[it];
502-
self.print_ast_id(ast_id.erase());
501+
let MacroRules { name, ast_id, def_site } = &self.tree[it];
502+
let _ = writeln!(
503+
self,
504+
"// AstId: {:?}, Span: {}",
505+
ast_id.erase().into_raw(),
506+
def_site,
507+
);
503508
wln!(self, "macro_rules! {} {{ ... }}", name.display(self.db.upcast()));
504509
}
505510
ModItem::Macro2(it) => {
506-
let Macro2 { name, visibility, ast_id } = &self.tree[it];
507-
self.print_ast_id(ast_id.erase());
511+
let Macro2 { name, visibility, ast_id, def_site } = &self.tree[it];
512+
let _ = writeln!(
513+
self,
514+
"// AstId: {:?}, Span: {}",
515+
ast_id.erase().into_raw(),
516+
def_site,
517+
);
508518
self.print_visibility(*visibility);
509519
wln!(self, "macro {} {{ ... }}", name.display(self.db.upcast()));
510520
}

crates/hir-def/src/item_tree/tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ pub macro m2() {}
272272
m!();
273273
"#,
274274
expect![[r#"
275-
// AstId: 1
275+
// AstId: 1, Span: 0:[email protected]#0
276276
macro_rules! m { ... }
277277
278-
// AstId: 2
278+
// AstId: 2, Span: 0:[email protected]#0
279279
pub macro m2 { ... }
280280
281281
// AstId: 3, Span: 0:[email protected]#0, ExpandTo: Items

crates/hir-expand/src/quote.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,8 @@ mod tests {
269269
let t = format!("{quoted:#?}");
270270
expect![[r#"
271271
SUBTREE $$ 937550:[email protected]#0 937550:[email protected]#0
272-
IDENT hello 937550:[email protected]#0"#]].assert_eq(&t);
272+
IDENT hello 937550:[email protected]#0"#]]
273+
.assert_eq(&t);
273274
}
274275

275276
#[test]

crates/ide-completion/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ pub fn completions(
207207
CompletionAnalysis::String { original, expanded: Some(expanded) } => {
208208
completions::extern_abi::complete_extern_abi(acc, ctx, expanded);
209209
completions::format_string::format_string(acc, ctx, original, expanded);
210-
completions::env_vars::complete_cargo_env_vars(acc, ctx,original, expanded);
210+
completions::env_vars::complete_cargo_env_vars(acc, ctx, original, expanded);
211211
}
212212
CompletionAnalysis::UnexpandedAttrTT {
213213
colon_prefix,

crates/proc-macro-srv/src/tests/mod.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ use expect_test::expect;
88

99
#[test]
1010
fn test_derive_empty() {
11-
assert_expand("DeriveEmpty", r#"struct S;"#, expect!["SUBTREE $$ 1 1"], expect!["SUBTREE $$ 42:[email protected]#0 42:[email protected]#0"]);
11+
assert_expand(
12+
"DeriveEmpty",
13+
r#"struct S;"#,
14+
expect!["SUBTREE $$ 1 1"],
15+
expect!["SUBTREE $$ 42:[email protected]#0 42:[email protected]#0"],
16+
);
1217
}
1318

1419
#[test]

crates/stdx/src/anymap.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -194,21 +194,6 @@ impl<'a, A: ?Sized + Downcast, V: IntoBox<A>> VacantEntry<'a, A, V> {
194194
mod tests {
195195
use super::*;
196196

197-
#[derive(Clone, Debug, PartialEq)]
198-
struct A(i32);
199-
#[derive(Clone, Debug, PartialEq)]
200-
struct B(i32);
201-
#[derive(Clone, Debug, PartialEq)]
202-
struct C(i32);
203-
#[derive(Clone, Debug, PartialEq)]
204-
struct D(i32);
205-
#[derive(Clone, Debug, PartialEq)]
206-
struct E(i32);
207-
#[derive(Clone, Debug, PartialEq)]
208-
struct F(i32);
209-
#[derive(Clone, Debug, PartialEq)]
210-
struct J(i32);
211-
212197
#[test]
213198
fn test_varieties() {
214199
fn assert_send<T: Send>() {}

0 commit comments

Comments
 (0)