Remove dead test code

This commit is contained in:
Lukas Wirth 2024-03-14 15:48:46 +01:00
parent d2f8eae2ec
commit d085ade631
10 changed files with 40 additions and 40 deletions

View File

@ -191,9 +191,9 @@ pub(crate) fn struct_data_with_diagnostics_query(
let krate = loc.container.krate; let krate = loc.container.krate;
let item_tree = loc.id.item_tree(db); let item_tree = loc.id.item_tree(db);
let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); 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; let mut flags = StructFlags::NO_FLAGS;
if attrs.by_key("rustc_has_incoherent_inherent_impls").exists() { if attrs.by_key("rustc_has_incoherent_inherent_impls").exists() {
@ -248,9 +248,9 @@ pub(crate) fn union_data_with_diagnostics_query(
let krate = loc.container.krate; let krate = loc.container.krate;
let item_tree = loc.id.item_tree(db); let item_tree = loc.id.item_tree(db);
let repr = repr_from_value(db, krate, &item_tree, ModItem::from(loc.id.value).into()); 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; let mut flags = StructFlags::NO_FLAGS;
if attrs.by_key("rustc_has_incoherent_inherent_impls").exists() { if attrs.by_key("rustc_has_incoherent_inherent_impls").exists() {
flags |= StructFlags::IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPL; flags |= StructFlags::IS_RUSTC_HAS_INCOHERENT_INHERENT_IMPL;

View File

@ -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 { match id {
MacroId::Macro2Id(it) => { MacroId::Macro2Id(it) => {
let loc: Macro2Loc = it.lookup(db); let loc: Macro2Loc = it.lookup(db);
@ -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()), kind: kind(loc.expander, loc.id.file_id(), makro.ast_id.upcast()),
local_inner: false, local_inner: false,
allow_internal_unsafe: loc.allow_internal_unsafe, allow_internal_unsafe: loc.allow_internal_unsafe,
span: db span: makro.def_site,
.span_map(loc.id.file_id())
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
edition: loc.edition, edition: loc.edition,
} }
} }
@ -328,9 +325,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
allow_internal_unsafe: loc allow_internal_unsafe: loc
.flags .flags
.contains(MacroRulesLocFlags::ALLOW_INTERNAL_UNSAFE), .contains(MacroRulesLocFlags::ALLOW_INTERNAL_UNSAFE),
span: db span: makro.def_site,
.span_map(loc.id.file_id())
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),
edition: loc.edition, edition: loc.edition,
} }
} }
@ -348,6 +343,7 @@ fn macro_def(db: &dyn DefDatabase, id: MacroId) -> MacroDefId {
), ),
local_inner: false, local_inner: false,
allow_internal_unsafe: false, allow_internal_unsafe: false,
// FIXME: This is wrong, this should point to the name
span: db span: db
.span_map(loc.id.file_id()) .span_map(loc.id.file_id())
.span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()), .span_for_range(db.ast_id_map(loc.id.file_id()).get(makro.ast_id).text_range()),

View File

@ -790,7 +790,6 @@ pub struct MacroCall {
pub path: Interned<ModPath>, pub path: Interned<ModPath>,
pub ast_id: FileAstId<ast::MacroCall>, pub ast_id: FileAstId<ast::MacroCall>,
pub expand_to: ExpandTo, 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, pub call_site: Span,
} }
@ -799,6 +798,7 @@ pub struct MacroRules {
/// The name of the declared macro. /// The name of the declared macro.
pub name: Name, pub name: Name,
pub ast_id: FileAstId<ast::MacroRules>, pub ast_id: FileAstId<ast::MacroRules>,
pub def_site: Span,
} }
/// "Macros 2.0" macro definition. /// "Macros 2.0" macro definition.
@ -807,6 +807,7 @@ pub struct Macro2 {
pub name: Name, pub name: Name,
pub visibility: RawVisibilityId, pub visibility: RawVisibilityId,
pub ast_id: FileAstId<ast::MacroDef>, pub ast_id: FileAstId<ast::MacroDef>,
pub def_site: Span,
} }
impl Use { impl Use {

View File

@ -572,20 +572,22 @@ fn lower_macro_call(&mut self, m: &ast::MacroCall) -> Option<FileItemTreeId<Macr
} }
fn lower_macro_rules(&mut self, m: &ast::MacroRules) -> Option<FileItemTreeId<MacroRules>> { 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 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))) Some(id(self.data().macro_rules.alloc(res)))
} }
fn lower_macro_def(&mut self, m: &ast::MacroDef) -> Option<FileItemTreeId<Macro2>> { 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 ast_id = self.source_ast_id_map.ast_id(m);
let visibility = self.lower_visibility(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))) Some(id(self.data().macro_defs.alloc(res)))
} }

View File

@ -498,13 +498,23 @@ fn print_mod_item(&mut self, item: ModItem) {
wln!(self, "{}!(...);", path.display(self.db.upcast())); wln!(self, "{}!(...);", path.display(self.db.upcast()));
} }
ModItem::MacroRules(it) => { ModItem::MacroRules(it) => {
let MacroRules { name, ast_id } = &self.tree[it]; let MacroRules { name, ast_id, def_site } = &self.tree[it];
self.print_ast_id(ast_id.erase()); let _ = writeln!(
self,
"// AstId: {:?}, Span: {}",
ast_id.erase().into_raw(),
def_site,
);
wln!(self, "macro_rules! {} {{ ... }}", name.display(self.db.upcast())); wln!(self, "macro_rules! {} {{ ... }}", name.display(self.db.upcast()));
} }
ModItem::Macro2(it) => { ModItem::Macro2(it) => {
let Macro2 { name, visibility, ast_id } = &self.tree[it]; let Macro2 { name, visibility, ast_id, def_site } = &self.tree[it];
self.print_ast_id(ast_id.erase()); let _ = writeln!(
self,
"// AstId: {:?}, Span: {}",
ast_id.erase().into_raw(),
def_site,
);
self.print_visibility(*visibility); self.print_visibility(*visibility);
wln!(self, "macro {} {{ ... }}", name.display(self.db.upcast())); wln!(self, "macro {} {{ ... }}", name.display(self.db.upcast()));
} }

View File

@ -272,10 +272,10 @@ macro_rules! m {
m!(); m!();
"#, "#,
expect![[r#" expect![[r#"
// AstId: 1 // AstId: 1, Span: 0:1@13..14#0
macro_rules! m { ... } macro_rules! m { ... }
// AstId: 2 // AstId: 2, Span: 0:2@10..12#0
pub macro m2 { ... } pub macro m2 { ... }
// AstId: 3, Span: 0:3@0..1#0, ExpandTo: Items // AstId: 3, Span: 0:3@0..1#0, ExpandTo: Items

View File

@ -269,7 +269,8 @@ fn test_quote_hash_token_tree() {
let t = format!("{quoted:#?}"); let t = format!("{quoted:#?}");
expect![[r#" expect![[r#"
SUBTREE $$ 937550:0@0..0#0 937550:0@0..0#0 SUBTREE $$ 937550:0@0..0#0 937550:0@0..0#0
IDENT hello 937550:0@0..0#0"#]].assert_eq(&t); IDENT hello 937550:0@0..0#0"#]]
.assert_eq(&t);
} }
#[test] #[test]

View File

@ -207,7 +207,7 @@ pub fn completions(
CompletionAnalysis::String { original, expanded: Some(expanded) } => { CompletionAnalysis::String { original, expanded: Some(expanded) } => {
completions::extern_abi::complete_extern_abi(acc, ctx, expanded); completions::extern_abi::complete_extern_abi(acc, ctx, expanded);
completions::format_string::format_string(acc, ctx, original, 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 { CompletionAnalysis::UnexpandedAttrTT {
colon_prefix, colon_prefix,

View File

@ -8,7 +8,12 @@
#[test] #[test]
fn test_derive_empty() { fn test_derive_empty() {
assert_expand("DeriveEmpty", r#"struct S;"#, expect!["SUBTREE $$ 1 1"], expect!["SUBTREE $$ 42:2@0..100#0 42:2@0..100#0"]); assert_expand(
"DeriveEmpty",
r#"struct S;"#,
expect!["SUBTREE $$ 1 1"],
expect!["SUBTREE $$ 42:2@0..100#0 42:2@0..100#0"],
);
} }
#[test] #[test]

View File

@ -194,21 +194,6 @@ pub fn insert(self, value: V) -> &'a mut V {
mod tests { mod tests {
use super::*; 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] #[test]
fn test_varieties() { fn test_varieties() {
fn assert_send<T: Send>() {} fn assert_send<T: Send>() {}