Skip to content

Commit

Permalink
Remove dead test code
Browse files Browse the repository at this point in the history
  • Loading branch information
Veykril committed Mar 14, 2024
1 parent d2f8eae commit d085ade
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 40 deletions.
8 changes: 4 additions & 4 deletions crates/hir-def/src/data/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ impl StructData {
let krate = loc.container.krate;
let item_tree = loc.id.item_tree(db);
let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into());
let cfg_options = db.crate_graph()[loc.container.krate].cfg_options.clone();
let cfg_options = db.crate_graph()[krate].cfg_options.clone();

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

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

let attrs = item_tree.attrs(db, loc.container.krate, ModItem::from(loc.id.value).into());
let attrs = item_tree.attrs(db, krate, ModItem::from(loc.id.value).into());
let mut flags = StructFlags::NO_FLAGS;
if attrs.by_key("rustc_has_incoherent_inherent_impls").exists() {
flags |= StructFlags::IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPL;
Expand Down
10 changes: 3 additions & 7 deletions crates/hir-def/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
}
};

// FIXME: The def site spans here are wrong, those should point to the name, not the whole ast node
match id {
MacroId::Macro2Id(it) => {
let loc: Macro2Loc = it.lookup(db);
Expand All @@ -310,9 +309,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
kind: kind(loc.expander, loc.id.file_id(), makro.ast_id.upcast()),
local_inner: false,
allow_internal_unsafe: loc.allow_internal_unsafe,
span: db
.span_map(loc.id.file_id())
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
span: makro.def_site,
edition: loc.edition,
}
}
Expand All @@ -328,9 +325,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
allow_internal_unsafe: loc
.flags
.contains(MacroRulesLocFlags::ALLOW_INTERNAL_UNSAFE),
span: db
.span_map(loc.id.file_id())
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
span: makro.def_site,
edition: loc.edition,
}
}
Expand All @@ -348,6 +343,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
),
local_inner: false,
allow_internal_unsafe: false,
// FIXME: This is wrong, this should point to the name
span: db
.span_map(loc.id.file_id())
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
Expand Down
3 changes: 2 additions & 1 deletion crates/hir-def/src/item_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,6 @@ pub struct MacroCall {
pub path: Interned<ModPath>,
pub ast_id: FileAstId<ast::MacroCall>,
pub expand_to: ExpandTo,
// FIXME: We need to move this out. It invalidates the item tree when typing inside the macro call.
pub call_site: Span,
}

Expand All @@ -799,6 +798,7 @@ pub struct MacroRules {
/// The name of the declared macro.
pub name: Name,
pub ast_id: FileAstId<ast::MacroRules>,
pub def_site: Span,
}

/// "Macros 2.0" macro definition.
Expand All @@ -807,6 +807,7 @@ pub struct Macro2 {
pub name: Name,
pub visibility: RawVisibilityId,
pub ast_id: FileAstId<ast::MacroDef>,
pub def_site: Span,
}

impl Use {
Expand Down
10 changes: 6 additions & 4 deletions crates/hir-def/src/item_tree/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -572,20 +572,22 @@ impl<'a> Ctx<'a> {
}

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

let res = MacroRules { name, ast_id };
let res = MacroRules { name: name.as_name(), ast_id, def_site };
Some(id(self.data().macro_rules.alloc(res)))
}

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

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

let res = Macro2 { name, ast_id, visibility };
let res = Macro2 { name: name.as_name(), ast_id, visibility, def_site };
Some(id(self.data().macro_defs.alloc(res)))
}

Expand Down
18 changes: 14 additions & 4 deletions crates/hir-def/src/item_tree/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,23 @@ impl Printer<'_> {
wln!(self, "{}!(...);", path.display(self.db.upcast()));
}
ModItem::MacroRules(it) => {
let MacroRules { name, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
let MacroRules { name, ast_id, def_site } = &self.tree[it];
let _ = writeln!(
self,
"// AstId: {:?}, Span: {}",
ast_id.erase().into_raw(),
def_site,
);
wln!(self, "macro_rules! {} {{ ... }}", name.display(self.db.upcast()));
}
ModItem::Macro2(it) => {
let Macro2 { name, visibility, ast_id } = &self.tree[it];
self.print_ast_id(ast_id.erase());
let Macro2 { name, visibility, ast_id, def_site } = &self.tree[it];
let _ = writeln!(
self,
"// AstId: {:?}, Span: {}",
ast_id.erase().into_raw(),
def_site,
);
self.print_visibility(*visibility);
wln!(self, "macro {} {{ ... }}", name.display(self.db.upcast()));
}
Expand Down
4 changes: 2 additions & 2 deletions crates/hir-def/src/item_tree/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ pub macro m2() {}
m!();
"#,
expect![[r#"
// AstId: 1
// AstId: 1, Span: 0:[email protected]#0
macro_rules! m { ... }
// AstId: 2
// AstId: 2, Span: 0:[email protected]#0
pub macro m2 { ... }
// AstId: 3, Span: 0:[email protected]#0, ExpandTo: Items
Expand Down
3 changes: 2 additions & 1 deletion crates/hir-expand/src/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,8 @@ mod tests {
let t = format!("{quoted:#?}");
expect![[r#"
SUBTREE $$ 937550:[email protected]#0 937550:[email protected]#0
IDENT hello 937550:[email protected]#0"#]].assert_eq(&t);
IDENT hello 937550:[email protected]#0"#]]
.assert_eq(&t);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion crates/ide-completion/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub fn completions(
CompletionAnalysis::String { original, expanded: Some(expanded) } => {
completions::extern_abi::complete_extern_abi(acc, ctx, expanded);
completions::format_string::format_string(acc, ctx, original, expanded);
completions::env_vars::complete_cargo_env_vars(acc, ctx,original, expanded);
completions::env_vars::complete_cargo_env_vars(acc, ctx, original, expanded);
}
CompletionAnalysis::UnexpandedAttrTT {
colon_prefix,
Expand Down
7 changes: 6 additions & 1 deletion crates/proc-macro-srv/src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ use expect_test::expect;

#[test]
fn test_derive_empty() {
assert_expand("DeriveEmpty", r#"struct S;"#, expect!["SUBTREE $$ 1 1"], expect!["SUBTREE $$ 42:[email protected]#0 42:[email protected]#0"]);
assert_expand(
"DeriveEmpty",
r#"struct S;"#,
expect!["SUBTREE $$ 1 1"],
expect!["SUBTREE $$ 42:[email protected]#0 42:[email protected]#0"],
);
}

#[test]
Expand Down
15 changes: 0 additions & 15 deletions crates/stdx/src/anymap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,6 @@ impl<'a, A: ?Sized + Downcast, V: IntoBox<A>> VacantEntry<'a, A, V> {
mod tests {
use super::*;

#[derive(Clone, Debug, PartialEq)]
struct A(i32);
#[derive(Clone, Debug, PartialEq)]
struct B(i32);
#[derive(Clone, Debug, PartialEq)]
struct C(i32);
#[derive(Clone, Debug, PartialEq)]
struct D(i32);
#[derive(Clone, Debug, PartialEq)]
struct E(i32);
#[derive(Clone, Debug, PartialEq)]
struct F(i32);
#[derive(Clone, Debug, PartialEq)]
struct J(i32);

#[test]
fn test_varieties() {
fn assert_send<T: Send>() {}
Expand Down

0 comments on commit d085ade

Please sign in to comment.