mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-14 14:13:58 +00:00
Thinner DefDiagnostics
This commit is contained in:
parent
2d72ec71ec
commit
1669344b2a
6 changed files with 39 additions and 29 deletions
|
@ -19,7 +19,7 @@ use crate::{
|
||||||
macro_call_as_call_id,
|
macro_call_as_call_id,
|
||||||
nameres::{
|
nameres::{
|
||||||
attr_resolution::ResolvedAttr,
|
attr_resolution::ResolvedAttr,
|
||||||
diagnostics::DefDiagnostic,
|
diagnostics::{DefDiagnostic, DefDiagnostics},
|
||||||
proc_macro::{parse_macro_name_and_helper_attrs, ProcMacroKind},
|
proc_macro::{parse_macro_name_and_helper_attrs, ProcMacroKind},
|
||||||
DefMap, MacroSubNs,
|
DefMap, MacroSubNs,
|
||||||
},
|
},
|
||||||
|
@ -240,7 +240,7 @@ impl TraitData {
|
||||||
pub(crate) fn trait_data_with_diagnostics_query(
|
pub(crate) fn trait_data_with_diagnostics_query(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
tr: TraitId,
|
tr: TraitId,
|
||||||
) -> (Arc<TraitData>, Arc<[DefDiagnostic]>) {
|
) -> (Arc<TraitData>, DefDiagnostics) {
|
||||||
let tr_loc @ ItemLoc { container: module_id, id: tree_id } = tr.lookup(db);
|
let tr_loc @ ItemLoc { container: module_id, id: tree_id } = tr.lookup(db);
|
||||||
let item_tree = tree_id.item_tree(db);
|
let item_tree = tree_id.item_tree(db);
|
||||||
let tr_def = &item_tree[tree_id.value];
|
let tr_def = &item_tree[tree_id.value];
|
||||||
|
@ -274,7 +274,7 @@ impl TraitData {
|
||||||
rustc_has_incoherent_inherent_impls,
|
rustc_has_incoherent_inherent_impls,
|
||||||
fundamental,
|
fundamental,
|
||||||
}),
|
}),
|
||||||
diagnostics.into(),
|
DefDiagnostics::new(diagnostics),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -340,7 +340,7 @@ impl ImplData {
|
||||||
pub(crate) fn impl_data_with_diagnostics_query(
|
pub(crate) fn impl_data_with_diagnostics_query(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
id: ImplId,
|
id: ImplId,
|
||||||
) -> (Arc<ImplData>, Arc<[DefDiagnostic]>) {
|
) -> (Arc<ImplData>, DefDiagnostics) {
|
||||||
let _p = profile::span("impl_data_with_diagnostics_query");
|
let _p = profile::span("impl_data_with_diagnostics_query");
|
||||||
let ItemLoc { container: module_id, id: tree_id } = id.lookup(db);
|
let ItemLoc { container: module_id, id: tree_id } = id.lookup(db);
|
||||||
|
|
||||||
|
@ -367,7 +367,7 @@ impl ImplData {
|
||||||
is_unsafe,
|
is_unsafe,
|
||||||
attribute_calls,
|
attribute_calls,
|
||||||
}),
|
}),
|
||||||
diagnostics.into(),
|
DefDiagnostics::new(diagnostics),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ use crate::{
|
||||||
item_tree::{AttrOwner, Field, FieldAstId, Fields, ItemTree, ModItem, RawVisibilityId},
|
item_tree::{AttrOwner, Field, FieldAstId, Fields, ItemTree, ModItem, RawVisibilityId},
|
||||||
lang_item::LangItem,
|
lang_item::LangItem,
|
||||||
lower::LowerCtx,
|
lower::LowerCtx,
|
||||||
nameres::diagnostics::DefDiagnostic,
|
nameres::diagnostics::{DefDiagnostic, DefDiagnostics},
|
||||||
src::HasChildSource,
|
src::HasChildSource,
|
||||||
src::HasSource,
|
src::HasSource,
|
||||||
trace::Trace,
|
trace::Trace,
|
||||||
|
@ -187,7 +187,7 @@ impl StructData {
|
||||||
pub(crate) fn struct_data_with_diagnostics_query(
|
pub(crate) fn struct_data_with_diagnostics_query(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
id: StructId,
|
id: StructId,
|
||||||
) -> (Arc<StructData>, Arc<[DefDiagnostic]>) {
|
) -> (Arc<StructData>, DefDiagnostics) {
|
||||||
let loc = id.lookup(db);
|
let loc = id.lookup(db);
|
||||||
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);
|
||||||
|
@ -232,7 +232,7 @@ impl StructData {
|
||||||
visibility: item_tree[strukt.visibility].clone(),
|
visibility: item_tree[strukt.visibility].clone(),
|
||||||
flags,
|
flags,
|
||||||
}),
|
}),
|
||||||
diagnostics.into(),
|
DefDiagnostics::new(diagnostics),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ impl StructData {
|
||||||
pub(crate) fn union_data_with_diagnostics_query(
|
pub(crate) fn union_data_with_diagnostics_query(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
id: UnionId,
|
id: UnionId,
|
||||||
) -> (Arc<StructData>, Arc<[DefDiagnostic]>) {
|
) -> (Arc<StructData>, DefDiagnostics) {
|
||||||
let loc = id.lookup(db);
|
let loc = id.lookup(db);
|
||||||
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);
|
||||||
|
@ -278,7 +278,7 @@ impl StructData {
|
||||||
visibility: item_tree[union.visibility].clone(),
|
visibility: item_tree[union.visibility].clone(),
|
||||||
flags,
|
flags,
|
||||||
}),
|
}),
|
||||||
diagnostics.into(),
|
DefDiagnostics::new(diagnostics),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -332,14 +332,14 @@ impl EnumVariantData {
|
||||||
pub(crate) fn enum_variant_data_with_diagnostics_query(
|
pub(crate) fn enum_variant_data_with_diagnostics_query(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
e: EnumVariantId,
|
e: EnumVariantId,
|
||||||
) -> (Arc<EnumVariantData>, Option<Arc<Box<[DefDiagnostic]>>>) {
|
) -> (Arc<EnumVariantData>, DefDiagnostics) {
|
||||||
let loc = e.lookup(db);
|
let loc = e.lookup(db);
|
||||||
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 cfg_options = db.crate_graph()[krate].cfg_options.clone();
|
let cfg_options = db.crate_graph()[krate].cfg_options.clone();
|
||||||
let variant = &item_tree[loc.id.value];
|
let variant = &item_tree[loc.id.value];
|
||||||
|
|
||||||
let (var_data, field_diagnostics) = lower_fields(
|
let (var_data, diagnostics) = lower_fields(
|
||||||
db,
|
db,
|
||||||
krate,
|
krate,
|
||||||
loc.id.file_id(),
|
loc.id.file_id(),
|
||||||
|
@ -355,11 +355,7 @@ impl EnumVariantData {
|
||||||
name: variant.name.clone(),
|
name: variant.name.clone(),
|
||||||
variant_data: Arc::new(var_data),
|
variant_data: Arc::new(var_data),
|
||||||
}),
|
}),
|
||||||
if field_diagnostics.is_empty() {
|
DefDiagnostics::new(diagnostics),
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(Arc::new(field_diagnostics.into_boxed_slice()))
|
|
||||||
},
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ use crate::{
|
||||||
import_map::ImportMap,
|
import_map::ImportMap,
|
||||||
item_tree::{AttrOwner, ItemTree},
|
item_tree::{AttrOwner, ItemTree},
|
||||||
lang_item::{self, LangItem, LangItemTarget, LangItems},
|
lang_item::{self, LangItem, LangItemTarget, LangItems},
|
||||||
nameres::{diagnostics::DefDiagnostic, DefMap},
|
nameres::{diagnostics::DefDiagnostics, DefMap},
|
||||||
visibility::{self, Visibility},
|
visibility::{self, Visibility},
|
||||||
AttrDefId, BlockId, BlockLoc, ConstBlockId, ConstBlockLoc, ConstId, ConstLoc, DefWithBodyId,
|
AttrDefId, BlockId, BlockLoc, ConstBlockId, ConstBlockLoc, ConstId, ConstLoc, DefWithBodyId,
|
||||||
EnumId, EnumLoc, EnumVariantId, EnumVariantLoc, ExternBlockId, ExternBlockLoc, ExternCrateId,
|
EnumId, EnumLoc, EnumVariantId, EnumVariantLoc, ExternBlockId, ExternBlockLoc, ExternCrateId,
|
||||||
|
@ -121,14 +121,13 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
|
||||||
fn struct_data(&self, id: StructId) -> Arc<StructData>;
|
fn struct_data(&self, id: StructId) -> Arc<StructData>;
|
||||||
|
|
||||||
#[salsa::invoke(StructData::struct_data_with_diagnostics_query)]
|
#[salsa::invoke(StructData::struct_data_with_diagnostics_query)]
|
||||||
fn struct_data_with_diagnostics(&self, id: StructId)
|
fn struct_data_with_diagnostics(&self, id: StructId) -> (Arc<StructData>, DefDiagnostics);
|
||||||
-> (Arc<StructData>, Arc<[DefDiagnostic]>);
|
|
||||||
|
|
||||||
#[salsa::invoke(StructData::union_data_query)]
|
#[salsa::invoke(StructData::union_data_query)]
|
||||||
fn union_data(&self, id: UnionId) -> Arc<StructData>;
|
fn union_data(&self, id: UnionId) -> Arc<StructData>;
|
||||||
|
|
||||||
#[salsa::invoke(StructData::union_data_with_diagnostics_query)]
|
#[salsa::invoke(StructData::union_data_with_diagnostics_query)]
|
||||||
fn union_data_with_diagnostics(&self, id: UnionId) -> (Arc<StructData>, Arc<[DefDiagnostic]>);
|
fn union_data_with_diagnostics(&self, id: UnionId) -> (Arc<StructData>, DefDiagnostics);
|
||||||
|
|
||||||
#[salsa::invoke(EnumData::enum_data_query)]
|
#[salsa::invoke(EnumData::enum_data_query)]
|
||||||
fn enum_data(&self, e: EnumId) -> Arc<EnumData>;
|
fn enum_data(&self, e: EnumId) -> Arc<EnumData>;
|
||||||
|
@ -140,19 +139,19 @@ pub trait DefDatabase: InternDatabase + ExpandDatabase + Upcast<dyn ExpandDataba
|
||||||
fn enum_variant_data_with_diagnostics(
|
fn enum_variant_data_with_diagnostics(
|
||||||
&self,
|
&self,
|
||||||
id: EnumVariantId,
|
id: EnumVariantId,
|
||||||
) -> (Arc<EnumVariantData>, Option<Arc<Box<[DefDiagnostic]>>>);
|
) -> (Arc<EnumVariantData>, DefDiagnostics);
|
||||||
|
|
||||||
#[salsa::invoke(ImplData::impl_data_query)]
|
#[salsa::invoke(ImplData::impl_data_query)]
|
||||||
fn impl_data(&self, e: ImplId) -> Arc<ImplData>;
|
fn impl_data(&self, e: ImplId) -> Arc<ImplData>;
|
||||||
|
|
||||||
#[salsa::invoke(ImplData::impl_data_with_diagnostics_query)]
|
#[salsa::invoke(ImplData::impl_data_with_diagnostics_query)]
|
||||||
fn impl_data_with_diagnostics(&self, e: ImplId) -> (Arc<ImplData>, Arc<[DefDiagnostic]>);
|
fn impl_data_with_diagnostics(&self, e: ImplId) -> (Arc<ImplData>, DefDiagnostics);
|
||||||
|
|
||||||
#[salsa::invoke(TraitData::trait_data_query)]
|
#[salsa::invoke(TraitData::trait_data_query)]
|
||||||
fn trait_data(&self, e: TraitId) -> Arc<TraitData>;
|
fn trait_data(&self, e: TraitId) -> Arc<TraitData>;
|
||||||
|
|
||||||
#[salsa::invoke(TraitData::trait_data_with_diagnostics_query)]
|
#[salsa::invoke(TraitData::trait_data_with_diagnostics_query)]
|
||||||
fn trait_data_with_diagnostics(&self, tr: TraitId) -> (Arc<TraitData>, Arc<[DefDiagnostic]>);
|
fn trait_data_with_diagnostics(&self, tr: TraitId) -> (Arc<TraitData>, DefDiagnostics);
|
||||||
|
|
||||||
#[salsa::invoke(TraitAliasData::trait_alias_query)]
|
#[salsa::invoke(TraitAliasData::trait_alias_query)]
|
||||||
fn trait_alias_data(&self, e: TraitAliasId) -> Arc<TraitAliasData>;
|
fn trait_alias_data(&self, e: TraitAliasId) -> Arc<TraitAliasData>;
|
||||||
|
|
|
@ -40,6 +40,23 @@ pub enum DefDiagnosticKind {
|
||||||
MacroDefError { ast: AstId<ast::Macro>, message: String },
|
MacroDefError { ast: AstId<ast::Macro>, message: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||||
|
pub struct DefDiagnostics(Option<triomphe::Arc<Box<[DefDiagnostic]>>>);
|
||||||
|
|
||||||
|
impl DefDiagnostics {
|
||||||
|
pub fn new(diagnostics: Vec<DefDiagnostic>) -> Self {
|
||||||
|
Self(if diagnostics.is_empty() {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
Some(triomphe::Arc::new(diagnostics.into_boxed_slice()))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn iter(&self) -> impl Iterator<Item = &DefDiagnostic> {
|
||||||
|
self.0.as_ref().into_iter().flat_map(|it| &***it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
pub struct DefDiagnostic {
|
pub struct DefDiagnostic {
|
||||||
pub in_module: LocalModuleId,
|
pub in_module: LocalModuleId,
|
||||||
|
|
|
@ -69,6 +69,7 @@ struct MirLowerCtx<'a> {
|
||||||
drop_scopes: Vec<DropScope>,
|
drop_scopes: Vec<DropScope>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME: Make this smaller, its stored in database queries
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum MirLowerError {
|
pub enum MirLowerError {
|
||||||
ConstEvalError(Box<str>, Box<ConstEvalError>),
|
ConstEvalError(Box<str>, Box<ConstEvalError>),
|
||||||
|
|
|
@ -584,15 +584,12 @@ impl Module {
|
||||||
Adt::Enum(e) => {
|
Adt::Enum(e) => {
|
||||||
for v in e.variants(db) {
|
for v in e.variants(db) {
|
||||||
acc.extend(ModuleDef::Variant(v).diagnostics(db));
|
acc.extend(ModuleDef::Variant(v).diagnostics(db));
|
||||||
if let Some(diags) = &db.enum_variant_data_with_diagnostics(v.id).1
|
for diag in db.enum_variant_data_with_diagnostics(v.id).1.iter() {
|
||||||
{
|
|
||||||
for diag in &***diags {
|
|
||||||
emit_def_diagnostic(db, acc, diag);
|
emit_def_diagnostic(db, acc, diag);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
acc.extend(def.diagnostics(db))
|
acc.extend(def.diagnostics(db))
|
||||||
}
|
}
|
||||||
ModuleDef::Macro(m) => emit_macro_def_diagnostics(db, acc, m),
|
ModuleDef::Macro(m) => emit_macro_def_diagnostics(db, acc, m),
|
||||||
|
|
Loading…
Reference in a new issue