From 642a8534b882ab926e376a71f617e7baac0ae053 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Fri, 31 Jul 2026 03:09:25 +0300 Subject: [PATCH 1/7] Remove `as_dyn()` from `HirDatabase`, put it in `SourceDatabase` --- crates/base-db/src/lib.rs | 2 ++ crates/hir-ty/src/db.rs | 19 +------------------ 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/crates/base-db/src/lib.rs b/crates/base-db/src/lib.rs index 4beeae950865..870352beecbf 100644 --- a/crates/base-db/src/lib.rs +++ b/crates/base-db/src/lib.rs @@ -310,6 +310,8 @@ pub trait SourceDatabase: salsa::Database + std::fmt::Debug { fn nonce_and_revision(&self) -> (Nonce, salsa::Revision); fn line_column(&self, file: FileId, offset: TextSize) -> Result<(u32, u32), ()>; + + fn as_dyn(&self) -> &dyn SourceDatabase; } static NEXT_NONCE: AtomicUsize = AtomicUsize::new(0); diff --git a/crates/hir-ty/src/db.rs b/crates/hir-ty/src/db.rs index 8e7e55a77b34..c36626eb5f9d 100644 --- a/crates/hir-ty/src/db.rs +++ b/crates/hir-ty/src/db.rs @@ -37,14 +37,7 @@ use crate::{ traits::{ParamEnvAndCrate, StoredParamEnvAndCrate}, }; -#[salsa::db] pub trait HirDatabase: SourceDatabase + 'static { - /// Manual implementation of upcasting from `dyn SourceDatabase` to `dyn HirDatabase`. - /// - /// This function is needed because Rust can't perform this upcasting automatically - /// in the general case, as `Self` could be unsized. - fn as_dyn(&self) -> &dyn HirDatabase; - // region:mir // FIXME: Collapse `mir_body_for_closure` into `mir_body` @@ -334,17 +327,7 @@ pub trait HirDatabase: SourceDatabase + 'static { } } -#[salsa::db] -impl HirDatabase for T { - fn as_dyn(&self) -> &dyn HirDatabase { - self - } -} - -#[test] -fn hir_database_is_dyn_compatible() { - fn _assert_dyn_compatible(_: &dyn HirDatabase) {} -} +impl HirDatabase for T {} #[salsa::interned(debug, revisions = usize::MAX)] #[derive(PartialOrd, Ord)] From 92f8f82a60fa7fb4584369aa8180b6ca5504ff7e Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Fri, 31 Jul 2026 03:11:12 +0300 Subject: [PATCH 2/7] Search-and-replace `dyn HirDatabase` with `dyn SourceDatabase` --- crates/hir-ty/src/autoderef.rs | 2 +- crates/hir-ty/src/builtin_derive.rs | 4 +- crates/hir-ty/src/consteval.rs | 36 +- crates/hir-ty/src/db.rs | 10 +- crates/hir-ty/src/diagnostics/decl_check.rs | 6 +- crates/hir-ty/src/diagnostics/expr.rs | 10 +- crates/hir-ty/src/diagnostics/match_check.rs | 4 +- .../diagnostics/match_check/pat_analysis.rs | 8 +- crates/hir-ty/src/diagnostics/unsafe_check.rs | 10 +- crates/hir-ty/src/display.rs | 20 +- crates/hir-ty/src/drop.rs | 2 +- crates/hir-ty/src/dyn_compatibility.rs | 28 +- crates/hir-ty/src/infer.rs | 26 +- crates/hir-ty/src/infer/cast.rs | 2 +- crates/hir-ty/src/infer/coerce.rs | 8 +- crates/hir-ty/src/infer/diagnostics.rs | 2 +- crates/hir-ty/src/infer/unify.rs | 10 +- crates/hir-ty/src/inhabitedness.rs | 2 +- crates/hir-ty/src/layout.rs | 10 +- crates/hir-ty/src/layout/adt.rs | 4 +- crates/hir-ty/src/layout/target.rs | 2 +- crates/hir-ty/src/lib.rs | 16 +- crates/hir-ty/src/lower.rs | 139 +-- crates/hir-ty/src/lower/path.rs | 2 +- crates/hir-ty/src/method_resolution.rs | 40 +- .../hir-ty/src/method_resolution/confirm.rs | 2 +- crates/hir-ty/src/method_resolution/probe.rs | 2 +- crates/hir-ty/src/mir.rs | 2 +- crates/hir-ty/src/mir/borrowck.rs | 16 +- crates/hir-ty/src/mir/eval.rs | 10 +- crates/hir-ty/src/mir/lower.rs | 24 +- crates/hir-ty/src/mir/monomorphization.rs | 14 +- crates/hir-ty/src/mir/pretty.rs | 8 +- crates/hir-ty/src/next_solver.rs | 2 +- .../hir-ty/src/next_solver/consts/valtree.rs | 2 +- crates/hir-ty/src/next_solver/generics.rs | 4 +- crates/hir-ty/src/next_solver/interner.rs | 40 +- crates/hir-ty/src/next_solver/ty.rs | 2 +- crates/hir-ty/src/opaques.rs | 10 +- crates/hir-ty/src/representability.rs | 14 +- crates/hir-ty/src/specialization.rs | 6 +- crates/hir-ty/src/target_feature.rs | 4 +- crates/hir-ty/src/traits.rs | 20 +- crates/hir-ty/src/upvars.rs | 16 +- crates/hir-ty/src/utils.rs | 8 +- crates/hir-ty/src/variance.rs | 10 +- crates/hir/src/attrs.rs | 54 +- crates/hir/src/diagnostics.rs | 8 +- crates/hir/src/display.rs | 2 +- crates/hir/src/has_source.rs | 68 +- crates/hir/src/lib.rs | 893 +++++++++--------- crates/hir/src/semantics.rs | 14 +- crates/hir/src/semantics/source_to_def.rs | 8 +- crates/hir/src/source_analyzer.rs | 122 +-- crates/hir/src/symbols.rs | 6 +- crates/hir/src/term_search.rs | 8 +- crates/hir/src/term_search/expr.rs | 6 +- .../ide-assists/src/handlers/auto_import.rs | 2 +- .../src/handlers/fix_visibility.rs | 4 +- .../src/handlers/generate_delegate_trait.rs | 2 +- .../src/handlers/generate_function.rs | 2 +- .../ide-assists/src/handlers/inline_call.rs | 2 +- .../src/handlers/qualify_method_call.rs | 4 +- crates/ide-assists/src/utils.rs | 28 +- crates/ide-completion/src/render/function.rs | 2 +- crates/ide-completion/src/render/literal.rs | 6 +- crates/ide-completion/src/render/macro_.rs | 2 +- crates/ide-completion/src/render/pattern.rs | 2 +- crates/ide-completion/src/tests/flyimport.rs | 2 +- crates/ide-db/src/defs.rs | 4 +- crates/ide-db/src/documentation.rs | 10 +- crates/ide-db/src/lib.rs | 2 +- crates/ide-db/src/symbol_index.rs | 16 +- crates/ide-db/src/traits.rs | 6 +- .../src/handlers/missing_fields.rs | 2 +- crates/ide/src/doc_links.rs | 6 +- crates/ide/src/static_index.rs | 2 +- crates/ide/src/syntax_highlighting/inject.rs | 2 +- crates/rust-analyzer/src/cli.rs | 2 +- crates/rust-analyzer/src/cli/diagnostics.rs | 2 +- crates/rust-analyzer/src/cli/run_tests.rs | 2 +- .../src/cli/unresolved_references.rs | 2 +- 82 files changed, 997 insertions(+), 927 deletions(-) diff --git a/crates/hir-ty/src/autoderef.rs b/crates/hir-ty/src/autoderef.rs index 4fab468dfd8e..cf4a3ff79f5a 100644 --- a/crates/hir-ty/src/autoderef.rs +++ b/crates/hir-ty/src/autoderef.rs @@ -35,7 +35,7 @@ const AUTODEREF_RECURSION_LIMIT: usize = 20; /// - a type won't be yielded more than once; in other words, the returned iterator will stop if it /// detects a cycle in the deref chain. pub fn autoderef<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, env: ParamEnvAndCrate<'db>, ty: Canonical<'db, Ty<'db>>, ) -> impl Iterator> + use<'db> { diff --git a/crates/hir-ty/src/builtin_derive.rs b/crates/hir-ty/src/builtin_derive.rs index f82fc940ff63..6f2b6bcbf703 100644 --- a/crates/hir-ty/src/builtin_derive.rs +++ b/crates/hir-ty/src/builtin_derive.rs @@ -82,7 +82,7 @@ pub(crate) fn generics_of<'db>( } } -pub fn generic_params_count(db: &dyn HirDatabase, id: BuiltinDeriveImplId) -> usize { +pub fn generic_params_count(db: &dyn SourceDatabase, id: BuiltinDeriveImplId) -> usize { let loc = id.loc(db); let adt_params = GenericParams::of(db, loc.adt.into()); let extra_params_count = match loc.trait_ { @@ -154,7 +154,7 @@ pub fn impl_trait<'db>( } #[salsa::tracked(returns(ref))] -pub fn predicates(db: &dyn HirDatabase, impl_: BuiltinDeriveImplId) -> GenericPredicates { +pub fn predicates(db: &dyn SourceDatabase, impl_: BuiltinDeriveImplId) -> GenericPredicates { let loc = impl_.loc(db); let generic_params = GenericParams::of(db, loc.adt.into()); let interner = DbInterner::new_with(db, loc.module(db).krate(db)); diff --git a/crates/hir-ty/src/consteval.rs b/crates/hir-ty/src/consteval.rs index 15dd53031206..1629f35a226c 100644 --- a/crates/hir-ty/src/consteval.rs +++ b/crates/hir-ty/src/consteval.rs @@ -46,7 +46,7 @@ impl ConstEvalError<'_> { pub fn pretty_print( &self, f: &mut String, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, span_formatter: impl Fn(span::FileId, span::TextRange) -> String, display_target: DisplayTarget, ) -> std::result::Result<(), std::fmt::Error> { @@ -214,7 +214,11 @@ pub(crate) fn literal_ty<'db>( } /// Interns a possibly-unknown target usize -pub fn usize_const<'db>(db: &'db dyn HirDatabase, value: Option, krate: Crate) -> Const<'db> { +pub fn usize_const<'db>( + db: &'db dyn SourceDatabase, + value: Option, + krate: Crate, +) -> Const<'db> { let interner = DbInterner::new_no_crate(db); let value = match value { Some(value) => value, @@ -236,7 +240,7 @@ pub fn allocation_as_usize(ec: Allocation<'_>) -> u128 { u128::from_le_bytes(pad16(&ec.memory, false)) } -pub fn try_const_usize<'db>(db: &'db dyn HirDatabase, c: Const<'db>) -> Option { +pub fn try_const_usize<'db>(db: &'db dyn SourceDatabase, c: Const<'db>) -> Option { match c.kind() { ConstKind::Param(_) => None, ConstKind::Infer(_) => None, @@ -274,7 +278,7 @@ pub fn allocation_as_isize(ec: Allocation<'_>) -> i128 { i128::from_le_bytes(pad16(&ec.memory, true)) } -pub fn try_const_isize<'db>(db: &'db dyn HirDatabase, c: Const<'db>) -> Option { +pub fn try_const_isize<'db>(db: &'db dyn SourceDatabase, c: Const<'db>) -> Option { match c.kind() { ConstKind::Param(_) => None, ConstKind::Infer(_) => None, @@ -323,7 +327,7 @@ pub(crate) enum CreateConstError<'db> { } pub(crate) fn path_to_const<'a, 'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: &Resolver<'db>, generics: &dyn Fn() -> &'a Generics<'db>, forbid_params_after: Option, @@ -416,7 +420,7 @@ pub(crate) fn create_anon_const<'a, 'db>( #[salsa::tracked(cycle_result = const_eval_discriminant_cycle_result)] pub(crate) fn const_eval_discriminant_variant<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, variant_id: EnumVariantId, ) -> Result> { let interner = DbInterner::new_no_crate(db); @@ -452,7 +456,7 @@ pub(crate) fn const_eval_discriminant_variant<'db>( } fn const_eval_discriminant_cycle_result<'db>( - _: &'db dyn HirDatabase, + _: &'db dyn SourceDatabase, _: salsa::Id, _: EnumVariantId, ) -> Result> { @@ -460,7 +464,7 @@ fn const_eval_discriminant_cycle_result<'db>( } pub(crate) fn const_eval<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: ConstId, subst: GenericArgs<'db>, trait_env: Option>, @@ -472,7 +476,7 @@ pub(crate) fn const_eval<'db>( #[salsa::tracked(returns(ref), cycle_result = const_eval_cycle_result)] pub(crate) fn const_eval_query<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: ConstId, subst: StoredGenericArgs, trait_env: Option, @@ -488,7 +492,7 @@ pub(crate) fn const_eval<'db>( } pub(crate) fn const_eval_cycle_result<'db>( - _: &'db dyn HirDatabase, + _: &'db dyn SourceDatabase, _: salsa::Id, _: ConstId, _: StoredGenericArgs, @@ -499,7 +503,7 @@ pub(crate) fn const_eval<'db>( } pub(crate) fn anon_const_eval<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: AnonConstId<'db>, subst: GenericArgs<'db>, trait_env: Option>, @@ -511,7 +515,7 @@ pub(crate) fn anon_const_eval<'db>( #[salsa::tracked(returns(ref), cycle_result = anon_const_eval_cycle_result)] pub(crate) fn anon_const_eval_query<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: AnonConstId<'db>, subst: StoredGenericArgs, trait_env: Option, @@ -530,7 +534,7 @@ pub(crate) fn anon_const_eval<'db>( } pub(crate) fn anon_const_eval_cycle_result<'db>( - _: &'db dyn HirDatabase, + _: &'db dyn SourceDatabase, _: salsa::Id, _: AnonConstId<'db>, _: StoredGenericArgs, @@ -541,7 +545,7 @@ pub(crate) fn anon_const_eval<'db>( } pub(crate) fn const_eval_static<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: StaticId, ) -> Result, ConstEvalError<'db>> { return match const_eval_static_query(db, def) { @@ -551,7 +555,7 @@ pub(crate) fn const_eval_static<'db>( #[salsa::tracked(returns(ref), cycle_result = const_eval_static_cycle_result)] pub(crate) fn const_eval_static_query<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: StaticId, ) -> Result> { let interner = DbInterner::new_no_crate(db); @@ -566,7 +570,7 @@ pub(crate) fn const_eval_static<'db>( } pub(crate) fn const_eval_static_cycle_result<'db>( - _: &'db dyn HirDatabase, + _: &'db dyn SourceDatabase, _: salsa::Id, _: StaticId, ) -> Result> { diff --git a/crates/hir-ty/src/db.rs b/crates/hir-ty/src/db.rs index c36626eb5f9d..1ec9ede27cd5 100644 --- a/crates/hir-ty/src/db.rs +++ b/crates/hir-ty/src/db.rs @@ -350,7 +350,7 @@ pub struct InternedClosureId<'db> { impl<'db> InternedClosureId<'db> { #[inline] - pub fn new(db: &'db dyn HirDatabase, loc: InternedClosure<'db>) -> Self { + pub fn new(db: &'db dyn SourceDatabase, loc: InternedClosure<'db>) -> Self { if cfg!(debug_assertions) { let store = ExpressionStore::of(db, loc.owner.expression_store_owner(db)); let expr = &store[loc.expr]; @@ -378,7 +378,7 @@ pub struct InternedCoroutineId<'db> { impl<'db> InternedCoroutineId<'db> { #[inline] - pub fn new(db: &'db dyn HirDatabase, loc: InternedClosure<'db>) -> Self { + pub fn new(db: &'db dyn SourceDatabase, loc: InternedClosure<'db>) -> Self { if cfg!(debug_assertions) { let store = ExpressionStore::of(db, loc.owner.expression_store_owner(db)); let expr = &store[loc.expr]; @@ -407,7 +407,7 @@ pub struct InternedCoroutineClosureId<'db> { impl<'db> InternedCoroutineClosureId<'db> { #[inline] - pub fn new(db: &'db dyn HirDatabase, loc: InternedClosure<'db>) -> Self { + pub fn new(db: &'db dyn SourceDatabase, loc: InternedClosure<'db>) -> Self { if cfg!(debug_assertions) { let store = ExpressionStore::of(db, loc.owner.expression_store_owner(db)); let expr = &store[loc.expr]; @@ -475,7 +475,7 @@ impl HasResolver for AnonConstId<'_> { impl<'db> AnonConstId<'db> { pub fn all_from_signature( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: GenericDefId, ) -> ArrayVec<&'db [Self], 5> { let mut result = ArrayVec::new(); @@ -523,7 +523,7 @@ pub enum GeneralConstId<'db> { impl_from!(impl<'db> ConstId, StaticId, AnonConstId<'db> for GeneralConstId<'db>); impl<'db> GeneralConstId<'db> { - pub fn generic_def(self, db: &'db dyn HirDatabase) -> Option { + pub fn generic_def(self, db: &'db dyn SourceDatabase) -> Option { match self { GeneralConstId::ConstId(it) => Some(it.into()), GeneralConstId::StaticId(it) => Some(it.into()), diff --git a/crates/hir-ty/src/diagnostics/decl_check.rs b/crates/hir-ty/src/diagnostics/decl_check.rs index a465f8be4e17..7cc5107d65a9 100644 --- a/crates/hir-ty/src/diagnostics/decl_check.rs +++ b/crates/hir-ty/src/diagnostics/decl_check.rs @@ -44,7 +44,7 @@ use crate::db::HirDatabase; use self::case_conv::{to_camel_case, to_lower_snake_case, to_upper_snake_case}; -pub fn incorrect_case(db: &dyn HirDatabase, owner: ModuleDefId) -> Vec { +pub fn incorrect_case(db: &dyn SourceDatabase, owner: ModuleDefId) -> Vec { let _p = tracing::info_span!("incorrect_case").entered(); let mut validator = DeclValidator::new(db); validator.validate_item(owner); @@ -123,7 +123,7 @@ pub struct IncorrectCase { } pub(super) struct DeclValidator<'a> { - db: &'a dyn HirDatabase, + db: &'a dyn SourceDatabase, pub(super) sink: Vec, } @@ -135,7 +135,7 @@ struct Replacement { } impl<'a> DeclValidator<'a> { - pub(super) fn new(db: &'a dyn HirDatabase) -> DeclValidator<'a> { + pub(super) fn new(db: &'a dyn SourceDatabase) -> DeclValidator<'a> { DeclValidator { db, sink: Vec::new() } } diff --git a/crates/hir-ty/src/diagnostics/expr.rs b/crates/hir-ty/src/diagnostics/expr.rs index 0947f456adea..997dd459e4b4 100644 --- a/crates/hir-ty/src/diagnostics/expr.rs +++ b/crates/hir-ty/src/diagnostics/expr.rs @@ -76,7 +76,7 @@ pub enum BodyValidationDiagnostic<'db> { impl<'db> BodyValidationDiagnostic<'db> { pub fn collect( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, owner: DefWithBodyId, validate_lints: bool, ) -> Vec> { @@ -113,7 +113,7 @@ struct ExprValidator<'db> { impl<'db> ExprValidator<'db> { #[inline] - fn db(&self) -> &'db dyn HirDatabase { + fn db(&self) -> &'db dyn SourceDatabase { self.infcx.interner.db } @@ -566,7 +566,7 @@ struct FilterMapNextChecker<'db> { } impl<'db> FilterMapNextChecker<'db> { - fn new(lang_items: &'db LangItems, db: &'db dyn HirDatabase) -> Self { + fn new(lang_items: &'db LangItems, db: &'db dyn SourceDatabase) -> Self { // Find and store the FunctionIds for Iterator::filter_map and Iterator::next let (next_function_id, filter_map_function_id) = match lang_items.IteratorNext { Some(next_function_id) => ( @@ -622,7 +622,7 @@ impl<'db> FilterMapNextChecker<'db> { } pub fn record_literal_missing_fields<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, infer: &InferenceResult<'db>, id: ExprId, expr: &Expr, @@ -665,7 +665,7 @@ pub fn record_literal_missing_fields<'db>( } pub fn record_pattern_missing_fields<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, infer: &InferenceResult<'db>, id: PatId, pat: &Pat, diff --git a/crates/hir-ty/src/diagnostics/match_check.rs b/crates/hir-ty/src/diagnostics/match_check.rs index 613912e0901b..1daad1ca745b 100644 --- a/crates/hir-ty/src/diagnostics/match_check.rs +++ b/crates/hir-ty/src/diagnostics/match_check.rs @@ -96,7 +96,7 @@ pub(crate) enum PatKind<'db> { } pub(crate) struct PatCtxt<'a, 'db> { - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, infer: &'db InferenceResult<'db>, body: &'a Body, pub(crate) errors: Vec, @@ -104,7 +104,7 @@ pub(crate) struct PatCtxt<'a, 'db> { impl<'a, 'db> PatCtxt<'a, 'db> { pub(crate) fn new( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, infer: &'db InferenceResult<'db>, body: &'a Body, ) -> Self { diff --git a/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs b/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs index 5994ca2f14fb..c79de2703140 100644 --- a/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs +++ b/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs @@ -47,13 +47,13 @@ pub(crate) enum Void {} pub(crate) struct EnumVariantContiguousIndex(usize); impl EnumVariantContiguousIndex { - fn from_enum_variant_id(db: &dyn HirDatabase, target_evid: EnumVariantId) -> Self { + fn from_enum_variant_id(db: &dyn SourceDatabase, target_evid: EnumVariantId) -> Self { // Find the index of this variant in the list of variants. let i = target_evid.index(db); EnumVariantContiguousIndex(i) } - fn to_enum_variant_id(self, db: &dyn HirDatabase, eid: EnumId) -> EnumVariantId { + fn to_enum_variant_id(self, db: &dyn SourceDatabase, eid: EnumId) -> EnumVariantId { eid.enum_variants(db).variants[self.0].0 } } @@ -71,7 +71,7 @@ impl rustc_pattern_analysis::Idx for EnumVariantContiguousIndex { #[derive(Clone)] pub(crate) struct MatchCheckCtx<'a, 'db> { module: ModuleId, - pub(crate) db: &'db dyn HirDatabase, + pub(crate) db: &'db dyn SourceDatabase, exhaustive_patterns: bool, env: ParamEnv<'db>, infcx: &'a InferCtxt<'db>, @@ -116,7 +116,7 @@ impl<'a, 'db> MatchCheckCtx<'a, 'db> { } fn variant_id_for_adt( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ctor: &Constructor, adt: hir_def::AdtId, ) -> Option { diff --git a/crates/hir-ty/src/diagnostics/unsafe_check.rs b/crates/hir-ty/src/diagnostics/unsafe_check.rs index 3021de68f3fd..7254ac2a6532 100644 --- a/crates/hir-ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir-ty/src/diagnostics/unsafe_check.rs @@ -31,7 +31,7 @@ pub struct MissingUnsafeResult { pub deprecated_safe_calls: Vec, } -pub fn missing_unsafe(db: &dyn HirDatabase, def: DefWithBodyId) -> MissingUnsafeResult { +pub fn missing_unsafe(db: &dyn SourceDatabase, def: DefWithBodyId) -> MissingUnsafeResult { let _p = tracing::info_span!("missing_unsafe").entered(); let is_unsafe = match def { @@ -99,7 +99,7 @@ enum UnsafeDiagnostic { } pub fn unsafe_operations_for_body( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, infer: &InferenceResult<'_>, def: DefWithBodyId, body: &Body, @@ -118,7 +118,7 @@ pub fn unsafe_operations_for_body( } pub fn unsafe_operations( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, infer: &InferenceResult<'_>, def: ExpressionStoreOwnerId, body: &ExpressionStore, @@ -136,7 +136,7 @@ pub fn unsafe_operations( } struct UnsafeVisitor<'db> { - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, infer: &'db InferenceResult<'db>, body: &'db ExpressionStore, resolver: Resolver<'db>, @@ -155,7 +155,7 @@ struct UnsafeVisitor<'db> { impl<'db> UnsafeVisitor<'db> { fn new( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, infer: &'db InferenceResult<'db>, body: &'db ExpressionStore, def: ExpressionStoreOwnerId, diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs index dc20eb930e81..c92e045fc512 100644 --- a/crates/hir-ty/src/display.rs +++ b/crates/hir-ty/src/display.rs @@ -115,7 +115,7 @@ impl HirWrite for fmt::Formatter<'_> {} pub struct HirFormatter<'a, 'db> { /// The database handle - pub db: &'db dyn HirDatabase, + pub db: &'db dyn SourceDatabase, pub interner: DbInterner<'db>, /// The sink to write into fmt: &'a mut dyn HirWrite, @@ -238,7 +238,7 @@ pub trait HirDisplay<'db> { /// Returns a `Display`able type that is human-readable. fn into_displayable<'a>( &'a self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, max_size: Option, limited_size: Option, omit_verbose_types: bool, @@ -273,7 +273,7 @@ pub trait HirDisplay<'db> { /// Use this for showing types to the user (e.g. diagnostics) fn display<'a>( &'a self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, display_target: DisplayTarget, ) -> HirDisplayWrapper<'a, 'db, Self> where @@ -298,7 +298,7 @@ pub trait HirDisplay<'db> { /// Use this for showing types to the user where space is constrained (e.g. doc popups) fn display_truncated<'a>( &'a self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, max_size: Option, display_target: DisplayTarget, ) -> HirDisplayWrapper<'a, 'db, Self> @@ -324,7 +324,7 @@ pub trait HirDisplay<'db> { /// Use this for showing definitions which may contain too many items, like `trait`, `struct`, `enum` fn display_limited<'a>( &'a self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, limited_size: Option, display_target: DisplayTarget, ) -> HirDisplayWrapper<'a, 'db, Self> @@ -350,7 +350,7 @@ pub trait HirDisplay<'db> { /// Use this when generating code (e.g. assists) fn display_source_code<'a>( &'a self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, module_id: ModuleId, allow_opaque: bool, ) -> Result { @@ -384,7 +384,7 @@ pub trait HirDisplay<'db> { /// Returns a String representation of `self` for test purposes fn display_test<'a>( &'a self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, display_target: DisplayTarget, ) -> HirDisplayWrapper<'a, 'db, Self> where @@ -409,7 +409,7 @@ pub trait HirDisplay<'db> { /// the container for functions fn display_with_container_bounds<'a>( &'a self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, show_container_bounds: bool, display_target: DisplayTarget, ) -> HirDisplayWrapper<'a, 'db, Self> @@ -516,7 +516,7 @@ pub struct DisplayTarget { } impl DisplayTarget { - pub fn from_crate(db: &dyn HirDatabase, krate: Crate) -> Self { + pub fn from_crate(db: &dyn SourceDatabase, krate: Crate) -> Self { let edition = krate.data(db).edition; Self { krate, edition } } @@ -569,7 +569,7 @@ impl From for HirDisplayError { } pub struct HirDisplayWrapper<'a, 'db, T> { - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, t: &'a T, max_size: Option, limited_size: Option, diff --git a/crates/hir-ty/src/drop.rs b/crates/hir-ty/src/drop.rs index 0a4d016c6a9c..c09d923d6fdd 100644 --- a/crates/hir-ty/src/drop.rs +++ b/crates/hir-ty/src/drop.rs @@ -19,7 +19,7 @@ use crate::{ }; #[salsa::tracked] -pub fn destructor(db: &dyn HirDatabase, adt: AdtId) -> Option { +pub fn destructor(db: &dyn SourceDatabase, adt: AdtId) -> Option { let module = match adt { AdtId::EnumId(id) => id.loc(db).container, AdtId::StructId(id) => id.loc(db).container, diff --git a/crates/hir-ty/src/dyn_compatibility.rs b/crates/hir-ty/src/dyn_compatibility.rs index bf7970d629d2..3eca5a66ba59 100644 --- a/crates/hir-ty/src/dyn_compatibility.rs +++ b/crates/hir-ty/src/dyn_compatibility.rs @@ -55,7 +55,7 @@ pub enum MethodViolationCode { } pub fn dyn_compatibility( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, trait_: TraitId, ) -> Option { let interner = DbInterner::new_no_crate(db); @@ -73,7 +73,7 @@ pub fn dyn_compatibility( } pub fn dyn_compatibility_with_callback( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, trait_: TraitId, cb: &mut F, ) -> ControlFlow<()> @@ -91,7 +91,7 @@ where } pub fn dyn_compatibility_of_trait_with_callback( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, trait_: TraitId, cb: &mut F, ) -> ControlFlow<()> @@ -124,7 +124,7 @@ where #[salsa::tracked] pub fn dyn_compatibility_of_trait_query( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, trait_: TraitId, ) -> Option { let mut res = None; @@ -136,7 +136,7 @@ pub fn dyn_compatibility_of_trait_query( res } -pub fn generics_require_sized_self(db: &dyn HirDatabase, def: GenericDefId) -> bool { +pub fn generics_require_sized_self(db: &dyn SourceDatabase, def: GenericDefId) -> bool { let krate = def.module(db).krate(db); let interner = DbInterner::new_with(db, krate); let Some(sized) = interner.lang_items().Sized else { @@ -168,14 +168,14 @@ pub fn generics_require_sized_self(db: &dyn HirDatabase, def: GenericDefId) -> b // rustc gathers all the spans that references `Self` for error rendering, // but we don't have good way to render such locations. // So, just return single boolean value for existence of such `Self` reference -fn predicates_reference_self(db: &dyn HirDatabase, trait_: TraitId) -> bool { +fn predicates_reference_self(db: &dyn SourceDatabase, trait_: TraitId) -> bool { GenericPredicates::query_explicit(db, trait_.into()).iter_identity().any(|pred| { predicate_references_self(db, trait_, pred.skip_norm_wip(), AllowSelfProjection::No) }) } // Same as the above, `predicates_reference_self` -fn bounds_reference_self(db: &dyn HirDatabase, trait_: TraitId) -> bool { +fn bounds_reference_self(db: &dyn SourceDatabase, trait_: TraitId) -> bool { let trait_data = trait_.trait_items(db); trait_data .items @@ -204,7 +204,7 @@ enum AllowSelfProjection { } fn predicate_references_self<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, trait_: TraitId, predicate: Clause<'db>, allow_self_projection: AllowSelfProjection, @@ -223,13 +223,13 @@ fn predicate_references_self<'db>( } fn contains_illegal_self_type_reference<'db, T: rustc_type_ir::TypeVisitable>>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, trait_: TraitId, t: &T, allow_self_projection: AllowSelfProjection, ) -> bool { struct IllegalSelfTypeVisitor<'db> { - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, trait_: TraitId, super_traits: Option>, allow_self_projection: AllowSelfProjection, @@ -276,7 +276,7 @@ fn contains_illegal_self_type_reference<'db, T: rustc_type_ir::TypeVisitable( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, features: &mut Option<&'db UnstableFeatures>, trait_: TraitId, item: AssocItemId, @@ -317,7 +317,7 @@ where } fn virtual_call_violations_for_method( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, trait_: TraitId, func: FunctionId, cb: &mut F, @@ -396,7 +396,7 @@ where } fn receiver_is_dispatchable<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, trait_: TraitId, func: FunctionId, sig: &EarlyBinder<'db, Binder<'db, rustc_type_ir::FnSig>>>, @@ -489,7 +489,7 @@ fn receiver_for_self_ty<'db>( } fn contains_illegal_impl_trait_in_trait<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, sig: &EarlyBinder<'db, Binder<'db, rustc_type_ir::FnSig>>>, ) -> Option { struct OpaqueTypeCollector<'db>(FxHashSet>); diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs index a5a82209c603..cf6d291a02bf 100644 --- a/crates/hir-ty/src/infer.rs +++ b/crates/hir-ty/src/infer.rs @@ -119,12 +119,12 @@ pub use unify::{could_unify, could_unify_deeply}; use cast::{CastCheck, CastError}; /// The entry point of type inference. -fn infer_query<'db>(db: &'db dyn HirDatabase, def: DefWithBodyId) -> InferenceResult<'db> { +fn infer_query<'db>(db: &'db dyn SourceDatabase, def: DefWithBodyId) -> InferenceResult<'db> { infer_query_with_inspect(db, def, None, LoweringMode::Analysis) } pub fn infer_query_with_inspect<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: DefWithBodyId, inspect: Option>, lowering_mode: LoweringMode, @@ -187,7 +187,7 @@ pub fn infer_query_with_inspect<'db>( } fn infer_cycle_result<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, _: salsa::Id, _: DefWithBodyId, ) -> InferenceResult<'db> { @@ -199,7 +199,7 @@ fn infer_cycle_result<'db>( /// Infer types for an anonymous const expression. fn infer_anon_const_query<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: AnonConstId<'db>, ) -> InferenceResult<'db> { let _p = tracing::info_span!("infer_anon_const_query").entered(); @@ -230,7 +230,7 @@ fn infer_anon_const_query<'db>( } fn infer_anon_const_cycle_result<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, _: salsa::Id, _: AnonConstId<'db>, ) -> InferenceResult<'db> { @@ -935,7 +935,7 @@ impl CapturedPlace { /// The type of the capture stored in the closure, which is different from the type of the captured place /// if we capture by reference. - pub fn captured_ty<'db>(&self, db: &'db dyn HirDatabase) -> Ty<'db> { + pub fn captured_ty<'db>(&self, db: &'db dyn SourceDatabase) -> Ty<'db> { let place_ty = self.place.ty(); let make_ref = |mutbl| { let interner = DbInterner::new_no_crate(db); @@ -1082,7 +1082,7 @@ pub enum UpvarCapture { #[salsa::tracked] impl<'db> InferenceResult<'db> { #[salsa::tracked(returns(ref), cycle_result = infer_cycle_result)] - fn for_body(db: &dyn HirDatabase, def: DefWithBodyId) -> InferenceResult<'_> { + fn for_body(db: &dyn SourceDatabase, def: DefWithBodyId) -> InferenceResult<'_> { infer_query(db, def) } } @@ -1095,7 +1095,7 @@ impl<'db> InferenceResult<'db> { /// const generic arguments, and other const expressions appearing in type /// positions within the item's signature. #[salsa::tracked(returns(ref), cycle_result = infer_anon_const_cycle_result)] - fn for_anon_const(db: &'db dyn HirDatabase, def: AnonConstId<'db>) -> InferenceResult<'db> { + fn for_anon_const(db: &'db dyn SourceDatabase, def: AnonConstId<'db>) -> InferenceResult<'db> { infer_anon_const_query(db, def) } } @@ -1103,7 +1103,7 @@ impl<'db> InferenceResult<'db> { impl<'db> InferenceResult<'db> { #[inline] pub fn of( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: impl Into>, ) -> &'db InferenceResult<'db> { match def.into() { @@ -1273,7 +1273,7 @@ impl<'db> InferenceResult<'db> { // This method is consumed by external tools to run rust-analyzer as a library. Don't remove, please. pub fn return_position_impl_trait_types<'a>( &'a self, - db: &'a dyn HirDatabase, + db: &'a dyn SourceDatabase, ) -> impl Iterator)> { self.type_of_opaque.iter().filter_map(move |(&id, ty)| { let ImplTraitId::ReturnTypeImplTrait(_, rpit_idx) = id.loc(db) else { @@ -1310,7 +1310,7 @@ impl<'db> InferenceResult<'db> { /// Like [`Self::closure_captures_tys()`], but using [`CapturedPlace::captured_ty()`]. pub fn closure_captures_captured_tys<'a>( &self, - db: &'a dyn HirDatabase, + db: &'a dyn SourceDatabase, closure: ExprId, ) -> impl Iterator> { self.closures_data[&closure] @@ -1333,7 +1333,7 @@ enum DerefPatBorrowMode { /// The inference context contains all information needed during type inference. #[derive(Debug)] pub(crate) struct InferenceContext<'db> { - pub(crate) db: &'db dyn HirDatabase, + pub(crate) db: &'db dyn SourceDatabase, pub(crate) owner: InferBodyId<'db>, pub(crate) store_owner: ExpressionStoreOwnerId, pub(crate) generic_def: GenericDefId, @@ -1431,7 +1431,7 @@ fn find_continuable<'a, 'db>( impl<'db> InferenceContext<'db> { fn new( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, owner: InferBodyId<'db>, store_owner: ExpressionStoreOwnerId, generic_def: GenericDefId, diff --git a/crates/hir-ty/src/infer/cast.rs b/crates/hir-ty/src/infer/cast.rs index dc0813908194..cac61b2ca81a 100644 --- a/crates/hir-ty/src/infer/cast.rs +++ b/crates/hir-ty/src/infer/cast.rs @@ -44,7 +44,7 @@ pub(crate) enum CastTy<'db> { } impl<'db> CastTy<'db> { - pub(crate) fn from_ty(db: &dyn HirDatabase, t: Ty<'db>) -> Option { + pub(crate) fn from_ty(db: &dyn SourceDatabase, t: Ty<'db>) -> Option { match t.kind() { TyKind::Bool => Some(Self::Int(Int::Bool)), TyKind::Char => Some(Self::Int(Int::Char)), diff --git a/crates/hir-ty/src/infer/coerce.rs b/crates/hir-ty/src/infer/coerce.rs index 85d8142335dd..a111c9d54da1 100644 --- a/crates/hir-ty/src/infer/coerce.rs +++ b/crates/hir-ty/src/infer/coerce.rs @@ -139,7 +139,7 @@ where } #[inline] - fn db(&self) -> &'db dyn HirDatabase { + fn db(&self) -> &'db dyn SourceDatabase { self.interner().db } @@ -1416,7 +1416,7 @@ impl<'db, 'exprs> CoerceMany<'db, 'exprs> { } pub fn could_coerce<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, env: ParamEnvAndCrate<'db>, tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>, ) -> bool { @@ -1448,7 +1448,7 @@ impl<'db> CoerceDelegate<'db> for HirCoercionDelegate<'_, 'db> { } fn coerce<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, env: ParamEnvAndCrate<'db>, tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>, ) -> Result<(Vec, Ty<'db>), TypeError>> { @@ -1597,7 +1597,7 @@ fn coerce<'db>( Ok((adjustments, ty)) } -fn is_capturing_closure(db: &dyn HirDatabase, closure: InternedClosureId<'_>) -> bool { +fn is_capturing_closure(db: &dyn SourceDatabase, closure: InternedClosureId<'_>) -> bool { let InternedClosure { owner, expr, .. } = closure.loc(db); upvars_mentioned(db, owner.expression_store_owner(db)) .is_some_and(|upvars| upvars.get(&expr).is_some_and(|upvars| !upvars.is_empty())) diff --git a/crates/hir-ty/src/infer/diagnostics.rs b/crates/hir-ty/src/infer/diagnostics.rs index 69753687afdd..87311b6ab8b0 100644 --- a/crates/hir-ty/src/infer/diagnostics.rs +++ b/crates/hir-ty/src/infer/diagnostics.rs @@ -99,7 +99,7 @@ pub(super) struct InferenceTyLoweringContext<'db, 'a> { impl<'db, 'a> InferenceTyLoweringContext<'db, 'a> { #[inline] pub(super) fn new( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: &'a Resolver<'db>, store: &'db ExpressionStore, diagnostics: &'a Diagnostics, diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs index 6157f51500d9..8c56fd9ee619 100644 --- a/crates/hir-ty/src/infer/unify.rs +++ b/crates/hir-ty/src/infer/unify.rs @@ -90,7 +90,7 @@ impl<'a, 'db> ProofTreeVisitor<'db> for NestedObligationsForSelfTy<'a, 'db> { /// type for the types to unify. For example `Option` and `Option` unify although there is /// unresolved goal `T = U`. pub fn could_unify<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, env: ParamEnvAndCrate<'db>, tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>, ) -> bool { @@ -102,7 +102,7 @@ pub fn could_unify<'db>( /// This means that placeholder types are not considered to unify if there are any bounds set on /// them. For example `Option` and `Option` do not unify as we cannot show that `T = U` pub fn could_unify_deeply<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, env: ParamEnvAndCrate<'db>, tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>, ) -> bool { @@ -110,7 +110,7 @@ pub fn could_unify_deeply<'db>( } fn could_unify_impl<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, env: ParamEnvAndCrate<'db>, tys: &Canonical<'db, (Ty<'db>, Ty<'db>)>, select: for<'a> fn(&mut ObligationCtxt<'a, 'db>) -> Vec>, @@ -129,7 +129,7 @@ fn could_unify_impl<'db>( } pub(crate) struct InferenceTable<'db> { - pub(crate) db: &'db dyn HirDatabase, + pub(crate) db: &'db dyn SourceDatabase, pub(crate) param_env: ParamEnv<'db>, pub(crate) infer_ctxt: InferCtxt<'db>, pub(super) fulfillment_cx: FulfillmentCtxt<'db>, @@ -141,7 +141,7 @@ impl<'db> InferenceTable<'db> { /// Inside hir-ty you should use this for inference only, and always pass `owner`. /// Outside it, always pass `owner = None`. pub(crate) fn new( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, trait_env: ParamEnv<'db>, krate: Crate, owner: ExpressionStoreOwnerId, diff --git a/crates/hir-ty/src/inhabitedness.rs b/crates/hir-ty/src/inhabitedness.rs index bca91d07a74f..9e09296cb6a4 100644 --- a/crates/hir-ty/src/inhabitedness.rs +++ b/crates/hir-ty/src/inhabitedness.rs @@ -108,7 +108,7 @@ impl<'a, 'db> UninhabitedFrom<'a, 'db> { } #[inline] - fn db(&self) -> &'db dyn HirDatabase { + fn db(&self) -> &'db dyn SourceDatabase { self.interner().db } diff --git a/crates/hir-ty/src/layout.rs b/crates/hir-ty/src/layout.rs index db1f7b874e95..23f21607f69a 100644 --- a/crates/hir-ty/src/layout.rs +++ b/crates/hir-ty/src/layout.rs @@ -131,7 +131,7 @@ impl<'a> LayoutCx<'a> { // FIXME: move this to the `rustc_abi`. fn layout_of_simd_ty<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, id: StructId, repr_packed: bool, args: &GenericArgs<'db>, @@ -162,7 +162,7 @@ fn layout_of_simd_ty<'db>( #[salsa::tracked(cycle_result = layout_of_ty_cycle_result)] pub fn layout_of_ty_query( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, ty: StoredTy, trait_env: StoredParamEnvAndCrate, ) -> Result, LayoutError> { @@ -504,7 +504,7 @@ pub fn layout_of_ty_query( } fn layout_of_ty_cycle_result( - _: &dyn HirDatabase, + _: &dyn SourceDatabase, _: salsa::Id, _: StoredTy, _: StoredParamEnvAndCrate, @@ -531,7 +531,7 @@ fn extract_const_value<'db>(ct: Const<'db>) -> Result, LayoutErr } } -fn struct_tail_erasing_lifetimes<'a>(db: &'a dyn HirDatabase, pointee: Ty<'a>) -> Ty<'a> { +fn struct_tail_erasing_lifetimes<'a>(db: &'a dyn SourceDatabase, pointee: Ty<'a>) -> Ty<'a> { match pointee.kind() { TyKind::Adt(def, args) => { let struct_id = match def.def_id() { @@ -560,7 +560,7 @@ fn struct_tail_erasing_lifetimes<'a>(db: &'a dyn HirDatabase, pointee: Ty<'a>) - } fn field_ty<'a>( - db: &'a dyn HirDatabase, + db: &'a dyn SourceDatabase, def: hir_def::VariantId, fd: LocalFieldId, args: GenericArgs<'a>, diff --git a/crates/hir-ty/src/layout/adt.rs b/crates/hir-ty/src/layout/adt.rs index 777d0803fc79..a01f78082adf 100644 --- a/crates/hir-ty/src/layout/adt.rs +++ b/crates/hir-ty/src/layout/adt.rs @@ -21,7 +21,7 @@ use crate::{ #[salsa::tracked(cycle_result = layout_of_adt_cycle_result)] pub fn layout_of_adt_query( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: AdtId, args: StoredGenericArgs, trait_env: StoredParamEnvAndCrate, @@ -98,7 +98,7 @@ pub fn layout_of_adt_query( } fn layout_of_adt_cycle_result( - _: &dyn HirDatabase, + _: &dyn SourceDatabase, _: salsa::Id, _def: AdtId, _args: StoredGenericArgs, diff --git a/crates/hir-ty/src/layout/target.rs b/crates/hir-ty/src/layout/target.rs index 4ff5eb769062..414a209f9a92 100644 --- a/crates/hir-ty/src/layout/target.rs +++ b/crates/hir-ty/src/layout/target.rs @@ -8,7 +8,7 @@ use crate::db::HirDatabase; #[salsa::tracked(returns(as_ref))] pub fn target_data_layout_query( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, krate: Crate, ) -> Result { match &krate.workspace_data(db).target { diff --git a/crates/hir-ty/src/lib.rs b/crates/hir-ty/src/lib.rs index 0dd558828fd7..1f58d6629c8b 100644 --- a/crates/hir-ty/src/lib.rs +++ b/crates/hir-ty/src/lib.rs @@ -217,11 +217,11 @@ impl<'db> MemoryMap<'db> { } /// Returns the index of a parameter in the generic type parameter list by its id. -pub fn type_or_const_param_idx(db: &dyn HirDatabase, id: TypeOrConstParamId) -> u32 { +pub fn type_or_const_param_idx(db: &dyn SourceDatabase, id: TypeOrConstParamId) -> u32 { generics::generics(db, id.parent).type_or_const_param_idx(id) } -pub fn lifetime_param_idx(db: &dyn HirDatabase, id: LifetimeParamId) -> u32 { +pub fn lifetime_param_idx(db: &dyn SourceDatabase, id: LifetimeParamId) -> u32 { generics::generics(db, id.parent).lifetime_param_idx(id, false).0 } @@ -367,7 +367,7 @@ where /// To be used from `hir` only. pub fn associated_type_shorthand_candidates( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: GenericDefId, res: TypeNs, mut cb: impl FnMut(&Name, TypeAliasId) -> bool, @@ -415,7 +415,7 @@ pub fn associated_type_shorthand_candidates( pub fn callable_sig_from_fn_trait<'db>( self_ty: Ty<'db>, param_env: ParamEnvAndCrate<'db>, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ) -> Option<(FnTrait, PolyFnSig<'db>)> { let ParamEnvAndCrate { param_env, krate } = param_env; let interner = DbInterner::new_with(db, krate); @@ -508,7 +508,7 @@ where pub fn known_const_to_ast<'db>( konst: Const<'db>, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, target_module: ModuleId, ) -> Option { Some(make::expr_const_value( @@ -590,14 +590,14 @@ impl HasResolver for InferBodyId<'_> { } impl InferBodyId<'_> { - pub fn expression_store_owner(self, db: &dyn HirDatabase) -> ExpressionStoreOwnerId { + pub fn expression_store_owner(self, db: &dyn SourceDatabase) -> ExpressionStoreOwnerId { match self { InferBodyId::DefWithBodyId(id) => id.into(), InferBodyId::AnonConstId(id) => id.loc(db).owner, } } - pub fn generic_def(self, db: &dyn HirDatabase) -> GenericDefId { + pub fn generic_def(self, db: &dyn SourceDatabase) -> GenericDefId { match self { InferBodyId::DefWithBodyId(id) => id.generic_def(db), InferBodyId::AnonConstId(id) => id.loc(db).owner.generic_def(db), @@ -620,7 +620,7 @@ impl InferBodyId<'_> { } } - pub fn store_and_root_expr(self, db: &dyn HirDatabase) -> (&ExpressionStore, ExprId) { + pub fn store_and_root_expr(self, db: &dyn SourceDatabase) -> (&ExpressionStore, ExprId) { match self { InferBodyId::DefWithBodyId(id) => { let body = Body::of(db, id); diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index bdb882b70b25..577b392dcb88 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -207,7 +207,7 @@ pub trait TyLoweringInferVarsCtx<'db> { } pub struct TyLoweringContext<'db, 'a> { - pub db: &'db dyn HirDatabase, + pub db: &'db dyn SourceDatabase, pub(crate) interner: DbInterner<'db>, types: &'db crate::next_solver::DefaultAny<'db>, lang_items: &'db LangItems, @@ -234,7 +234,7 @@ pub struct TyLoweringContext<'db, 'a> { impl<'db, 'a> TyLoweringContext<'db, 'a> { pub fn new( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: &'a Resolver<'db>, store: &'db ExpressionStore, def: ExpressionStoreOwnerId, @@ -397,7 +397,7 @@ impl<'db, 'a> TyLoweringContext<'db, 'a> { } fn bound_vars( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, interner: DbInterner<'db>, def: GenericDefId, generic: &'a OnceCell>, @@ -1455,7 +1455,7 @@ pub(crate) fn lower_mutability(m: hir_def::type_ref::Mutability) -> Mutability { } pub(crate) fn impl_trait_query<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, impl_id: ImplId, ) -> Option>> { impl_trait_with_diagnostics(db, impl_id) @@ -1465,7 +1465,7 @@ pub(crate) fn impl_trait_query<'db>( #[salsa::tracked(returns(ref), cycle_result = impl_trait_with_diagnostics_cycle_result)] pub(crate) fn impl_trait_with_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, impl_id: ImplId, ) -> Option>> { let impl_data = ImplSignature::of(db, impl_id); @@ -1488,7 +1488,7 @@ pub(crate) fn impl_trait_with_diagnostics<'db>( } pub(crate) fn impl_trait_with_diagnostics_cycle_result<'db>( - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, _: salsa::Id, _impl_id: ImplId, ) -> Option>> { @@ -1497,7 +1497,10 @@ pub(crate) fn impl_trait_with_diagnostics_cycle_result<'db>( impl ImplTraitId { #[inline] - pub fn predicates<'db>(self, db: &'db dyn HirDatabase) -> EarlyBinder<'db, &'db [Clause<'db>]> { + pub fn predicates<'db>( + self, + db: &'db dyn SourceDatabase, + ) -> EarlyBinder<'db, &'db [Clause<'db>]> { let (impl_traits, idx) = match self { ImplTraitId::ReturnTypeImplTrait(owner, idx) => { (ImplTraits::return_type_impl_traits(db, owner), idx) @@ -1515,7 +1518,7 @@ impl ImplTraitId { #[inline] pub fn self_predicates<'db>( self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ) -> EarlyBinder<'db, &'db [Clause<'db>]> { let (impl_traits, idx) = match self { ImplTraitId::ReturnTypeImplTrait(owner, idx) => { @@ -1540,14 +1543,17 @@ impl ImplTraitId { impl InternedOpaqueTyId<'_> { #[inline] - pub fn predicates<'db>(self, db: &'db dyn HirDatabase) -> EarlyBinder<'db, &'db [Clause<'db>]> { + pub fn predicates<'db>( + self, + db: &'db dyn SourceDatabase, + ) -> EarlyBinder<'db, &'db [Clause<'db>]> { self.loc(db).predicates(db) } #[inline] pub fn self_predicates<'db>( self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ) -> EarlyBinder<'db, &'db [Clause<'db>]> { self.loc(db).self_predicates(db) } @@ -1557,7 +1563,7 @@ impl InternedOpaqueTyId<'_> { impl ImplTraits { #[salsa::tracked(returns(ref))] pub(crate) fn return_type_impl_traits( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: hir_def::FunctionId, ) -> Option>> { // FIXME unify with fn_sig_for_fn instead of doing lowering twice, maybe @@ -1590,7 +1596,7 @@ impl ImplTraits { #[salsa::tracked(returns(ref))] pub(crate) fn type_alias_impl_traits( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: hir_def::TypeAliasId, ) -> Option>> { let data = TypeAliasSignature::of(db, def); @@ -1641,7 +1647,7 @@ pub enum ValueTyDefId { impl_from!(FunctionId, StructId, UnionId, EnumVariantId, ConstId, StaticId for ValueTyDefId); impl ValueTyDefId { - pub(crate) fn to_generic_def_id(self, db: &dyn HirDatabase) -> GenericDefId { + pub(crate) fn to_generic_def_id(self, db: &dyn SourceDatabase) -> GenericDefId { match self { Self::FunctionId(id) => id.into(), Self::StructId(id) => id.into(), @@ -1657,7 +1663,10 @@ impl ValueTyDefId { /// `struct Foo(usize)`, we have two types: The type of the struct itself, and /// the constructor function `(usize) -> Foo` which lives in the values /// namespace. -pub(crate) fn ty_query<'db>(db: &'db dyn HirDatabase, def: TyDefId) -> EarlyBinder<'db, Ty<'db>> { +pub(crate) fn ty_query<'db>( + db: &'db dyn SourceDatabase, + def: TyDefId, +) -> EarlyBinder<'db, Ty<'db>> { let interner = DbInterner::new_no_crate(db); match def { TyDefId::BuiltinType(it) => EarlyBinder::bind(Ty::from_builtin_type(interner, it)), @@ -1672,7 +1681,7 @@ pub(crate) fn ty_query<'db>(db: &'db dyn HirDatabase, def: TyDefId) -> EarlyBind /// Build the declared type of a function. This should not need to look at the /// function body. -fn type_for_fn<'db>(db: &'db dyn HirDatabase, def: FunctionId) -> EarlyBinder<'db, Ty<'db>> { +fn type_for_fn<'db>(db: &'db dyn SourceDatabase, def: FunctionId) -> EarlyBinder<'db, Ty<'db>> { let interner = DbInterner::new_no_crate(db); EarlyBinder::bind(Ty::new_fn_def( interner, @@ -1682,7 +1691,7 @@ fn type_for_fn<'db>(db: &'db dyn HirDatabase, def: FunctionId) -> EarlyBinder<'d } pub(crate) fn type_for_const<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: ConstId, ) -> EarlyBinder<'db, Ty<'db>> { type_for_const_with_diagnostics(db, def).value.get() @@ -1691,7 +1700,7 @@ pub(crate) fn type_for_const<'db>( /// Build the declared type of a const. #[salsa::tracked(returns(ref))] pub(crate) fn type_for_const_with_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: ConstId, ) -> TyLoweringResult<'db, StoredEarlyBinder> { let resolver = def.resolver(db); @@ -1714,7 +1723,7 @@ pub(crate) fn type_for_const_with_diagnostics<'db>( } pub(crate) fn type_for_static<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: StaticId, ) -> EarlyBinder<'db, Ty<'db>> { type_for_static_with_diagnostics(db, def).value.get() @@ -1723,7 +1732,7 @@ pub(crate) fn type_for_static<'db>( /// Build the declared type of a static. #[salsa::tracked(returns(ref))] pub(crate) fn type_for_static_with_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: StaticId, ) -> TyLoweringResult<'db, StoredEarlyBinder> { let resolver = def.resolver(db); @@ -1746,7 +1755,7 @@ pub(crate) fn type_for_static_with_diagnostics<'db>( /// Build the type of a tuple struct constructor. fn type_for_struct_constructor<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: StructId, ) -> Option>> { let struct_data = StructSignature::of(db, def); @@ -1767,7 +1776,7 @@ fn type_for_struct_constructor<'db>( /// Build the type of a tuple enum variant constructor. fn type_for_enum_variant_constructor<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: EnumVariantId, ) -> Option>> { let struct_data = def.fields(db); @@ -1787,7 +1796,7 @@ fn type_for_enum_variant_constructor<'db>( } pub(crate) fn value_ty<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: ValueTyDefId, ) -> Option>> { match def { @@ -1802,7 +1811,7 @@ pub(crate) fn value_ty<'db>( #[salsa::tracked(returns(ref), cycle_result = type_for_type_alias_with_diagnostics_cycle_result)] pub(crate) fn type_for_type_alias_with_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, t: TypeAliasId, ) -> TyLoweringResult<'db, StoredEarlyBinder> { let type_alias_data = TypeAliasSignature::of(db, t); @@ -1837,7 +1846,7 @@ pub(crate) fn type_for_type_alias_with_diagnostics<'db>( } pub(crate) fn type_for_type_alias_with_diagnostics_cycle_result<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, _: salsa::Id, _adt: TypeAliasId, ) -> TyLoweringResult<'db, StoredEarlyBinder> { @@ -1847,7 +1856,7 @@ pub(crate) fn type_for_type_alias_with_diagnostics_cycle_result<'db>( } pub(crate) fn impl_self_ty_query<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, impl_id: ImplId, ) -> EarlyBinder<'db, Ty<'db>> { impl_self_ty_with_diagnostics(db, impl_id).value.get() @@ -1855,7 +1864,7 @@ pub(crate) fn impl_self_ty_query<'db>( #[salsa::tracked(returns(ref), cycle_result = impl_self_ty_with_diagnostics_cycle_result)] pub(crate) fn impl_self_ty_with_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, impl_id: ImplId, ) -> TyLoweringResult<'db, StoredEarlyBinder> { let resolver = impl_id.resolver(db); @@ -1877,7 +1886,7 @@ pub(crate) fn impl_self_ty_with_diagnostics<'db>( } pub(crate) fn impl_self_ty_with_diagnostics_cycle_result<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, _: salsa::Id, _impl_id: ImplId, ) -> TyLoweringResult<'db, StoredEarlyBinder> { @@ -1886,7 +1895,7 @@ pub(crate) fn impl_self_ty_with_diagnostics_cycle_result<'db>( )) } -pub(crate) fn const_param_ty<'db>(db: &'db dyn HirDatabase, def: ConstParamId) -> Ty<'db> { +pub(crate) fn const_param_ty<'db>(db: &'db dyn SourceDatabase, def: ConstParamId) -> Ty<'db> { let param_types = const_param_types(db, def.parent()); match param_types.get(def.local_id()) { Some(ty) => ty.as_ref(), @@ -1895,7 +1904,7 @@ pub(crate) fn const_param_ty<'db>(db: &'db dyn HirDatabase, def: ConstParamId) - } pub(crate) fn const_param_types( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: GenericDefId, ) -> &ArenaMap { &const_param_types_with_diagnostics(db, def).value @@ -1903,7 +1912,7 @@ pub(crate) fn const_param_types( #[salsa::tracked(returns(ref), cycle_result = const_param_types_with_diagnostics_cycle_result)] pub(crate) fn const_param_types_with_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: GenericDefId, ) -> TyLoweringResult<'db, ArenaMap> { let mut result = ArenaMap::new(); @@ -1931,7 +1940,7 @@ pub(crate) fn const_param_types_with_diagnostics<'db>( } fn const_param_types_with_diagnostics_cycle_result<'db>( - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, _: salsa::Id, _def: GenericDefId, ) -> TyLoweringResult<'db, ArenaMap> { @@ -1939,7 +1948,7 @@ fn const_param_types_with_diagnostics_cycle_result<'db>( } pub(crate) fn field_types_query( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, variant_id: VariantId, ) -> &ArenaMap { &field_types_with_diagnostics(db, variant_id).value @@ -1966,7 +1975,7 @@ impl FieldType { /// Build the type of all specific fields of a struct or enum variant. #[salsa::tracked(returns(ref))] pub(crate) fn field_types_with_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, variant_id: VariantId, ) -> TyLoweringResult<'db, ArenaMap> { let var_data = variant_id.fields(db); @@ -2016,11 +2025,11 @@ pub(crate) struct SupertraitsInfo { impl SupertraitsInfo { #[inline] - pub(crate) fn query(db: &dyn HirDatabase, trait_: TraitId) -> &Self { + pub(crate) fn query(db: &dyn SourceDatabase, trait_: TraitId) -> &Self { return supertraits_info(db, trait_); #[salsa::tracked(returns(ref), cycle_result = supertraits_info_cycle)] - fn supertraits_info(db: &dyn HirDatabase, trait_: TraitId) -> SupertraitsInfo { + fn supertraits_info(db: &dyn SourceDatabase, trait_: TraitId) -> SupertraitsInfo { let mut all_supertraits = FxHashSet::default(); let mut direct_supertraits = FxHashSet::default(); let mut defined_assoc_types = FxHashSet::default(); @@ -2074,7 +2083,7 @@ impl SupertraitsInfo { } fn supertraits_info_cycle( - _db: &dyn HirDatabase, + _db: &dyn SourceDatabase, _: salsa::Id, _trait_: TraitId, ) -> SupertraitsInfo { @@ -2112,7 +2121,7 @@ enum AssocTypeShorthandResolution { #[tracing::instrument(skip(db), ret)] #[salsa::tracked(returns(ref), cycle_result = resolve_type_param_assoc_type_shorthand_cycle_result)] fn resolve_type_param_assoc_type_shorthand( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: GenericDefId, param: TypeParamId, assoc_name: Name, @@ -2255,7 +2264,7 @@ fn resolve_type_param_assoc_type_shorthand( } fn resolve_type_param_assoc_type_shorthand_cycle_result( - _db: &dyn HirDatabase, + _db: &dyn SourceDatabase, _: salsa::Id, _def: GenericDefId, _param: TypeParamId, @@ -2266,7 +2275,7 @@ fn resolve_type_param_assoc_type_shorthand_cycle_result( #[inline] pub(crate) fn type_alias_bounds<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, type_alias: TypeAliasId, ) -> EarlyBinder<'db, &'db [Clause<'db>]> { type_alias_bounds_with_diagnostics(db, type_alias) @@ -2278,7 +2287,7 @@ pub(crate) fn type_alias_bounds<'db>( #[inline] pub(crate) fn type_alias_self_bounds<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, type_alias: TypeAliasId, ) -> EarlyBinder<'db, &'db [Clause<'db>]> { let TypeAliasBounds { predicates, assoc_ty_bounds_start } = @@ -2294,7 +2303,7 @@ pub struct TypeAliasBounds { #[salsa::tracked(returns(ref))] pub(crate) fn type_alias_bounds_with_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, type_alias: TypeAliasId, ) -> TyLoweringResult<'db, TypeAliasBounds>> { let type_alias_data = TypeAliasSignature::of(db, type_alias); @@ -2378,7 +2387,7 @@ impl<'db> GenericPredicates { /// Diagnostics are computed only for this item's predicates, not for parents. #[salsa::tracked(returns(ref), cycle_result=generic_predicates_cycle_result)] pub fn query_with_diagnostics( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: GenericDefId, ) -> TyLoweringResult<'db, GenericPredicates> { generic_predicates(db, def) @@ -2387,7 +2396,7 @@ impl<'db> GenericPredicates { /// A cycle can occur from malformed code. fn generic_predicates_cycle_result<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, _: salsa::Id, _def: GenericDefId, ) -> TyLoweringResult<'db, GenericPredicates> { @@ -2424,13 +2433,13 @@ impl GenericPredicates { } #[inline] - pub fn query(db: &dyn HirDatabase, def: GenericDefId) -> &GenericPredicates { + pub fn query(db: &dyn SourceDatabase, def: GenericDefId) -> &GenericPredicates { &Self::query_with_diagnostics(db, def).value } #[inline] pub fn query_all<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: GenericDefId, ) -> EarlyBinder<'db, impl Iterator>> { Self::query(db, def).all_predicates() @@ -2438,7 +2447,7 @@ impl GenericPredicates { #[inline] pub fn query_own_explicit<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: GenericDefId, ) -> EarlyBinder<'db, impl Iterator>> { Self::query(db, def).own_explicit_predicates() @@ -2446,7 +2455,7 @@ impl GenericPredicates { #[inline] pub fn query_explicit<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: GenericDefId, ) -> EarlyBinder<'db, impl Iterator>> { Self::query(db, def).explicit_predicates() @@ -2512,12 +2521,15 @@ pub(crate) fn param_env_from_predicates<'db>( ParamEnv { clauses } } -pub(crate) fn trait_environment<'db>(db: &'db dyn HirDatabase, def: GenericDefId) -> ParamEnv<'db> { +pub(crate) fn trait_environment<'db>( + db: &'db dyn SourceDatabase, + def: GenericDefId, +) -> ParamEnv<'db> { return ParamEnv { clauses: trait_environment_query(db, def).as_ref() }; #[salsa::tracked(returns(ref))] pub(crate) fn trait_environment_query( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: GenericDefId, ) -> StoredClauses { let module = def.module(db); @@ -2531,7 +2543,7 @@ pub(crate) fn trait_environment<'db>(db: &'db dyn HirDatabase, def: GenericDefId /// with a given filter #[tracing::instrument(skip(db), ret)] fn generic_predicates<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: GenericDefId, ) -> TyLoweringResult<'db, GenericPredicates> { let generics = generics(db, def); @@ -2700,7 +2712,7 @@ fn generic_predicates<'db>( } fn push_const_arg_has_type_predicates<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, predicates: &mut Vec>, single_generics: &SingleGenerics<'db>, ) { @@ -2737,7 +2749,10 @@ impl<'db> GenericDefaultsRef<'db> { } } -pub(crate) fn generic_defaults(db: &dyn HirDatabase, def: GenericDefId) -> GenericDefaultsRef<'_> { +pub(crate) fn generic_defaults( + db: &dyn SourceDatabase, + def: GenericDefId, +) -> GenericDefaultsRef<'_> { generic_defaults_with_diagnostics(db, def).value.as_ref() } @@ -2746,7 +2761,7 @@ pub(crate) fn generic_defaults(db: &dyn HirDatabase, def: GenericDefId) -> Gener /// Diagnostics are only returned for this `GenericDefId` (returned defaults include parents). #[salsa::tracked(returns(ref), cycle_result = generic_defaults_with_diagnostics_cycle_result)] pub(crate) fn generic_defaults_with_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: GenericDefId, ) -> TyLoweringResult<'db, GenericDefaults> { let generics = generics(db, def); @@ -2810,7 +2825,7 @@ pub(crate) fn generic_defaults_with_diagnostics<'db>( } fn generic_defaults_with_diagnostics_cycle_result<'db>( - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, _: salsa::Id, _def: GenericDefId, ) -> TyLoweringResult<'db, GenericDefaults> { @@ -2819,7 +2834,7 @@ fn generic_defaults_with_diagnostics_cycle_result<'db>( /// Build the signature of a callable item (function, struct or enum variant). pub(crate) fn callable_item_signature<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: CallableDefId, ) -> EarlyBinder<'db, PolyFnSig<'db>> { callable_item_signature_with_diagnostics(db, def).value.get() @@ -2827,7 +2842,7 @@ pub(crate) fn callable_item_signature<'db>( #[salsa::tracked(returns(ref))] pub(crate) fn callable_item_signature_with_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: CallableDefId, ) -> TyLoweringResult<'db, StoredEarlyBinder> { match def { @@ -2840,7 +2855,7 @@ pub(crate) fn callable_item_signature_with_diagnostics<'db>( } fn fn_sig_for_fn<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: FunctionId, ) -> TyLoweringResult<'db, StoredEarlyBinder> { let data = FunctionSignature::of(db, def); @@ -2894,7 +2909,7 @@ fn fn_sig_for_fn<'db>( TyLoweringResult::from_ctx(result, ctx_params) } -fn type_for_adt<'db>(db: &'db dyn HirDatabase, adt: AdtId) -> EarlyBinder<'db, Ty<'db>> { +fn type_for_adt<'db>(db: &'db dyn SourceDatabase, adt: AdtId) -> EarlyBinder<'db, Ty<'db>> { let interner = DbInterner::new_no_crate(db); let args = GenericArgs::identity_for_item(interner, adt.into()); let ty = Ty::new_adt(interner, adt, args); @@ -2902,7 +2917,7 @@ fn type_for_adt<'db>(db: &'db dyn HirDatabase, adt: AdtId) -> EarlyBinder<'db, T } fn fn_sig_for_struct_constructor( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: StructId, ) -> StoredEarlyBinder { let field_tys = db.field_types(def.into()); @@ -2918,7 +2933,7 @@ fn fn_sig_for_struct_constructor( } fn fn_sig_for_enum_variant_constructor( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: EnumVariantId, ) -> StoredEarlyBinder { let field_tys = db.field_types(def.into()); @@ -2936,7 +2951,7 @@ fn fn_sig_for_enum_variant_constructor( // FIXME: Remove this. pub(crate) fn associated_ty_item_bounds<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, type_alias: TypeAliasId, ) -> EarlyBinder<'db, BoundExistentialPredicates<'db>> { let type_alias_data = TypeAliasSignature::of(db, type_alias); @@ -3014,7 +3029,7 @@ pub(crate) fn associated_ty_item_bounds<'db>( } pub(crate) fn associated_type_by_name_including_super_traits_allow_ambiguity<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, trait_ref: TraitRef<'db>, name: Name, ) -> Option<(TypeAliasId, GenericArgs<'db>)> { diff --git a/crates/hir-ty/src/lower/path.rs b/crates/hir-ty/src/lower/path.rs index c67c69520db1..885f5dfd2b6a 100644 --- a/crates/hir-ty/src/lower/path.rs +++ b/crates/hir-ty/src/lower/path.rs @@ -1154,7 +1154,7 @@ fn check_generic_args_len<'db>( } pub(crate) fn substs_from_args_and_bindings<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, store: &ExpressionStore, args_and_bindings: Option<&HirGenericArgs>, def: GenericDefId, diff --git a/crates/hir-ty/src/method_resolution.rs b/crates/hir-ty/src/method_resolution.rs index 97e9d8bae190..aa01524222bd 100644 --- a/crates/hir-ty/src/method_resolution.rs +++ b/crates/hir-ty/src/method_resolution.rs @@ -81,7 +81,7 @@ pub enum CandidateId { impl_from!(FunctionId, ConstId for CandidateId); impl CandidateId { - fn container(self, db: &dyn HirDatabase) -> ItemContainerId { + fn container(self, db: &dyn SourceDatabase) -> ItemContainerId { match self { CandidateId::FunctionId(id) => id.loc(db).container, CandidateId::ConstId(id) => id.loc(db).container, @@ -413,7 +413,7 @@ pub fn is_dyn_method<'db>( /// /// Returns `func` if it's not a method defined in a trait or the lookup failed. pub(crate) fn lookup_impl_method_query<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, env: ParamEnvAndCrate<'db>, func: FunctionId, fn_subst: GenericArgs<'db>, @@ -517,7 +517,10 @@ pub(crate) fn find_matching_impl<'db>( } #[salsa::tracked(returns(ref))] -fn crates_containing_incoherent_inherent_impls(db: &dyn HirDatabase, krate: Crate) -> Box<[Crate]> { +fn crates_containing_incoherent_inherent_impls( + db: &dyn SourceDatabase, + krate: Crate, +) -> Box<[Crate]> { let _p = tracing::info_span!("crates_containing_incoherent_inherent_impls").entered(); // We assume that only sysroot crates contain `#[rustc_has_incoherent_inherent_impls]` // impls, since this is an internal feature and only std uses it. @@ -525,7 +528,7 @@ fn crates_containing_incoherent_inherent_impls(db: &dyn HirDatabase, krate: Crat } pub fn with_incoherent_inherent_impls<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, krate: Crate, self_ty: &SimplifiedType<'db>, mut callback: impl FnMut(&[ImplId]), @@ -549,7 +552,10 @@ pub fn with_incoherent_inherent_impls<'db>( } } -pub fn simplified_type_module(db: &dyn HirDatabase, ty: &SimplifiedType<'_>) -> Option { +pub fn simplified_type_module( + db: &dyn SourceDatabase, + ty: &SimplifiedType<'_>, +) -> Option { match ty.def()? { SolverDefId::AdtId(id) => Some(id.module(db)), SolverDefId::TypeAliasId(id) => Some(id.module(db)), @@ -567,7 +573,7 @@ pub struct InherentImpls<'db> { #[salsa::tracked] impl<'db> InherentImpls<'db> { #[salsa::tracked(returns(ref))] - pub fn for_crate(db: &'db dyn HirDatabase, krate: Crate) -> InherentImpls<'db> { + pub fn for_crate(db: &'db dyn SourceDatabase, krate: Crate) -> InherentImpls<'db> { let _p = tracing::info_span!("inherent_impls_in_crate_query", ?krate).entered(); let crate_def_map = crate_def_map(db, krate); @@ -577,7 +583,7 @@ impl<'db> InherentImpls<'db> { #[salsa::tracked(returns(ref))] pub fn for_block( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, block: BlockIdLt<'db>, ) -> Option>> { let _p = tracing::info_span!("inherent_impls_in_block_query").entered(); @@ -589,7 +595,7 @@ impl<'db> InherentImpls<'db> { } impl<'db> InherentImpls<'db> { - fn collect_def_map(db: &'db dyn HirDatabase, def_map: &'db DefMap) -> Self { + fn collect_def_map(db: &'db dyn SourceDatabase, def_map: &'db DefMap) -> Self { let mut map = FxHashMap::default(); collect(db, def_map, &mut map); let mut map = map @@ -600,7 +606,7 @@ impl<'db> InherentImpls<'db> { return Self { map }; fn collect<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def_map: &DefMap, map: &mut FxHashMap, Vec>, ) { @@ -633,7 +639,7 @@ impl<'db> InherentImpls<'db> { } pub fn for_each_crate_and_block( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, krate: Crate, block: Option>, for_each: &mut dyn FnMut(&InherentImpls<'db>), @@ -680,7 +686,7 @@ pub struct TraitImpls<'db> { #[salsa::tracked] impl<'db> TraitImpls<'db> { #[salsa::tracked(returns(ref))] - pub fn for_crate(db: &'db dyn HirDatabase, krate: Crate) -> Arc> { + pub fn for_crate(db: &'db dyn SourceDatabase, krate: Crate) -> Arc> { let _p = tracing::info_span!("inherent_impls_in_crate_query", ?krate).entered(); let crate_def_map = crate_def_map(db, krate); @@ -690,7 +696,7 @@ impl<'db> TraitImpls<'db> { #[salsa::tracked(returns(as_deref))] pub fn for_block( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, block: BlockIdLt<'db>, ) -> Option>> { let _p = tracing::info_span!("inherent_impls_in_block_query").entered(); @@ -701,13 +707,13 @@ impl<'db> TraitImpls<'db> { } #[salsa::tracked(returns(deref))] - pub fn for_crate_and_deps(db: &'db dyn HirDatabase, krate: Crate) -> Box<[Arc]> { + pub fn for_crate_and_deps(db: &'db dyn SourceDatabase, krate: Crate) -> Box<[Arc]> { krate.transitive_deps(db).iter().map(|&dep| Self::for_crate(db, dep).clone()).collect() } } impl<'db> TraitImpls<'db> { - fn collect_def_map(db: &'db dyn HirDatabase, def_map: &DefMap) -> Self { + fn collect_def_map(db: &'db dyn SourceDatabase, def_map: &DefMap) -> Self { let lang_items = hir_def::lang_item::lang_items(db, def_map.krate()); let mut map = FxHashMap::default(); collect(db, def_map, lang_items, &mut map); @@ -719,7 +725,7 @@ impl<'db> TraitImpls<'db> { return Self { map }; fn collect<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def_map: &DefMap, lang_items: &LangItems, map: &mut FxHashMap>, @@ -837,7 +843,7 @@ impl<'db> TraitImpls<'db> { } pub fn for_each_crate_and_block( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, krate: Crate, block: Option>, for_each: &mut dyn FnMut(&TraitImpls<'db>) -> R, @@ -854,7 +860,7 @@ impl<'db> TraitImpls<'db> { /// Like [`Self::for_each_crate_and_block()`], but takes in account two blocks, one for a trait and one for a self type. pub fn for_each_crate_and_block_trait_and_type( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, krate: Crate, type_block: Option>, trait_block: Option>, diff --git a/crates/hir-ty/src/method_resolution/confirm.rs b/crates/hir-ty/src/method_resolution/confirm.rs index 6d948464b1c0..c316365bd1c0 100644 --- a/crates/hir-ty/src/method_resolution/confirm.rs +++ b/crates/hir-ty/src/method_resolution/confirm.rs @@ -80,7 +80,7 @@ impl<'a, 'db> ConfirmContext<'a, 'db> { } #[inline] - fn db(&self) -> &'db dyn HirDatabase { + fn db(&self) -> &'db dyn SourceDatabase { self.ctx.table.infer_ctxt.interner.db } diff --git a/crates/hir-ty/src/method_resolution/probe.rs b/crates/hir-ty/src/method_resolution/probe.rs index 0a47e031b720..bb31737a0835 100644 --- a/crates/hir-ty/src/method_resolution/probe.rs +++ b/crates/hir-ty/src/method_resolution/probe.rs @@ -838,7 +838,7 @@ impl<'a, 'db, Choice: ProbeChoice<'db>> ProbeContext<'a, 'db, Choice> { } #[inline] - fn db(&self) -> &'db dyn HirDatabase { + fn db(&self) -> &'db dyn SourceDatabase { self.ctx.infcx.interner.db } diff --git a/crates/hir-ty/src/mir.rs b/crates/hir-ty/src/mir.rs index fe4b383fbe67..bac827d305d7 100644 --- a/crates/hir-ty/src/mir.rs +++ b/crates/hir-ty/src/mir.rs @@ -136,7 +136,7 @@ impl<'db> Operand { } fn from_fn( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, func_id: hir_def::FunctionId, generic_args: GenericArgs<'db>, ) -> Operand { diff --git a/crates/hir-ty/src/mir/borrowck.rs b/crates/hir-ty/src/mir/borrowck.rs index e860ae8d3e01..31b8cf2c8068 100644 --- a/crates/hir-ty/src/mir/borrowck.rs +++ b/crates/hir-ty/src/mir/borrowck.rs @@ -67,7 +67,7 @@ pub struct BorrowckResult<'db> { } impl<'db> BorrowckResult<'db> { - pub fn mir_body(&self, db: &'db dyn HirDatabase) -> &'db MirBody<'db> { + pub fn mir_body(&self, db: &'db dyn SourceDatabase) -> &'db MirBody<'db> { match self.owner { Either::Left(it) => db.mir_body(it).unwrap(), Either::Right(it) => db.mir_body_for_closure(it).unwrap(), @@ -76,7 +76,7 @@ impl<'db> BorrowckResult<'db> { } fn all_mir_bodies<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: InferBodyId<'db>, mut cb: impl FnMut( &'db MirBody<'db>, @@ -88,7 +88,7 @@ fn all_mir_bodies<'db>( ), ) -> Result]>, MirLowerError<'db>> { fn for_closure<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, c: InternedClosureId<'db>, results: &mut Vec<(BorrowckResult<'db>, &'db MirBody<'db>)>, cb: &mut impl FnMut( @@ -146,13 +146,13 @@ fn all_mir_bodies<'db>( impl<'db> InferBodyId<'db> { pub fn borrowck( self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ) -> Result<&'db [BorrowckResult<'db>], MirLowerError<'db>> { return borrowck_query(db, self).map_err(|e| e.clone()); #[salsa::tracked(returns(as_deref), lru = 2024)] fn borrowck_query<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: InferBodyId<'db>, ) -> Result]>, MirLowerError<'db>> { let _p = tracing::info_span!("InferBodyId::borrowck").entered(); @@ -384,7 +384,7 @@ fn partially_moved<'db>( result } -fn borrow_regions<'db>(db: &'db dyn HirDatabase, body: &MirBody<'db>) -> Vec { +fn borrow_regions<'db>(db: &'db dyn SourceDatabase, body: &MirBody<'db>) -> Vec { let mut borrows = FxHashMap::default(); for (_, block) in body.basic_blocks.iter() { db.unwind_if_revision_cancelled(); @@ -463,13 +463,13 @@ fn place_case<'db>( /// the start of the block. Only `StorageDead` can remove something from this map, and we ignore /// `Uninit` and `drop` and similar after initialization. fn ever_initialized_map( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, body: &MirBody<'_>, ) -> ArenaMap> { let mut result: ArenaMap> = body.basic_blocks.iter().map(|it| (it.0, ArenaMap::default())).collect(); fn dfs( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, body: &MirBody<'_>, l: LocalId, stack: &mut Vec, diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs index e968da5111ad..4df5ee664375 100644 --- a/crates/hir-ty/src/mir/eval.rs +++ b/crates/hir-ty/src/mir/eval.rs @@ -170,7 +170,7 @@ enum MirOrDynIndex<'db> { } pub struct Evaluator<'a, 'db> { - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, param_env: ParamEnvAndCrate<'db>, target_data_layout: &'db TargetDataLayout, stack: Vec, @@ -383,7 +383,7 @@ impl MirEvalError<'_> { pub fn pretty_print( &self, f: &mut String, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, span_formatter: impl Fn(FileId, TextRange) -> String, display_target: DisplayTarget, ) -> std::result::Result<(), std::fmt::Error> { @@ -612,7 +612,7 @@ impl MirOutput { } pub fn interpret_mir<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, body: &'db MirBody<'db>, // FIXME: This is workaround. Ideally, const generics should have a separate body (issue #7434), but now // they share their body with their parent, so in MIR lowering we have locals of the parent body, which @@ -655,7 +655,7 @@ const EXECUTION_LIMIT: usize = 10_000_000; impl<'a, 'db> Evaluator<'a, 'db> { pub fn new( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, owner: InferBodyId<'db>, assert_placeholder_ty_is_unused: bool, trait_env: Option>, @@ -3198,7 +3198,7 @@ impl<'a, 'db> Evaluator<'a, 'db> { } pub fn render_const_using_debug_impl<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, owner: InferBodyId<'db>, c: Allocation<'db>, ty: Ty<'db>, diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs index 620d768cff42..e0f89b49ebb7 100644 --- a/crates/hir-ty/src/mir/lower.rs +++ b/crates/hir-ty/src/mir/lower.rs @@ -86,7 +86,7 @@ struct MirLowerCtx<'a, 'db> { current_loop_blocks: Option, labeled_loop_blocks: FxHashMap, discr_temp: Option, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, store: &'a ExpressionStore, infer: &'a InferenceResult<'db>, types: &'db crate::next_solver::DefaultAny<'db>, @@ -172,7 +172,7 @@ impl MirLowerError<'_> { pub fn pretty_print( &self, f: &mut String, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, span_formatter: impl Fn(FileId, TextRange) -> String, display_target: DisplayTarget, ) -> std::result::Result<(), std::fmt::Error> { @@ -273,7 +273,7 @@ impl From for MirLowerError<'_> { impl MirLowerError<'_> { fn unresolved_path( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, p: &Path, display_target: DisplayTarget, owner: ExpressionStoreOwnerId, @@ -289,7 +289,7 @@ type Result<'db, T> = std::result::Result>; impl<'a, 'db> MirLowerCtx<'a, 'db> { fn new( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, owner: InferBodyId<'db>, store: &'a ExpressionStore, infer: &'a InferenceResult<'db>, @@ -2065,7 +2065,7 @@ impl<'a, 'db> MirLowerCtx<'a, 'db> { } fn convert_closure_capture_projections( - _db: &dyn HirDatabase, + _db: &dyn SourceDatabase, place: &HirPlace, ) -> impl Iterator { place.projections.iter().enumerate().map(|(i, proj)| match proj.kind { @@ -2086,7 +2086,7 @@ fn convert_closure_capture_projections( } fn cast_kind<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, source_ty: Ty<'db>, target_ty: Ty<'db>, ) -> Result<'db, CastKind> { @@ -2109,7 +2109,7 @@ fn cast_kind<'db>( #[salsa::tracked(returns(as_ref), cycle_result = mir_body_for_closure_cycle_result)] pub fn mir_body_for_closure_query<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, closure: InternedClosureId<'db>, ) -> Result<'db, MirBody<'db>> { let InternedClosure { owner: body_owner, expr, .. } = closure.loc(db); @@ -2267,7 +2267,7 @@ pub fn mir_body_for_closure_query<'db>( #[salsa::tracked(returns(as_ref), cycle_result = mir_body_cycle_result)] pub fn mir_body_query<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: InferBodyId<'db>, ) -> Result<'db, MirBody<'db>> { let krate = def.krate(db); @@ -2310,7 +2310,7 @@ pub fn mir_body_query<'db>( } fn mir_body_cycle_result<'db>( - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, _: salsa::Id, _def: InferBodyId<'db>, ) -> Result<'db, MirBody<'db>> { @@ -2318,7 +2318,7 @@ fn mir_body_cycle_result<'db>( } fn mir_body_for_closure_cycle_result<'db>( - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, _: salsa::Id, _def: InternedClosureId<'db>, ) -> Result<'db, MirBody<'db>> { @@ -2328,7 +2328,7 @@ fn mir_body_for_closure_cycle_result<'db>( /// Extracts params from `body.params`/`body.self_param` and the callable signature, /// then delegates to [`lower_to_mir_with_store`]. pub fn lower_body_to_mir<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, owner: InferBodyId<'db>, store: &ExpressionStore, infer: &InferenceResult<'db>, @@ -2368,7 +2368,7 @@ pub fn lower_body_to_mir<'db>( /// bindings with no owner); `false` when lowering an inline const or anonymous /// const (picks bindings owned by `root_expr`). pub fn lower_to_mir_with_store<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, owner: InferBodyId<'db>, store: &ExpressionStore, infer: &InferenceResult<'db>, diff --git a/crates/hir-ty/src/mir/monomorphization.rs b/crates/hir-ty/src/mir/monomorphization.rs index 976ef2c45f1c..e6143e65327a 100644 --- a/crates/hir-ty/src/mir/monomorphization.rs +++ b/crates/hir-ty/src/mir/monomorphization.rs @@ -100,7 +100,11 @@ impl<'db> FallibleTypeFolder> for Filler<'db> { } impl<'db> Filler<'db> { - fn new(db: &'db dyn HirDatabase, env: ParamEnvAndCrate<'db>, subst: GenericArgs<'db>) -> Self { + fn new( + db: &'db dyn SourceDatabase, + env: ParamEnvAndCrate<'db>, + subst: GenericArgs<'db>, + ) -> Self { let interner = DbInterner::new_with(db, env.krate); let infcx = interner.infer_ctxt().build(TypingMode::PostAnalysis); Self { infcx, trait_env: env, subst } @@ -237,7 +241,7 @@ impl<'db> Filler<'db> { #[salsa::tracked(returns(as_ref), cycle_result = monomorphized_mir_body_cycle_result)] pub fn monomorphized_mir_body_query<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, owner: InferBodyId<'db>, subst: StoredGenericArgs, trait_env: StoredParamEnvAndCrate, @@ -250,7 +254,7 @@ pub fn monomorphized_mir_body_query<'db>( } fn monomorphized_mir_body_cycle_result<'db>( - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, _: salsa::Id, _: InferBodyId<'db>, _: StoredGenericArgs, @@ -261,7 +265,7 @@ fn monomorphized_mir_body_cycle_result<'db>( #[salsa::tracked(returns(as_ref), cycle_result = monomorphized_mir_body_for_closure_cycle_result)] pub fn monomorphized_mir_body_for_closure_query<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, closure: InternedClosureId<'db>, subst: StoredGenericArgs, trait_env: StoredParamEnvAndCrate, @@ -274,7 +278,7 @@ pub fn monomorphized_mir_body_for_closure_query<'db>( } fn monomorphized_mir_body_for_closure_cycle_result<'db>( - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, _: salsa::Id, _: InternedClosureId<'db>, _: StoredGenericArgs, diff --git a/crates/hir-ty/src/mir/pretty.rs b/crates/hir-ty/src/mir/pretty.rs index 4a51b5113a43..af73a833b906 100644 --- a/crates/hir-ty/src/mir/pretty.rs +++ b/crates/hir-ty/src/mir/pretty.rs @@ -44,7 +44,7 @@ macro_rules! wln { } impl MirBody<'_> { - pub fn pretty_print(&self, db: &dyn HirDatabase, display_target: DisplayTarget) -> String { + pub fn pretty_print(&self, db: &dyn SourceDatabase, display_target: DisplayTarget) -> String { let hir_body = ExpressionStore::of(db, self.owner.expression_store_owner(db)); let mut ctx = MirPrettyCtx::new(self, hir_body, db, display_target); ctx.for_body(|this| match ctx.body.owner { @@ -88,7 +88,7 @@ impl MirBody<'_> { // String with lines is rendered poorly in `dbg` macros, which I use very much, so this // function exists to solve that. - pub fn dbg(&self, db: &dyn HirDatabase, display_target: DisplayTarget) -> impl Debug { + pub fn dbg(&self, db: &dyn SourceDatabase, display_target: DisplayTarget) -> impl Debug { struct StringDbg(String); impl Debug for StringDbg { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { @@ -102,7 +102,7 @@ impl MirBody<'_> { struct MirPrettyCtx<'a, 'db> { body: &'a MirBody<'db>, hir_body: &'a ExpressionStore, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, result: String, indent: String, local_to_binding: ArenaMap, @@ -189,7 +189,7 @@ impl<'a, 'db> MirPrettyCtx<'a, 'db> { fn new( body: &'a MirBody<'db>, hir_body: &'a ExpressionStore, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, display_target: DisplayTarget, ) -> Self { let local_to_binding = body.local_to_binding_map(); diff --git a/crates/hir-ty/src/next_solver.rs b/crates/hir-ty/src/next_solver.rs index 42fd31f2594d..443e3a76ad36 100644 --- a/crates/hir-ty/src/next_solver.rs +++ b/crates/hir-ty/src/next_solver.rs @@ -143,7 +143,7 @@ impl std::fmt::Debug for DefaultAny<'_> { } #[inline] -pub fn default_types<'db>(db: &'db dyn HirDatabase) -> &'db DefaultAny<'db> { +pub fn default_types<'db>(db: &'db dyn SourceDatabase) -> &'db DefaultAny<'db> { static TYPES: OnceLock> = OnceLock::new(); let interner = DbInterner::new_no_crate(db); diff --git a/crates/hir-ty/src/next_solver/consts/valtree.rs b/crates/hir-ty/src/next_solver/consts/valtree.rs index bef238670681..597a5552cb73 100644 --- a/crates/hir-ty/src/next_solver/consts/valtree.rs +++ b/crates/hir-ty/src/next_solver/consts/valtree.rs @@ -49,7 +49,7 @@ impl<'db> ValueConst<'db> { #[inline] pub fn try_to_bits( self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, param_env: ParamEnvAndCrate<'db>, ) -> Option { let (TyKind::Bool | TyKind::Char | TyKind::Uint(_) | TyKind::Int(_) | TyKind::Float(_)) = diff --git a/crates/hir-ty/src/next_solver/generics.rs b/crates/hir-ty/src/next_solver/generics.rs index 9558a8b2b312..aa39a04dc8bf 100644 --- a/crates/hir-ty/src/next_solver/generics.rs +++ b/crates/hir-ty/src/next_solver/generics.rs @@ -60,7 +60,7 @@ pub struct Generics<'db> { impl<'db> Generics<'db> { pub(crate) fn from_generic_def( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: GenericDefId, consider_late_bound: bool, ) -> Generics<'db> { @@ -72,7 +72,7 @@ impl<'db> Generics<'db> { } pub(crate) fn from_generic_def_plus_one( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: GenericDefId, additional_param: TypeParamId, consider_late_bound: bool, diff --git a/crates/hir-ty/src/next_solver/interner.rs b/crates/hir-ty/src/next_solver/interner.rs index 7554ca6bcd02..dcc084564506 100644 --- a/crates/hir-ty/src/next_solver/interner.rs +++ b/crates/hir-ty/src/next_solver/interner.rs @@ -351,7 +351,7 @@ pub trait WorldExposer { #[derive(Debug, Copy, Clone)] pub struct DbInterner<'db> { - pub(crate) db: &'db dyn HirDatabase, + pub(crate) db: &'db dyn SourceDatabase, krate: Option, lang_items: Option<&'db LangItems>, } @@ -366,7 +366,7 @@ impl<'db> DbInterner<'db> { pub fn conjure() -> DbInterner<'db> { // Here we can not reinit the cache since we do that when we attach the db. crate::with_attached_db(|db| DbInterner { - db: unsafe { std::mem::transmute::<&dyn HirDatabase, &'db dyn HirDatabase>(db) }, + db: unsafe { std::mem::transmute::<&dyn SourceDatabase, &'db dyn SourceDatabase>(db) }, krate: None, lang_items: None, }) @@ -376,13 +376,13 @@ impl<'db> DbInterner<'db> { /// As a rule of thumb, when you create an `InferCtxt`, you need to provide the crate (and the block). /// /// Elaboration is a special kind: it needs lang items (for `Sized`), therefore it needs `new_with()`. - pub fn new_no_crate(db: &'db dyn HirDatabase) -> Self { + pub fn new_no_crate(db: &'db dyn SourceDatabase) -> Self { // We do not reinit the cache here, since anything accessing the cache needs an InferCtxt, // and we panic when trying to construct an InferCtxt for an Interner without a crate. DbInterner { db, krate: None, lang_items: None } } - pub fn new_with(db: &'db dyn HirDatabase, krate: Crate) -> DbInterner<'db> { + pub fn new_with(db: &'db dyn SourceDatabase, krate: Crate) -> DbInterner<'db> { tls_cache::reinit_cache(db); DbInterner { db, @@ -394,7 +394,7 @@ impl<'db> DbInterner<'db> { } #[inline] - pub fn db(&self) -> &'db dyn HirDatabase { + pub fn db(&self) -> &'db dyn SourceDatabase { self.db } @@ -577,7 +577,7 @@ impl AdtDef { } #[inline] - pub fn repr(self, db: &dyn HirDatabase) -> ReprOptions { + pub fn repr(self, db: &dyn SourceDatabase) -> ReprOptions { if self.flags().contains(AdtFlags::HAS_REPR) { AttrFlags::repr_assume_has(db, self.def_id()).unwrap_or_default() } else { @@ -2013,7 +2013,7 @@ impl<'db> Interner for DbInterner<'db> { return SolverDefIds::new_from_slice(&result); struct CoroutinesVisitor<'a, 'db> { - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, owner: InferBodyId<'db>, store: &'db ExpressionStore, coroutines: &'a mut Vec>, @@ -2306,7 +2306,7 @@ impl<'db> DbInterner<'db> { } fn predicates_of<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def_id: SolverDefId<'db>, ) -> &'db GenericPredicates { match def_id { @@ -2401,19 +2401,19 @@ mod tls_db { use crate::db::HirDatabase; struct Attached { - database: Cell>>, + database: Cell>>, } impl Attached { #[inline] - fn attach(&self, db: &dyn HirDatabase, op: impl FnOnce() -> R) -> R { + fn attach(&self, db: &dyn SourceDatabase, op: impl FnOnce() -> R) -> R { struct DbGuard<'s> { state: Option<&'s Attached>, } impl<'s> DbGuard<'s> { #[inline] - fn new(attached: &'s Attached, db: &dyn HirDatabase) -> Self { + fn new(attached: &'s Attached, db: &dyn SourceDatabase) -> Self { match attached.database.get() { Some(current_db) => { let new_db = NonNull::from(db); @@ -2450,15 +2450,15 @@ mod tls_db { } #[inline] - fn attach_allow_change(&self, db: &dyn HirDatabase, op: impl FnOnce() -> R) -> R { + fn attach_allow_change(&self, db: &dyn SourceDatabase, op: impl FnOnce() -> R) -> R { struct DbGuard<'s> { state: &'s Attached, - prev: Option>, + prev: Option>, } impl<'s> DbGuard<'s> { #[inline] - fn new(attached: &'s Attached, db: &dyn HirDatabase) -> Self { + fn new(attached: &'s Attached, db: &dyn SourceDatabase) -> Self { let prev = attached.database.replace(Some(NonNull::from(db))); Self { state: attached, prev } } @@ -2480,7 +2480,7 @@ mod tls_db { } #[inline] - fn with(&self, op: impl FnOnce(&dyn HirDatabase) -> R) -> R { + fn with(&self, op: impl FnOnce(&dyn SourceDatabase) -> R) -> R { let db = self.database.get().expect("Try to use attached db, but not db is attached"); // SAFETY: The db is attached, so it must be valid. @@ -2493,17 +2493,17 @@ mod tls_db { } #[inline] - pub fn attach_db(db: &dyn HirDatabase, op: impl FnOnce() -> R) -> R { + pub fn attach_db(db: &dyn SourceDatabase, op: impl FnOnce() -> R) -> R { GLOBAL_DB.with(|global_db| global_db.attach(db, op)) } #[inline] - pub fn attach_db_allow_change(db: &dyn HirDatabase, op: impl FnOnce() -> R) -> R { + pub fn attach_db_allow_change(db: &dyn SourceDatabase, op: impl FnOnce() -> R) -> R { GLOBAL_DB.with(|global_db| global_db.attach_allow_change(db, op)) } #[inline] - pub fn with_attached_db(op: impl FnOnce(&dyn HirDatabase) -> R) -> R { + pub fn with_attached_db(op: impl FnOnce(&dyn SourceDatabase) -> R) -> R { GLOBAL_DB.with( #[inline] |a| a.with(op), @@ -2540,7 +2540,7 @@ mod tls_cache { static GLOBAL_CACHE: RefCell = const { RefCell::new(Cache::default()) }; } - pub(super) fn reinit_cache(db: &dyn HirDatabase) { + pub(super) fn reinit_cache(db: &dyn SourceDatabase) { GLOBAL_CACHE.with_borrow_mut(|handle| { let (db_nonce, revision) = db.nonce_and_revision(); if handle.revision != revision || db_nonce != handle.db_nonce { @@ -2551,7 +2551,7 @@ mod tls_cache { #[inline] pub(super) fn borrow_assume_valid<'db, T>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, f: impl FnOnce(&mut GlobalCache>) -> T, ) -> T { if cfg!(debug_assertions) { diff --git a/crates/hir-ty/src/next_solver/ty.rs b/crates/hir-ty/src/next_solver/ty.rs index 36c18ed772ca..a1311dff5b8f 100644 --- a/crates/hir-ty/src/next_solver/ty.rs +++ b/crates/hir-ty/src/next_solver/ty.rs @@ -737,7 +737,7 @@ impl<'db> Ty<'db> { } // FIXME: Should this be here? - pub fn impl_trait_bounds(self, db: &'db dyn HirDatabase) -> Option>> { + pub fn impl_trait_bounds(self, db: &'db dyn SourceDatabase) -> Option>> { let interner = DbInterner::new_no_crate(db); match self.kind() { diff --git a/crates/hir-ty/src/opaques.rs b/crates/hir-ty/src/opaques.rs index 9cb0022ca6bf..d87031417d2d 100644 --- a/crates/hir-ty/src/opaques.rs +++ b/crates/hir-ty/src/opaques.rs @@ -21,7 +21,7 @@ use crate::{ }; pub(crate) fn opaque_types_defined_by<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def_id: InferBodyId<'_>, result: &mut Vec>, ) { @@ -80,7 +80,7 @@ pub(crate) fn opaque_types_defined_by<'db>( // FIXME: Collect opaques from `#[define_opaque]`. fn extend_with_opaques<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, opaques: &Option>>, mut make_impl_trait: impl FnMut(ImplTraitIdx) -> ImplTraitId, result: &mut Vec>, @@ -98,7 +98,7 @@ pub(crate) fn opaque_types_defined_by<'db>( #[salsa::tracked(returns(ref))] pub(crate) fn rpit_hidden_types( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, function: FunctionId, ) -> ArenaMap> { let infer = InferenceResult::of(db, DefWithBodyId::from(function)); @@ -112,7 +112,7 @@ pub(crate) fn rpit_hidden_types( #[salsa::tracked(returns(ref))] pub(crate) fn tait_hidden_types( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, type_alias: TypeAliasId, ) -> ArenaMap> { // Call this first, to not perform redundant work if there are no TAITs. @@ -186,7 +186,7 @@ pub(crate) fn tait_hidden_types( } fn tait_defining_bodies( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, loc: &AssocItemLoc, ) -> Vec { let from_assoc_items = |assoc_items: &[(Name, AssocItemId)]| { diff --git a/crates/hir-ty/src/representability.rs b/crates/hir-ty/src/representability.rs index 828af20b7b10..f5c544e6b2bd 100644 --- a/crates/hir-ty/src/representability.rs +++ b/crates/hir-ty/src/representability.rs @@ -24,7 +24,7 @@ macro_rules! rtry { } #[salsa::tracked(cycle_result = representability_cycle)] -pub(crate) fn representability(db: &dyn HirDatabase, id: AdtId) -> Representability { +pub(crate) fn representability(db: &dyn SourceDatabase, id: AdtId) -> Representability { match id { AdtId::StructId(id) => variant_representability(db, id.into()), AdtId::UnionId(id) => variant_representability(db, id.into()), @@ -38,21 +38,21 @@ pub(crate) fn representability(db: &dyn HirDatabase, id: AdtId) -> Representabil } pub(crate) fn representability_cycle( - _db: &dyn HirDatabase, + _db: &dyn SourceDatabase, _: salsa::Id, _id: AdtId, ) -> Representability { Representability::Infinite } -fn variant_representability(db: &dyn HirDatabase, id: VariantId) -> Representability { +fn variant_representability(db: &dyn SourceDatabase, id: VariantId) -> Representability { for ty in db.field_types(id).values() { rtry!(representability_ty(db, ty.ty().instantiate_identity().skip_norm_wip())); } Representability::Representable } -fn representability_ty<'db>(db: &'db dyn HirDatabase, ty: Ty<'db>) -> Representability { +fn representability_ty<'db>(db: &'db dyn SourceDatabase, ty: Ty<'db>) -> Representability { match ty.kind() { TyKind::Adt(adt_id, args) => representability_adt_ty(db, adt_id.def_id(), args), // FIXME(#11924) allow zero-length arrays? @@ -68,7 +68,7 @@ fn representability_ty<'db>(db: &'db dyn HirDatabase, ty: Ty<'db>) -> Representa } fn representability_adt_ty<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def_id: AdtId, args: GenericArgs<'db>, ) -> Representability { @@ -87,7 +87,7 @@ fn representability_adt_ty<'db>( Representability::Representable } -fn params_in_repr(db: &dyn HirDatabase, def_id: AdtId) -> Box<[bool]> { +fn params_in_repr(db: &dyn SourceDatabase, def_id: AdtId) -> Box<[bool]> { let generics = GenericParams::of(db, def_id.into()); let mut params_in_repr = (0..generics.len_lifetimes() + generics.len_type_or_consts()) .map(|_| false) @@ -113,7 +113,7 @@ fn params_in_repr(db: &dyn HirDatabase, def_id: AdtId) -> Box<[bool]> { params_in_repr } -fn params_in_repr_ty<'db>(db: &'db dyn HirDatabase, ty: Ty<'db>, params_in_repr: &mut [bool]) { +fn params_in_repr_ty<'db>(db: &'db dyn SourceDatabase, ty: Ty<'db>, params_in_repr: &mut [bool]) { match ty.kind() { TyKind::Adt(adt, args) => { let inner_params_in_repr = self::params_in_repr(db, adt.def_id()); diff --git a/crates/hir-ty/src/specialization.rs b/crates/hir-ty/src/specialization.rs index 2d206fe38002..788cc708aafd 100644 --- a/crates/hir-ty/src/specialization.rs +++ b/crates/hir-ty/src/specialization.rs @@ -20,7 +20,7 @@ use crate::{ // create a cycle if there is an error in the impl's where clauses. I believe well formed code // cannot create a cycle, but a cycle handler is required nevertheless. fn specializes_query_cycle( - _db: &dyn HirDatabase, + _db: &dyn SourceDatabase, _: salsa::Id, _specializing_impl_def_id: ImplId, _parent_impl_def_id: ImplId, @@ -41,7 +41,7 @@ fn specializes_query_cycle( /// set of types. #[salsa::tracked(cycle_result = specializes_query_cycle)] fn specializes_query( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, specializing_impl_def_id: ImplId, parent_impl_def_id: ImplId, ) -> bool { @@ -135,7 +135,7 @@ fn specializes_query( // This function is used to avoid creating the query for crates that does not define `#![feature(specialization)]`, // as the solver is calling this a lot, and creating the query consumes a lot of memory. pub(crate) fn specializes( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, specializing_impl_def_id: ImplId, parent_impl_def_id: ImplId, ) -> bool { diff --git a/crates/hir-ty/src/target_feature.rs b/crates/hir-ty/src/target_feature.rs index 29a933f92263..670d996285c2 100644 --- a/crates/hir-ty/src/target_feature.rs +++ b/crates/hir-ty/src/target_feature.rs @@ -16,7 +16,7 @@ pub struct TargetFeatures<'db> { } impl<'db> TargetFeatures<'db> { - pub fn from_fn(db: &'db dyn HirDatabase, owner: FunctionId) -> Self { + pub fn from_fn(db: &'db dyn SourceDatabase, owner: FunctionId) -> Self { let mut result = TargetFeatures::from_fn_no_implications(db, owner); result.expand_implications(); result @@ -38,7 +38,7 @@ impl<'db> TargetFeatures<'db> { } /// Retrieves the target features from the attributes, and does not expand the target features implied by them. - pub(crate) fn from_fn_no_implications(db: &'db dyn HirDatabase, owner: FunctionId) -> Self { + pub(crate) fn from_fn_no_implications(db: &'db dyn SourceDatabase, owner: FunctionId) -> Self { let enabled = AttrFlags::target_features(db, owner); Self { enabled: Cow::Borrowed(enabled) } } diff --git a/crates/hir-ty/src/traits.rs b/crates/hir-ty/src/traits.rs index 108e3e07a666..ec1e102e4f57 100644 --- a/crates/hir-ty/src/traits.rs +++ b/crates/hir-ty/src/traits.rs @@ -61,12 +61,12 @@ pub struct StoredParamEnvAndCrate { impl StoredParamEnvAndCrate { #[inline] - pub fn param_env<'db>(&self, _db: &'db dyn HirDatabase) -> ParamEnv<'db> { + pub fn param_env<'db>(&self, _db: &'db dyn SourceDatabase) -> ParamEnv<'db> { ParamEnv { clauses: self.param_env.as_ref() } } #[inline] - pub fn as_ref<'db>(&self, db: &'db dyn HirDatabase) -> ParamEnvAndCrate<'db> { + pub fn as_ref<'db>(&self, db: &'db dyn SourceDatabase) -> ParamEnvAndCrate<'db> { ParamEnvAndCrate { param_env: self.param_env(db), krate: self.krate } } } @@ -123,7 +123,7 @@ impl FnTrait { /// This should not be used in `hir-ty`, only in `hir`. pub fn implements_trait_unique<'db>( ty: Ty<'db>, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, env: ParamEnvAndCrate<'db>, trait_: TraitId, ) -> bool { @@ -134,7 +134,7 @@ pub fn implements_trait_unique<'db>( /// This should not be used in `hir-ty`, only in `hir`. pub fn implements_trait_unique_with_args<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, env: ParamEnvAndCrate<'db>, trait_: TraitId, args: GenericArgs<'db>, @@ -143,7 +143,7 @@ pub fn implements_trait_unique_with_args<'db>( } pub fn implements_trait_unique_with_infcx<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, env: ParamEnvAndCrate<'db>, trait_: TraitId, create_args: &mut dyn FnMut(&InferCtxt<'db>) -> GenericArgs<'db>, @@ -173,7 +173,7 @@ pub enum WherePredicateEvaluation { /// This should not be used in `hir-ty`, only in `hir`. /// This is exposed to allow the IDE to evaluate arbitrary predicates. pub fn where_predicate_must_hold<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: &Resolver<'db>, store: &'db ExpressionStore, def: ExpressionStoreOwnerId, @@ -247,7 +247,11 @@ pub fn where_predicate_must_hold<'db>( } } -pub fn is_inherent_impl_coherent(db: &dyn HirDatabase, def_map: &DefMap, impl_id: ImplId) -> bool { +pub fn is_inherent_impl_coherent( + db: &dyn SourceDatabase, + def_map: &DefMap, + impl_id: ImplId, +) -> bool { let self_ty = db.impl_self_ty(impl_id).instantiate_identity().skip_norm_wip(); let self_ty = self_ty.kind(); let impl_allowed = match self_ty { @@ -331,7 +335,7 @@ pub fn is_inherent_impl_coherent(db: &dyn HirDatabase, def_map: &DefMap, impl_id /// - All of /// - At least one of the types `T0..=Tn` must be a local type. Let `Ti` be the first such type. /// - No uncovered type parameters `P1..=Pn` may appear in `T0..Ti` (excluding `Ti`) -pub fn check_orphan_rules<'db>(db: &'db dyn HirDatabase, impl_: ImplId) -> bool { +pub fn check_orphan_rules<'db>(db: &'db dyn SourceDatabase, impl_: ImplId) -> bool { let Some(impl_trait) = db.impl_trait(impl_) else { // not a trait impl return true; diff --git a/crates/hir-ty/src/upvars.rs b/crates/hir-ty/src/upvars.rs index 6dcd8b59a558..9d8678ad53b0 100644 --- a/crates/hir-ty/src/upvars.rs +++ b/crates/hir-ty/src/upvars.rs @@ -71,7 +71,7 @@ impl UpvarsRef<'_> { /// Returns a map from `Expr::Closure` to its upvars. pub fn upvars_mentioned( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, owner: ExpressionStoreOwnerId, ) -> Option<&FxHashMap> { return match owner { @@ -82,7 +82,7 @@ pub fn upvars_mentioned( #[salsa::tracked(returns(as_deref))] pub fn signature_upvars_mentioned( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, owner: GenericDefId, ) -> Option>> { upvars_mentioned_impl(db, owner.into()) @@ -90,7 +90,7 @@ pub fn upvars_mentioned( #[salsa::tracked(returns(as_deref))] pub fn body_upvars_mentioned( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, owner: DefWithBodyId, ) -> Option>> { upvars_mentioned_impl(db, owner.into()) @@ -98,7 +98,7 @@ pub fn upvars_mentioned( #[salsa::tracked(returns(as_deref))] pub fn variant_fields_upvars_mentioned( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, owner: VariantId, ) -> Option>> { upvars_mentioned_impl(db, owner.into()) @@ -106,7 +106,7 @@ pub fn upvars_mentioned( } pub fn upvars_mentioned_impl( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, owner: ExpressionStoreOwnerId, ) -> Option>> { let store = ExpressionStore::of(db, owner); @@ -124,7 +124,7 @@ pub fn upvars_mentioned_impl( }; fn handle_expr_outside_closure<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: &mut Resolver<'db>, owner: ExpressionStoreOwnerId, body: &ExpressionStore, @@ -155,7 +155,7 @@ pub fn upvars_mentioned_impl( } fn handle_expr_inside_closure<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: &mut Resolver<'db>, owner: ExpressionStoreOwnerId, body: &ExpressionStore, @@ -220,7 +220,7 @@ pub fn upvars_mentioned_impl( } fn resolve_maybe_upvar<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: &mut Resolver<'db>, owner: ExpressionStoreOwnerId, body: &ExpressionStore, diff --git a/crates/hir-ty/src/utils.rs b/crates/hir-ty/src/utils.rs index 53d723156281..d8559ddcc9f6 100644 --- a/crates/hir-ty/src/utils.rs +++ b/crates/hir-ty/src/utils.rs @@ -24,12 +24,12 @@ pub(crate) fn fn_traits(lang_items: &LangItems) -> impl Iterator } /// Returns an iterator over the direct super traits (including the trait itself). -pub fn direct_super_traits(db: &dyn HirDatabase, trait_: TraitId) -> &[TraitId] { +pub fn direct_super_traits(db: &dyn SourceDatabase, trait_: TraitId) -> &[TraitId] { &SupertraitsInfo::query(db, trait_).direct_supertraits } /// Returns the whole super trait hierarchy (including the trait itself). -pub fn all_super_traits(db: &dyn HirDatabase, trait_: TraitId) -> &[TraitId] { +pub fn all_super_traits(db: &dyn SourceDatabase, trait_: TraitId) -> &[TraitId] { &SupertraitsInfo::query(db, trait_).all_supertraits } @@ -55,7 +55,7 @@ pub fn target_feature_is_safe_in_target(target: &TargetData) -> TargetFeatureIsS } pub fn is_fn_unsafe_to_call( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, func: FunctionId, caller_target_features: &TargetFeatures<'_>, call_edition: Edition, @@ -95,7 +95,7 @@ pub fn is_fn_unsafe_to_call( pub(crate) fn detect_variant_from_bytes<'a>( layout: &'a Layout, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, target_data_layout: &TargetDataLayout, b: &[u8], e: EnumId, diff --git a/crates/hir-ty/src/variance.rs b/crates/hir-ty/src/variance.rs index 9e0435308776..938bd9776b69 100644 --- a/crates/hir-ty/src/variance.rs +++ b/crates/hir-ty/src/variance.rs @@ -30,7 +30,7 @@ use crate::{ }, }; -pub(crate) fn variances_of(db: &dyn HirDatabase, def: GenericDefId) -> VariancesOf<'_> { +pub(crate) fn variances_of(db: &dyn SourceDatabase, def: GenericDefId) -> VariancesOf<'_> { variances_of_query(db, def).as_ref() } @@ -39,7 +39,7 @@ pub(crate) fn variances_of(db: &dyn HirDatabase, def: GenericDefId) -> Variances cycle_fn = crate::variance::variances_of_cycle_fn, cycle_initial = crate::variance::variances_of_cycle_initial, )] -fn variances_of_query(db: &dyn HirDatabase, def: GenericDefId) -> StoredVariancesOf { +fn variances_of_query(db: &dyn SourceDatabase, def: GenericDefId) -> StoredVariancesOf { tracing::debug!("variances_of(def={:?})", def); match def { GenericDefId::FunctionId(_) => (), @@ -70,7 +70,7 @@ fn variances_of_query(db: &dyn HirDatabase, def: GenericDefId) -> StoredVariance } pub(crate) fn variances_of_cycle_fn( - _db: &dyn HirDatabase, + _db: &dyn SourceDatabase, _: &salsa::Cycle<'_>, _last_provisional_value: &StoredVariancesOf, value: StoredVariancesOf, @@ -100,7 +100,7 @@ fn glb(v1: Variance, v2: Variance) -> Variance { } pub(crate) fn variances_of_cycle_initial( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, _: salsa::Id, def: GenericDefId, ) -> StoredVariancesOf { @@ -112,7 +112,7 @@ pub(crate) fn variances_of_cycle_initial( } struct Context<'db> { - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, generics: Generics<'db>, variances: Box<[Variance]>, } diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index 9a61885ccb70..e7675f5113b2 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs @@ -61,21 +61,21 @@ pub struct AttrsWithOwner { } impl AttrsWithOwner { - fn new(db: &dyn HirDatabase, owner: AttrDefId) -> Self { + fn new(db: &dyn SourceDatabase, owner: AttrDefId) -> Self { Self { attrs: AttrFlags::query(db, owner), owner: AttrsOwner::AttrDef(owner) } } - fn new_field(db: &dyn HirDatabase, owner: FieldId) -> Self { + fn new_field(db: &dyn SourceDatabase, owner: FieldId) -> Self { Self { attrs: AttrFlags::query_field(db, owner), owner: AttrsOwner::Field(owner) } } - fn new_lifetime_param(db: &dyn HirDatabase, owner: LifetimeParamId) -> Self { + fn new_lifetime_param(db: &dyn SourceDatabase, owner: LifetimeParamId) -> Self { Self { attrs: AttrFlags::query_lifetime_param(db, owner), owner: AttrsOwner::LifetimeParam(owner), } } - fn new_type_or_const_param(db: &dyn HirDatabase, owner: TypeOrConstParamId) -> Self { + fn new_type_or_const_param(db: &dyn SourceDatabase, owner: TypeOrConstParamId) -> Self { Self { attrs: AttrFlags::query_type_or_const_param(db, owner), owner: AttrsOwner::TypeOrConstParam(owner), @@ -90,7 +90,7 @@ impl AttrsWithOwner { /// Currently, it could be that `is_unstable() == true` but `unstable_feature == None` /// (due to unstable features not being retrieved for fields etc.). #[inline] - pub fn unstable_feature(&self, db: &dyn HirDatabase) -> Option { + pub fn unstable_feature(&self, db: &dyn SourceDatabase) -> Option { match self.owner { AttrsOwner::AttrDef(owner) => self.attrs.unstable_feature(db, owner), AttrsOwner::Field(_) @@ -131,7 +131,7 @@ impl AttrsWithOwner { } #[inline] - pub fn lang(&self, db: &dyn HirDatabase) -> Option { + pub fn lang(&self, db: &dyn SourceDatabase) -> Option { self.owner .attr_def() .and_then(|owner| self.attrs.lang_item_with_attrs(db, owner)) @@ -139,7 +139,7 @@ impl AttrsWithOwner { } #[inline] - pub fn doc_aliases<'db>(&self, db: &'db dyn HirDatabase) -> &'db [Symbol] { + pub fn doc_aliases<'db>(&self, db: &'db dyn SourceDatabase) -> &'db [Symbol] { let owner = match self.owner { AttrsOwner::AttrDef(it) => Either::Left(it), AttrsOwner::Field(it) => Either::Right(it), @@ -151,7 +151,7 @@ impl AttrsWithOwner { } #[inline] - pub fn cfgs<'db>(&self, db: &'db dyn HirDatabase) -> Option<&'db CfgExpr> { + pub fn cfgs<'db>(&self, db: &'db dyn SourceDatabase) -> Option<&'db CfgExpr> { let owner = match self.owner { AttrsOwner::AttrDef(it) => Either::Left(it), AttrsOwner::Field(it) => Either::Right(it), @@ -163,7 +163,7 @@ impl AttrsWithOwner { } #[inline] - pub fn hir_docs<'db>(&self, db: &'db dyn HirDatabase) -> Option<&'db Docs> { + pub fn hir_docs<'db>(&self, db: &'db dyn SourceDatabase) -> Option<&'db Docs> { match self.owner { AttrsOwner::AttrDef(it) => AttrFlags::docs(db, it).as_deref(), AttrsOwner::Field(it) => AttrFlags::field_docs(db, it), @@ -176,7 +176,7 @@ impl AttrsWithOwner { pub trait HasAttrs: Sized { #[inline] - fn attrs(self, db: &dyn HirDatabase) -> AttrsWithOwner { + fn attrs(self, db: &dyn SourceDatabase) -> AttrsWithOwner { match self.attr_id(db) { AttrsOwner::AttrDef(it) => AttrsWithOwner::new(db, it), AttrsOwner::Field(it) => AttrsWithOwner::new_field(db, it), @@ -189,10 +189,10 @@ pub trait HasAttrs: Sized { } #[doc(hidden)] - fn attr_id(self, db: &dyn HirDatabase) -> AttrsOwner; + fn attr_id(self, db: &dyn SourceDatabase) -> AttrsOwner; #[inline] - fn hir_docs(self, db: &dyn HirDatabase) -> Option<&Docs> { + fn hir_docs(self, db: &dyn SourceDatabase) -> Option<&Docs> { match self.attr_id(db) { AttrsOwner::AttrDef(it) => AttrFlags::docs(db, it).as_deref(), AttrsOwner::Field(it) => AttrFlags::field_docs(db, it), @@ -207,7 +207,7 @@ macro_rules! impl_has_attrs { ($(($def:ident, $def_id:ident),)*) => {$( impl HasAttrs for $def { #[inline] - fn attr_id(self, _db: &dyn HirDatabase) -> AttrsOwner { + fn attr_id(self, _db: &dyn SourceDatabase) -> AttrsOwner { AttrsOwner::AttrDef(AttrDefId::$def_id(self.into())) } } @@ -226,7 +226,7 @@ impl_has_attrs![ ]; impl HasAttrs for Function { - fn attr_id(self, _db: &dyn HirDatabase) -> AttrsOwner { + fn attr_id(self, _db: &dyn SourceDatabase) -> AttrsOwner { match self.id { crate::AnyFunctionId::FunctionId(id) => AttrsOwner::AttrDef(id.into()), crate::AnyFunctionId::BuiltinDeriveImplMethod { .. } => AttrsOwner::Dummy, @@ -235,7 +235,7 @@ impl HasAttrs for Function { } impl HasAttrs for Impl { - fn attr_id(self, _db: &dyn HirDatabase) -> AttrsOwner { + fn attr_id(self, _db: &dyn SourceDatabase) -> AttrsOwner { match self.id { hir_ty::next_solver::AnyImplId::ImplId(id) => AttrsOwner::AttrDef(id.into()), hir_ty::next_solver::AnyImplId::BuiltinDeriveImplId(..) => AttrsOwner::Dummy, @@ -247,7 +247,7 @@ macro_rules! impl_has_attrs_enum { ($($variant:ident),* for $enum:ident) => {$( impl HasAttrs for $variant { #[inline] - fn attr_id(self, db: &dyn HirDatabase) -> AttrsOwner { + fn attr_id(self, db: &dyn SourceDatabase) -> AttrsOwner { $enum::$variant(self).attr_id(db) } } @@ -259,14 +259,14 @@ impl_has_attrs_enum![TypeParam, ConstParam, LifetimeParam for GenericParam]; impl HasAttrs for Module { #[inline] - fn attr_id(self, _: &dyn HirDatabase) -> AttrsOwner { + fn attr_id(self, _: &dyn SourceDatabase) -> AttrsOwner { AttrsOwner::AttrDef(AttrDefId::ModuleId(self.id)) } } impl HasAttrs for GenericParam { #[inline] - fn attr_id(self, _db: &dyn HirDatabase) -> AttrsOwner { + fn attr_id(self, _db: &dyn SourceDatabase) -> AttrsOwner { match self { GenericParam::TypeParam(it) => AttrsOwner::TypeOrConstParam(it.merge().into()), GenericParam::ConstParam(it) => AttrsOwner::TypeOrConstParam(it.merge().into()), @@ -277,7 +277,7 @@ impl HasAttrs for GenericParam { impl HasAttrs for AssocItem { #[inline] - fn attr_id(self, db: &dyn HirDatabase) -> AttrsOwner { + fn attr_id(self, db: &dyn SourceDatabase) -> AttrsOwner { match self { AssocItem::Function(it) => it.attr_id(db), AssocItem::Const(it) => it.attr_id(db), @@ -288,21 +288,21 @@ impl HasAttrs for AssocItem { impl HasAttrs for crate::Crate { #[inline] - fn attr_id(self, db: &dyn HirDatabase) -> AttrsOwner { + fn attr_id(self, db: &dyn SourceDatabase) -> AttrsOwner { self.root_module(db).attr_id(db) } } impl HasAttrs for Field { #[inline] - fn attr_id(self, _db: &dyn HirDatabase) -> AttrsOwner { + fn attr_id(self, _db: &dyn SourceDatabase) -> AttrsOwner { AttrsOwner::Field(self.into()) } } /// Resolves the item `link` points to in the scope of `def`. pub fn resolve_doc_path_on( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: impl HasAttrs + Copy, link: &str, ns: Option, @@ -312,7 +312,7 @@ pub fn resolve_doc_path_on( } fn resolve_doc_path_on_( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, link: &str, attr_id: AttrsOwner, ns: Option, @@ -368,7 +368,7 @@ fn resolve_doc_path_on_( } fn resolve_assoc_or_field( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, resolver: Resolver<'_>, path: ModPath, name: Name, @@ -466,7 +466,7 @@ fn resolve_assoc_or_field( } fn resolve_assoc_item<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ty: &Type<'db>, name: &Name, ns: Option, @@ -480,7 +480,7 @@ fn resolve_assoc_item<'db>( } fn resolve_impl_trait_item<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: Resolver<'_>, ty: &Type<'db>, name: &Name, @@ -522,7 +522,7 @@ fn resolve_impl_trait_item<'db>( } fn resolve_field( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: Variant, name: Name, ns: Option, diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index 0c4191ce2dd6..be661f9cf705 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -701,7 +701,7 @@ pub struct ReturnOutsideFunction { impl<'db> AnyDiagnostic<'db> { pub(crate) fn body_validation_diagnostic( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, diagnostic: BodyValidationDiagnostic<'db>, source_map: &hir_def::expr_store::BodySourceMap, ) -> Option> { @@ -833,7 +833,7 @@ impl<'db> AnyDiagnostic<'db> { } pub(crate) fn inference_diagnostic( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: DefWithBodyId, d: &'db InferenceDiagnostic, source_map: &hir_def::expr_store::BodySourceMap, @@ -1203,7 +1203,7 @@ impl<'db> AnyDiagnostic<'db> { } fn solver_diagnostic( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, d: &'db SolverDiagnosticKind, span: SpanSyntax, type_owner: TypeOwnerId<'db>, @@ -1382,7 +1382,7 @@ impl<'db> AnyDiagnostic<'db> { pub(crate) fn ty_diagnostic( diag: &TyLoweringDiagnostic, source_map: &ExpressionStoreSourceMap, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ) -> Option> { Some(match diag { TyLoweringDiagnostic::PathDiagnostic { source, diag } => { diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 61eda80fb487..81dc80510ddc 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -773,7 +773,7 @@ fn write_where_clause<'db>(def: GenericDefId, f: &mut HirFormatter<'_, 'db>) -> } fn has_disaplayable_predicates( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, params: &GenericParams, store: &ExpressionStore, ) -> bool { diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index 3a6e19636a0b..5aca9c2fb844 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs @@ -27,7 +27,7 @@ pub trait HasSource: Sized { /// The current some implementations can return `InFile` instead of `Option`. /// But we made this method `Option` to support rlib in the future /// by - fn source(self, db: &dyn HirDatabase) -> Option>; + fn source(self, db: &dyn SourceDatabase) -> Option>; /// Fetches the source node, along with its full range. /// @@ -37,7 +37,7 @@ pub trait HasSource: Sized { /// and if the node is supported too it will return it as well. fn source_with_range( self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, ) -> Option)>> { let source = self.source(db)?; Some(source.map(|node| (node.syntax().text_range(), Some(node)))) @@ -48,23 +48,23 @@ pub trait HasSource: Sized { /// definition and declaration. impl Module { /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. - pub fn definition_source(self, db: &dyn HirDatabase) -> InFile { + pub fn definition_source(self, db: &dyn SourceDatabase) -> InFile { let def_map = self.id.def_map(db); def_map[self.id].definition_source(db) } /// Returns a node which defines this module. That is, a file or a `mod foo {}` with items. - pub fn definition_source_range(self, db: &dyn HirDatabase) -> InFile { + pub fn definition_source_range(self, db: &dyn SourceDatabase) -> InFile { let def_map = self.id.def_map(db); def_map[self.id].definition_source_range(db) } - pub fn definition_source_file_id(self, db: &dyn HirDatabase) -> HirFileId { + pub fn definition_source_file_id(self, db: &dyn SourceDatabase) -> HirFileId { let def_map = self.id.def_map(db); def_map[self.id].definition_source_file_id() } - pub fn is_mod_rs(self, db: &dyn HirDatabase) -> bool { + pub fn is_mod_rs(self, db: &dyn SourceDatabase) -> bool { let def_map = self.id.def_map(db); match def_map[self.id].origin { ModuleOrigin::File { is_mod_rs, .. } => is_mod_rs, @@ -72,7 +72,7 @@ impl Module { } } - pub fn as_source_file_id(self, db: &dyn HirDatabase) -> Option { + pub fn as_source_file_id(self, db: &dyn SourceDatabase) -> Option { let def_map = self.id.def_map(db); match def_map[self.id].origin { ModuleOrigin::File { definition, .. } | ModuleOrigin::CrateRoot { definition, .. } => { @@ -82,21 +82,21 @@ impl Module { } } - pub fn is_inline(self, db: &dyn HirDatabase) -> bool { + pub fn is_inline(self, db: &dyn SourceDatabase) -> bool { let def_map = self.id.def_map(db); def_map[self.id].origin.is_inline() } /// Returns a node which declares this module, either a `mod foo;` or a `mod foo {}`. /// `None` for the crate root. - pub fn declaration_source(self, db: &dyn HirDatabase) -> Option> { + pub fn declaration_source(self, db: &dyn SourceDatabase) -> Option> { let def_map = self.id.def_map(db); def_map[self.id].declaration_source(db) } /// Returns a text range which declares this module, either a `mod foo;` or a `mod foo {}`. /// `None` for the crate root. - pub fn declaration_source_range(self, db: &dyn HirDatabase) -> Option> { + pub fn declaration_source_range(self, db: &dyn SourceDatabase) -> Option> { let def_map = self.id.def_map(db); def_map[self.id].declaration_source_range(db) } @@ -104,7 +104,7 @@ impl Module { impl HasSource for Field { type Ast = FieldSource; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { let var = VariantId::from(self.parent); let src = var.child_source(db); let field_source = src.map(|it| match it[self.id].clone() { @@ -116,7 +116,7 @@ impl HasSource for Field { } impl HasSource for Adt { type Ast = ast::Adt; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { match self { Adt::Struct(s) => Some(s.source(db)?.map(ast::Adt::Struct)), Adt::Union(u) => Some(u.source(db)?.map(ast::Adt::Union)), @@ -126,7 +126,7 @@ impl HasSource for Adt { } impl HasSource for Variant { type Ast = ast::VariantDef; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { match self { Variant::Struct(s) => Some(s.source(db)?.map(ast::VariantDef::Struct)), Variant::Union(u) => Some(u.source(db)?.map(ast::VariantDef::Union)), @@ -136,31 +136,31 @@ impl HasSource for Variant { } impl HasSource for Struct { type Ast = ast::Struct; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { Some(self.id.lookup(db).source(db)) } } impl HasSource for Union { type Ast = ast::Union; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { Some(self.id.lookup(db).source(db)) } } impl HasSource for Enum { type Ast = ast::Enum; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { Some(self.id.lookup(db).source(db)) } } impl HasSource for EnumVariant { type Ast = ast::Variant; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { Some(self.id.lookup(db).source(db)) } } impl HasSource for Function { type Ast = ast::Fn; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { match self.id { AnyFunctionId::FunctionId(id) => Some(id.loc(db).source(db)), // When calling `source()`, we use the trait method source, but when calling `source_with_range()`, @@ -175,7 +175,7 @@ impl HasSource for Function { fn source_with_range( self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, ) -> Option)>> { match self.id { AnyFunctionId::FunctionId(id) => Some( @@ -189,31 +189,31 @@ impl HasSource for Function { } impl HasSource for Const { type Ast = ast::Const; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { Some(self.id.lookup(db).source(db)) } } impl HasSource for Static { type Ast = ast::Static; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { Some(self.id.lookup(db).source(db)) } } impl HasSource for Trait { type Ast = ast::Trait; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { Some(self.id.lookup(db).source(db)) } } impl HasSource for TypeAlias { type Ast = ast::TypeAlias; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { Some(self.id.lookup(db).source(db)) } } impl HasSource for Macro { type Ast = Either; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { match self.id { MacroId::Macro2Id(it) => { Some(it.lookup(db).source(db).map(ast::Macro::MacroDef).map(Either::Left)) @@ -227,7 +227,7 @@ impl HasSource for Macro { } impl HasSource for Impl { type Ast = ast::Impl; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { match self.id { AnyImplId::ImplId(id) => Some(id.loc(db).source(db)), AnyImplId::BuiltinDeriveImplId(_) => None, @@ -236,7 +236,7 @@ impl HasSource for Impl { fn source_with_range( self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, ) -> Option)>> { match self.id { AnyImplId::ImplId(id) => Some( @@ -251,7 +251,7 @@ impl HasSource for Impl { impl HasSource for TypeOrConstParam { type Ast = Either; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { let child_source = self.id.parent.child_source(db); child_source.map(|it| it.get(self.id.local_id).cloned()).transpose() } @@ -259,7 +259,7 @@ impl HasSource for TypeOrConstParam { impl HasSource for LifetimeParam { type Ast = ast::LifetimeParam; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { let child_source = self.id.parent.child_source(db); child_source.map(|it| it.get(self.id.local_id).cloned()).transpose() } @@ -268,7 +268,7 @@ impl HasSource for LifetimeParam { impl HasSource for LocalSource<'_> { type Ast = Either; - fn source(self, _: &dyn HirDatabase) -> Option> { + fn source(self, _: &dyn SourceDatabase) -> Option> { Some(self.source) } } @@ -276,7 +276,7 @@ impl HasSource for LocalSource<'_> { impl HasSource for Param<'_> { type Ast = Either; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { match self.func { Callee::Def(CallableDefId::FunctionId(func)) => { let InFile { file_id, value } = Function::from(func).source(db)?; @@ -316,7 +316,7 @@ impl HasSource for Param<'_> { impl HasSource for SelfParam { type Ast = ast::SelfParam; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { let InFile { file_id, value } = self.func.source(db)?; value .param_list() @@ -328,7 +328,7 @@ impl HasSource for SelfParam { impl HasSource for Label { type Ast = ast::Label; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { let src = ExpressionStore::with_source_map(db, self.parent).1.label_syntax(self.label_id); let root = src.file_syntax(db); src.map(|ast| ast.to_node(&root).left()).transpose() @@ -338,14 +338,14 @@ impl HasSource for Label { impl HasSource for ExternCrateDecl { type Ast = ast::ExternCrate; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { Some(self.id.lookup(db).source(db)) } } impl HasSource for InlineAsmOperand { type Ast = ast::AsmOperandNamed; - fn source(self, db: &dyn HirDatabase) -> Option> { + fn source(self, db: &dyn SourceDatabase) -> Option> { let (_, source_map) = ExpressionStore::with_source_map(db, self.owner); if let Ok(src) = source_map.expr_syntax(self.expr) { let root = src.file_syntax(db); diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs index 70e2d3faf160..3a40a6f344fe 100644 --- a/crates/hir/src/lib.rs +++ b/crates/hir/src/lib.rs @@ -255,15 +255,15 @@ impl Crate { self.id } - pub fn origin(self, db: &dyn HirDatabase) -> CrateOrigin { + pub fn origin(self, db: &dyn SourceDatabase) -> CrateOrigin { self.id.data(db).origin.clone() } - pub fn is_builtin(self, db: &dyn HirDatabase) -> bool { + pub fn is_builtin(self, db: &dyn SourceDatabase) -> bool { matches!(self.origin(db), CrateOrigin::Lang(_)) } - pub fn dependencies(self, db: &dyn HirDatabase) -> Vec { + pub fn dependencies(self, db: &dyn SourceDatabase) -> Vec { self.id .data(db) .dependencies @@ -276,7 +276,7 @@ impl Crate { .collect() } - pub fn reverse_dependencies(self, db: &dyn HirDatabase) -> Vec { + pub fn reverse_dependencies(self, db: &dyn SourceDatabase) -> Vec { let all_crates = all_crates(db); all_crates .iter() @@ -288,12 +288,12 @@ impl Crate { pub fn transitive_reverse_dependencies( self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, ) -> impl Iterator { self.id.transitive_rev_deps(db).into_iter().map(|id| Crate { id }) } - pub fn notable_traits_in_deps(self, db: &dyn HirDatabase) -> impl Iterator { + pub fn notable_traits_in_deps(self, db: &dyn SourceDatabase) -> impl Iterator { self.id .transitive_deps(db) .into_iter() @@ -301,28 +301,28 @@ impl Crate { .flatten() } - pub fn root_module(self, db: &dyn HirDatabase) -> Module { + pub fn root_module(self, db: &dyn SourceDatabase) -> Module { Module { id: crate_def_map(db, self.id).root_module_id() } } - pub fn modules(self, db: &dyn HirDatabase) -> Vec { + pub fn modules(self, db: &dyn SourceDatabase) -> Vec { let def_map = crate_def_map(db, self.id); def_map.modules().map(|(id, _)| id.into()).collect() } - pub fn root_file(self, db: &dyn HirDatabase) -> FileId { + pub fn root_file(self, db: &dyn SourceDatabase) -> FileId { self.id.data(db).root_file_id } - pub fn edition(self, db: &dyn HirDatabase) -> Edition { + pub fn edition(self, db: &dyn SourceDatabase) -> Edition { self.id.data(db).edition } - pub fn version(self, db: &dyn HirDatabase) -> Option { + pub fn version(self, db: &dyn SourceDatabase) -> Option { self.id.extra_data(db).version.clone() } - pub fn display_name(self, db: &dyn HirDatabase) -> Option { + pub fn display_name(self, db: &dyn SourceDatabase) -> Option { self.id.extra_data(db).display_name.clone() } @@ -343,31 +343,31 @@ impl Crate { ) } - pub fn all(db: &dyn HirDatabase) -> Vec { + pub fn all(db: &dyn SourceDatabase) -> Vec { all_crates(db).iter().map(|&id| Crate { id }).collect() } /// Try to get the root URL of the documentation of a crate. - pub fn get_html_root_url(self, db: &dyn HirDatabase) -> Option { + pub fn get_html_root_url(self, db: &dyn SourceDatabase) -> Option { // Look for #![doc(html_root_url = "...")] let doc_url = AttrFlags::doc_html_root_url(db, self.id); doc_url.as_ref().map(|s| s.trim_matches('"').trim_end_matches('/').to_owned() + "/") } - pub fn cfg<'db>(&self, db: &'db dyn HirDatabase) -> &'db CfgOptions { + pub fn cfg<'db>(&self, db: &'db dyn SourceDatabase) -> &'db CfgOptions { self.id.cfg_options(db) } - pub fn potential_cfg<'db>(&self, db: &'db dyn HirDatabase) -> &'db CfgOptions { + pub fn potential_cfg<'db>(&self, db: &'db dyn SourceDatabase) -> &'db CfgOptions { let data = self.id.extra_data(db); data.potential_cfg_options.as_ref().unwrap_or_else(|| self.id.cfg_options(db)) } - pub fn to_display_target(self, db: &dyn HirDatabase) -> DisplayTarget { + pub fn to_display_target(self, db: &dyn SourceDatabase) -> DisplayTarget { DisplayTarget::from_crate(db, self.id) } - fn core(db: &dyn HirDatabase) -> Option { + fn core(db: &dyn SourceDatabase) -> Option { all_crates(db) .iter() .copied() @@ -377,7 +377,7 @@ impl Crate { .map(Crate::from) } - pub fn is_unstable_feature_enabled(self, db: &dyn HirDatabase, feature: &Symbol) -> bool { + pub fn is_unstable_feature_enabled(self, db: &dyn SourceDatabase, feature: &Symbol) -> bool { UnstableFeatures::query(db, self.id).is_enabled(feature) } } @@ -422,7 +422,7 @@ impl_from!( ); impl ModuleDef { - pub fn module(self, db: &dyn HirDatabase) -> Option { + pub fn module(self, db: &dyn SourceDatabase) -> Option { match self { ModuleDef::Module(it) => it.parent(db), ModuleDef::Function(it) => Some(it.module(db)), @@ -437,7 +437,7 @@ impl ModuleDef { } } - pub fn canonical_path(&self, db: &dyn HirDatabase, edition: Edition) -> Option { + pub fn canonical_path(&self, db: &dyn SourceDatabase, edition: Edition) -> Option { let name = self.name(db)?; let segments = self.module(db)?.path_segments(db).chain(Some(name)); Some(segments.map(|it| it.display(db, edition).to_string()).join("::")) @@ -445,12 +445,12 @@ impl ModuleDef { pub fn canonical_module_path( &self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, ) -> Option> { self.module(db).map(|it| it.path_to_root(db).into_iter().rev()) } - pub fn name(self, db: &dyn HirDatabase) -> Option { + pub fn name(self, db: &dyn SourceDatabase) -> Option { let name = match self { ModuleDef::Module(it) => it.name(db)?, ModuleDef::Const(it) => it.name(db)?, @@ -468,7 +468,7 @@ impl ModuleDef { pub fn diagnostics<'db>( self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, style_lints: bool, ) -> Vec> { let id = match self { @@ -557,7 +557,7 @@ impl ModuleDef { } } - pub fn attrs(&self, db: &dyn HirDatabase) -> Option { + pub fn attrs(&self, db: &dyn SourceDatabase) -> Option { Some(match self { ModuleDef::Module(it) => it.attrs(db), ModuleDef::Function(it) => HasAttrs::attrs(*it, db), @@ -574,7 +574,7 @@ impl ModuleDef { } impl HasCrate for ModuleDef { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { match self.module(db) { Some(module) => module.krate(db), None => Crate::core(db).unwrap_or_else(|| all_crates(db)[0].into()), @@ -583,7 +583,7 @@ impl HasCrate for ModuleDef { } impl HasAttrs for ModuleDef { - fn attr_id(self, db: &dyn HirDatabase) -> attrs::AttrsOwner { + fn attr_id(self, db: &dyn SourceDatabase) -> attrs::AttrsOwner { match self { ModuleDef::Module(it) => it.attr_id(db), ModuleDef::Function(it) => it.attr_id(db), @@ -600,7 +600,7 @@ impl HasAttrs for ModuleDef { } impl HasVisibility for ModuleDef { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { match *self { ModuleDef::Module(it) => it.visibility(db), ModuleDef::Function(it) => it.visibility(db), @@ -618,29 +618,29 @@ impl HasVisibility for ModuleDef { impl Module { /// Name of this module. - pub fn name(self, db: &dyn HirDatabase) -> Option { + pub fn name(self, db: &dyn SourceDatabase) -> Option { self.id.name(db) } /// Returns the crate this module is part of. - pub fn krate(self, db: &dyn HirDatabase) -> Crate { + pub fn krate(self, db: &dyn SourceDatabase) -> Crate { Crate { id: self.id.krate(db) } } /// Topmost parent of this module. Every module has a `crate_root`, but some /// might be missing `krate`. This can happen if a module's file is not included /// in the module tree of any target in `Cargo.toml`. - pub fn crate_root(self, db: &dyn HirDatabase) -> Module { + pub fn crate_root(self, db: &dyn SourceDatabase) -> Module { let def_map = crate_def_map(db, self.id.krate(db)); Module { id: def_map.crate_root(db) } } - pub fn is_crate_root(self, db: &dyn HirDatabase) -> bool { + pub fn is_crate_root(self, db: &dyn SourceDatabase) -> bool { self.crate_root(db) == self } /// Iterates over all child modules. - pub fn children(self, db: &dyn HirDatabase) -> impl Iterator { + pub fn children(self, db: &dyn SourceDatabase) -> impl Iterator { let def_map = self.id.def_map(db); let children = def_map[self.id] .children @@ -651,14 +651,14 @@ impl Module { } /// Finds a parent module. - pub fn parent(self, db: &dyn HirDatabase) -> Option { + pub fn parent(self, db: &dyn SourceDatabase) -> Option { let def_map = self.id.def_map(db); let parent_id = def_map.containing_module(self.id)?; Some(Module { id: parent_id }) } /// Finds nearest non-block ancestor `Module` (`self` included). - pub fn nearest_non_block_module(self, db: &dyn HirDatabase) -> Module { + pub fn nearest_non_block_module(self, db: &dyn SourceDatabase) -> Module { let mut id = self.id; while id.is_block_module(db) { id = id.containing_module(db).expect("block without parent module"); @@ -666,7 +666,7 @@ impl Module { Module { id: unsafe { id.to_static() } } } - pub fn path_to_root(self, db: &dyn HirDatabase) -> Vec { + pub fn path_to_root(self, db: &dyn SourceDatabase) -> Vec { let mut res = vec![self]; let mut curr = self; while let Some(next) = curr.parent(db) { @@ -686,11 +686,11 @@ impl Module { /// [`ModuleDef::canonical_module_path`] is the same walk yielding the `Module`s /// themselves, for callers that need more than the name — each module's own /// edition, say. - pub fn path_segments(self, db: &dyn HirDatabase) -> impl Iterator { + pub fn path_segments(self, db: &dyn SourceDatabase) -> impl Iterator { self.path_to_root(db).into_iter().rev().filter_map(|it| it.name(db)) } - pub fn modules_in_scope(&self, db: &dyn HirDatabase, pub_only: bool) -> Vec<(Name, Module)> { + pub fn modules_in_scope(&self, db: &dyn SourceDatabase, pub_only: bool) -> Vec<(Name, Module)> { let def_map = self.id.def_map(db); let scope = &def_map[self.id].scope; @@ -710,7 +710,7 @@ impl Module { /// Returns a `ModuleScope`: a set of items, visible in this module. pub fn scope( self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, visible_from: Option, ) -> Vec<(Name, ScopeDef<'_>)> { self.id.def_map(db)[self.id] @@ -732,7 +732,7 @@ impl Module { pub fn resolve_mod_path( &self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, segments: impl IntoIterator, ) -> Option> { let items = self @@ -745,7 +745,7 @@ impl Module { /// Fills `acc` with the module's diagnostics. pub fn diagnostics<'db>( self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, acc: &mut Vec>, style_lints: bool, ) { @@ -1086,7 +1086,7 @@ impl Module { } } - pub fn declarations(self, db: &dyn HirDatabase) -> Vec { + pub fn declarations(self, db: &dyn SourceDatabase) -> Vec { let def_map = self.id.def_map(db); let scope = &def_map[self.id].scope; scope @@ -1096,13 +1096,13 @@ impl Module { .collect() } - pub fn legacy_macros(self, db: &dyn HirDatabase) -> Vec { + pub fn legacy_macros(self, db: &dyn SourceDatabase) -> Vec { let def_map = self.id.def_map(db); let scope = &def_map[self.id].scope; scope.legacy_macros().flat_map(|(_, it)| it).map(|&it| it.into()).collect() } - pub fn impl_defs(self, db: &dyn HirDatabase) -> Vec { + pub fn impl_defs(self, db: &dyn SourceDatabase) -> Vec { let def_map = self.id.def_map(db); let scope = &def_map[self.id].scope; scope.impls().map(Impl::from).chain(scope.builtin_derive_impls().map(Impl::from)).collect() @@ -1146,19 +1146,19 @@ impl Module { } #[inline] - pub fn doc_keyword(self, db: &dyn HirDatabase) -> Option { + pub fn doc_keyword(self, db: &dyn SourceDatabase) -> Option { AttrFlags::doc_keyword(db, self.id) } /// Whether it has `#[path = "..."]` attribute. #[inline] - pub fn has_path(&self, db: &dyn HirDatabase) -> bool { + pub fn has_path(&self, db: &dyn SourceDatabase) -> bool { self.attrs(db).attrs.contains(AttrFlags::HAS_PATH) } } fn macro_call_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, macro_call_id: MacroCallId, acc: &mut Vec>, ) { @@ -1186,7 +1186,7 @@ fn macro_call_diagnostics<'db>( } fn emit_macro_def_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, acc: &mut Vec>, m: Macro, ) { @@ -1208,7 +1208,7 @@ fn emit_macro_def_diagnostics<'db>( } fn emit_def_diagnostic<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, acc: &mut Vec>, diag: &DefDiagnostic, edition: Edition, @@ -1218,7 +1218,7 @@ fn emit_def_diagnostic<'db>( } fn emit_def_diagnostic_<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, acc: &mut Vec>, diag: &DefDiagnosticKind, edition: Edition, @@ -1324,7 +1324,7 @@ fn emit_def_diagnostic_<'db>( fn precise_macro_call_location( ast: &MacroCallKind, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, krate: base_db::Crate, ) -> InFile { // FIXME: maybe we actually want slightly different ranges for the different macro diagnostics @@ -1353,7 +1353,7 @@ fn precise_macro_call_location( } impl HasVisibility for Module { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { let def_map = self.id.def_map(db); let module_data = &def_map[self.id]; module_data.visibility @@ -1378,7 +1378,7 @@ impl<'db> TupleField<'db> { Name::new_tuple_field(self.index as usize) } - pub fn ty(&self, db: &'db dyn HirDatabase) -> Type<'db> { + pub fn ty(&self, db: &'db dyn SourceDatabase) -> Type<'db> { let interner = DbInterner::new_no_crate(db); let ty = InferenceResult::of(db, self.owner) .tuple_field_access_type(self.tuple) @@ -1426,7 +1426,7 @@ impl AstNode for FieldSource { } impl Field { - pub fn name(&self, db: &dyn HirDatabase) -> Name { + pub fn name(&self, db: &dyn SourceDatabase) -> Name { VariantId::from(self.parent).fields(db).fields()[self.id].name.clone() } @@ -1436,23 +1436,23 @@ impl Field { /// Returns the type as in the signature of the struct. Only use this in the /// context of the field definition. - pub fn ty<'db>(&self, db: &'db dyn HirDatabase) -> Type<'db> { + pub fn ty<'db>(&self, db: &'db dyn SourceDatabase) -> Type<'db> { let var_id = self.parent.into(); let ty = db.field_types(var_id)[self.id].ty().instantiate_identity().skip_norm_wip(); Type::new(var_id.adt_id(db).into(), ty) } - pub fn layout<'db>(&self, db: &'db dyn HirDatabase) -> Result, LayoutError> { + pub fn layout<'db>(&self, db: &'db dyn SourceDatabase) -> Result, LayoutError> { self.ty(db).layout(db) } - pub fn parent_def(&self, _db: &dyn HirDatabase) -> Variant { + pub fn parent_def(&self, _db: &dyn SourceDatabase) -> Variant { self.parent } } impl HasVisibility for Field { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { let variant_data = VariantId::from(self.parent).fields(db); let visibility = &variant_data.fields()[self.id].visibility; let parent_id: hir_def::VariantId = self.parent.into(); @@ -1467,15 +1467,15 @@ pub struct Struct { } impl Struct { - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { Module { id: self.id.lookup(db).container } } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { StructSignature::of(db, self.id).name.clone() } - pub fn fields(self, db: &dyn HirDatabase) -> Vec { + pub fn fields(self, db: &dyn SourceDatabase) -> Vec { self.id .fields(db) .fields() @@ -1484,19 +1484,19 @@ impl Struct { .collect() } - pub fn ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn ty(self, db: &dyn SourceDatabase) -> Type<'_> { Type::from_def(db, self.id) } - pub fn constructor_ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn constructor_ty(self, db: &dyn SourceDatabase) -> Type<'_> { Type::from_value_def(db, self.id) } - pub fn repr(self, db: &dyn HirDatabase) -> Option { + pub fn repr(self, db: &dyn SourceDatabase) -> Option { AttrFlags::repr(db, self.id.into()) } - pub fn kind(self, db: &dyn HirDatabase) -> StructKind { + pub fn kind(self, db: &dyn SourceDatabase) -> StructKind { match self.variant_fields(db).shape { hir_def::item_tree::FieldsShape::Record => StructKind::Record, hir_def::item_tree::FieldsShape::Tuple => StructKind::Tuple, @@ -1504,17 +1504,17 @@ impl Struct { } } - fn variant_fields(self, db: &dyn HirDatabase) -> &VariantFields { + fn variant_fields(self, db: &dyn SourceDatabase) -> &VariantFields { self.id.fields(db) } - pub fn is_unstable(self, db: &dyn HirDatabase) -> bool { + pub fn is_unstable(self, db: &dyn SourceDatabase) -> bool { AttrFlags::query(db, self.id.into()).contains(AttrFlags::IS_UNSTABLE) } } impl HasVisibility for Struct { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { let loc = self.id.lookup(db); let source = loc.source(db); visibility_from_ast(db, self.id, source.map(|src| src.visibility())) @@ -1527,23 +1527,23 @@ pub struct Union { } impl Union { - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { UnionSignature::of(db, self.id).name.clone() } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { Module { id: self.id.lookup(db).container } } - pub fn ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn ty(self, db: &dyn SourceDatabase) -> Type<'_> { Type::from_def(db, self.id) } - pub fn constructor_ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn constructor_ty(self, db: &dyn SourceDatabase) -> Type<'_> { Type::from_value_def(db, self.id) } - pub fn kind(self, db: &dyn HirDatabase) -> StructKind { + pub fn kind(self, db: &dyn SourceDatabase) -> StructKind { match self.id.fields(db).shape { hir_def::item_tree::FieldsShape::Record => StructKind::Record, hir_def::item_tree::FieldsShape::Tuple => StructKind::Tuple, @@ -1551,7 +1551,7 @@ impl Union { } } - pub fn fields(self, db: &dyn HirDatabase) -> Vec { + pub fn fields(self, db: &dyn SourceDatabase) -> Vec { self.id .fields(db) .fields() @@ -1559,13 +1559,13 @@ impl Union { .map(|(id, _)| Field { parent: self.into(), id }) .collect() } - pub fn is_unstable(self, db: &dyn HirDatabase) -> bool { + pub fn is_unstable(self, db: &dyn SourceDatabase) -> bool { AttrFlags::query(db, self.id.into()).contains(AttrFlags::IS_UNSTABLE) } } impl HasVisibility for Union { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { let loc = self.id.lookup(db); let source = loc.source(db); visibility_from_ast(db, self.id, source.map(|src| src.visibility())) @@ -1578,32 +1578,32 @@ pub struct Enum { } impl Enum { - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { Module { id: self.id.lookup(db).container } } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { EnumSignature::of(db, self.id).name.clone() } - pub fn variants(self, db: &dyn HirDatabase) -> Vec { + pub fn variants(self, db: &dyn SourceDatabase) -> Vec { self.id.enum_variants(db).variants.values().map(|&(id, _)| EnumVariant { id }).collect() } - pub fn num_variants(self, db: &dyn HirDatabase) -> usize { + pub fn num_variants(self, db: &dyn SourceDatabase) -> usize { self.id.enum_variants(db).variants.len() } - pub fn repr(self, db: &dyn HirDatabase) -> Option { + pub fn repr(self, db: &dyn SourceDatabase) -> Option { AttrFlags::repr(db, self.id.into()) } - pub fn ty<'db>(self, db: &'db dyn HirDatabase) -> Type<'db> { + pub fn ty<'db>(self, db: &'db dyn SourceDatabase) -> Type<'db> { Type::from_def(db, self.id) } /// The type of the enum variant bodies. - pub fn variant_body_ty<'db>(self, db: &'db dyn HirDatabase) -> Type<'db> { + pub fn variant_body_ty<'db>(self, db: &'db dyn SourceDatabase) -> Type<'db> { let interner = DbInterner::new_no_crate(db); Type::no_params( Type::builtin_type_crate(db), @@ -1639,21 +1639,21 @@ impl Enum { } /// Returns true if at least one variant of this enum is a non-unit variant. - pub fn is_data_carrying(self, db: &dyn HirDatabase) -> bool { + pub fn is_data_carrying(self, db: &dyn SourceDatabase) -> bool { self.variants(db).iter().any(|v| !matches!(v.kind(db), StructKind::Unit)) } - pub fn layout<'db>(self, db: &'db dyn HirDatabase) -> Result, LayoutError> { + pub fn layout<'db>(self, db: &'db dyn SourceDatabase) -> Result, LayoutError> { Adt::from(self).layout(db) } - pub fn is_unstable(self, db: &dyn HirDatabase) -> bool { + pub fn is_unstable(self, db: &dyn SourceDatabase) -> bool { AttrFlags::query(db, self.id.into()).contains(AttrFlags::IS_UNSTABLE) } } impl HasVisibility for Enum { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { let loc = self.id.lookup(db); let source = loc.source(db); visibility_from_ast(db, self.id, source.map(|src| src.visibility())) @@ -1666,23 +1666,23 @@ pub struct EnumVariant { } impl EnumVariant { - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { Module { id: self.id.module(db) } } - pub fn parent_enum(self, db: &dyn HirDatabase) -> Enum { + pub fn parent_enum(self, db: &dyn SourceDatabase) -> Enum { self.id.lookup(db).parent.into() } - pub fn constructor_ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn constructor_ty(self, db: &dyn SourceDatabase) -> Type<'_> { Type::from_value_def(db, self.id) } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { self.id.lookup(db).name.clone() } - pub fn fields(self, db: &dyn HirDatabase) -> Vec { + pub fn fields(self, db: &dyn SourceDatabase) -> Vec { self.id .fields(db) .fields() @@ -1691,7 +1691,7 @@ impl EnumVariant { .collect() } - pub fn kind(self, db: &dyn HirDatabase) -> StructKind { + pub fn kind(self, db: &dyn SourceDatabase) -> StructKind { match self.id.fields(db).shape { hir_def::item_tree::FieldsShape::Record => StructKind::Record, hir_def::item_tree::FieldsShape::Tuple => StructKind::Tuple, @@ -1699,15 +1699,15 @@ impl EnumVariant { } } - pub fn value(self, db: &dyn HirDatabase) -> Option { + pub fn value(self, db: &dyn SourceDatabase) -> Option { self.source(db)?.value.const_arg()?.expr() } - pub fn eval(self, db: &dyn HirDatabase) -> Result> { + pub fn eval(self, db: &dyn SourceDatabase) -> Result> { db.const_eval_discriminant(self.into()) } - pub fn layout<'db>(&self, db: &'db dyn HirDatabase) -> Result, LayoutError> { + pub fn layout<'db>(&self, db: &'db dyn SourceDatabase) -> Result, LayoutError> { let parent_enum = self.parent_enum(db); let parent_layout = parent_enum.layout(db)?; Ok(match &parent_layout.0.variants { @@ -1723,7 +1723,7 @@ impl EnumVariant { }) } - pub fn is_unstable(self, db: &dyn HirDatabase) -> bool { + pub fn is_unstable(self, db: &dyn SourceDatabase) -> bool { AttrFlags::query(db, self.id.into()).contains(AttrFlags::IS_UNSTABLE) } } @@ -1737,7 +1737,7 @@ pub enum StructKind { /// Variants inherit visibility from the parent enum. impl HasVisibility for EnumVariant { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { self.parent_enum(db).visibility(db) } } @@ -1752,11 +1752,11 @@ pub enum Adt { impl_from!(Struct, Union, Enum for Adt); impl Adt { - pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { + pub fn has_non_default_type_params(self, db: &dyn SourceDatabase) -> bool { has_non_default_type_params(db, self.into()) } - pub fn layout<'db>(self, db: &'db dyn HirDatabase) -> Result, LayoutError> { + pub fn layout<'db>(self, db: &'db dyn SourceDatabase) -> Result, LayoutError> { let interner = DbInterner::new_no_crate(db); let adt_id = AdtId::from(self); let args = GenericArgs::for_item_with_defaults(interner, adt_id.into(), |_, id, _| { @@ -1769,12 +1769,12 @@ impl Adt { /// Turns this ADT into a type. Any type parameters of the ADT will be /// turned into unknown types, which is good for e.g. finding the most /// general set of completions, but will not look very nice when printed. - pub fn ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn ty(self, db: &dyn SourceDatabase) -> Type<'_> { let id = AdtId::from(self); Type::from_def(db, id) } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { match self { Adt::Struct(s) => s.module(db), Adt::Union(s) => s.module(db), @@ -1782,7 +1782,7 @@ impl Adt { } } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { match self { Adt::Struct(s) => s.name(db), Adt::Union(u) => u.name(db), @@ -1791,7 +1791,7 @@ impl Adt { } /// Returns the lifetime of the DataType - pub fn lifetime(&self, db: &dyn HirDatabase) -> Option { + pub fn lifetime(&self, db: &dyn SourceDatabase) -> Option { let resolver = match self { Adt::Struct(s) => s.id.resolver(db), Adt::Union(u) => u.id.resolver(db), @@ -1818,7 +1818,7 @@ impl Adt { } impl HasVisibility for Adt { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { match self { Adt::Struct(it) => it.visibility(db), Adt::Union(it) => it.visibility(db), @@ -1836,7 +1836,7 @@ pub enum Variant { impl_from!(Struct, Union, EnumVariant for Variant); impl Variant { - pub fn fields(self, db: &dyn HirDatabase) -> Vec { + pub fn fields(self, db: &dyn SourceDatabase) -> Vec { match self { Variant::Struct(it) => it.fields(db), Variant::Union(it) => it.fields(db), @@ -1844,7 +1844,7 @@ impl Variant { } } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { match self { Variant::Struct(it) => it.module(db), Variant::Union(it) => it.module(db), @@ -1852,7 +1852,7 @@ impl Variant { } } - pub fn name(&self, db: &dyn HirDatabase) -> Name { + pub fn name(&self, db: &dyn SourceDatabase) -> Name { match self { Variant::Struct(s) => (*s).name(db), Variant::Union(u) => (*u).name(db), @@ -1860,7 +1860,7 @@ impl Variant { } } - pub fn adt(&self, db: &dyn HirDatabase) -> Adt { + pub fn adt(&self, db: &dyn SourceDatabase) -> Adt { match *self { Variant::Struct(it) => it.into(), Variant::Union(it) => it.into(), @@ -1875,18 +1875,18 @@ pub struct AnonConst<'db> { } impl<'db> AnonConst<'db> { - pub fn owner(self, db: &dyn HirDatabase) -> ExpressionStoreOwner { + pub fn owner(self, db: &dyn SourceDatabase) -> ExpressionStoreOwner { self.id.loc(db).owner.into() } - pub fn ty(self, db: &'db dyn HirDatabase) -> Type<'db> { + pub fn ty(self, db: &'db dyn SourceDatabase) -> Type<'db> { let loc = self.id.loc(db); Type { owner: self.id.into(), ty: loc.ty.get() } } pub fn eval( self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ) -> Result, ConstEvalError<'db>> { let interner = DbInterner::new_no_crate(db); let ty = self.id.loc(db).ty.get().instantiate_identity().skip_norm_wip(); @@ -1933,7 +1933,7 @@ impl_from!( ); impl ExpressionStoreOwner { - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { match self { Self::Body(body) => body.module(db), Self::Signature(generic_def) => generic_def.module(db), @@ -1953,7 +1953,7 @@ pub enum DefWithBody { impl_from!(Function, Const, Static, EnumVariant for DefWithBody); impl DefWithBody { - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { match self { DefWithBody::Const(c) => c.module(db), DefWithBody::Function(f) => f.module(db), @@ -1962,7 +1962,7 @@ impl DefWithBody { } } - pub fn name(self, db: &dyn HirDatabase) -> Option { + pub fn name(self, db: &dyn SourceDatabase) -> Option { match self { DefWithBody::Function(f) => Some(f.name(db)), DefWithBody::Static(s) => Some(s.name(db)), @@ -1972,7 +1972,7 @@ impl DefWithBody { } /// Returns the type this def's body has to evaluate to. - pub fn body_type(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn body_type(self, db: &dyn SourceDatabase) -> Type<'_> { match self { DefWithBody::Function(it) => it.ret_type(db), DefWithBody::Static(it) => it.ty(db), @@ -1994,13 +1994,13 @@ impl DefWithBody { } #[deprecated = "you should really not use this, this is exported for analysis-stats only"] - pub fn run_mir_body(self, db: &dyn HirDatabase) -> Result<(), MirLowerError<'_>> { + pub fn run_mir_body(self, db: &dyn SourceDatabase) -> Result<(), MirLowerError<'_>> { let Some(id) = self.id() else { return Ok(()) }; db.mir_body(id.into()).map(drop) } /// A textual representation of the HIR of this def's body for debugging purposes. - pub fn debug_hir(self, db: &dyn HirDatabase) -> String { + pub fn debug_hir(self, db: &dyn SourceDatabase) -> String { let Some(id) = self.id() else { return String::new(); }; @@ -2009,7 +2009,7 @@ impl DefWithBody { } /// A textual representation of the MIR of this def's body for debugging purposes. - pub fn debug_mir(self, db: &dyn HirDatabase) -> String { + pub fn debug_mir(self, db: &dyn SourceDatabase) -> String { let Some(id) = self.id() else { return String::new(); }; @@ -2022,7 +2022,7 @@ impl DefWithBody { pub fn diagnostics<'db>( self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, acc: &mut Vec>, style_lints: bool, ) { @@ -2225,7 +2225,7 @@ impl DefWithBody { /// Returns an iterator over the inferred types of all expressions in this body. pub fn expression_types<'db>( self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ) -> impl Iterator> { self.id().into_iter().flat_map(move |def_id| { let infer = InferenceResult::of(db, def_id); @@ -2236,7 +2236,10 @@ impl DefWithBody { } /// Returns an iterator over the inferred types of all patterns in this body. - pub fn pattern_types<'db>(self, db: &'db dyn HirDatabase) -> impl Iterator> { + pub fn pattern_types<'db>( + self, + db: &'db dyn SourceDatabase, + ) -> impl Iterator> { self.id().into_iter().flat_map(move |def_id| { let infer = InferenceResult::of(db, def_id); let def_id = def_id.generic_def(db); @@ -2246,7 +2249,10 @@ impl DefWithBody { } /// Returns an iterator over the inferred types of all bindings in this body. - pub fn binding_types<'db>(self, db: &'db dyn HirDatabase) -> impl Iterator> { + pub fn binding_types<'db>( + self, + db: &'db dyn SourceDatabase, + ) -> impl Iterator> { self.id().into_iter().flat_map(move |def_id| { let infer = InferenceResult::of(db, def_id); let def_id = def_id.generic_def(db); @@ -2257,7 +2263,7 @@ impl DefWithBody { } fn expr_store_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, acc: &mut Vec>, source_map: &ExpressionStoreSourceMap, ) { @@ -2313,7 +2319,7 @@ impl fmt::Debug for Function { } impl Function { - pub fn lang(db: &dyn HirDatabase, krate: Crate, lang_item: LangItem) -> Option { + pub fn lang(db: &dyn SourceDatabase, krate: Crate, lang_item: LangItem) -> Option { let lang_items = hir_def::lang_item::lang_items(db, krate.id); match lang_item.from_lang_items(lang_items)? { LangItemTarget::FunctionId(it) => Some(it.into()), @@ -2321,14 +2327,14 @@ impl Function { } } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { match self.id { AnyFunctionId::FunctionId(id) => id.module(db).into(), AnyFunctionId::BuiltinDeriveImplMethod { impl_, .. } => impl_.module(db).into(), } } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { match self.id { AnyFunctionId::FunctionId(id) => FunctionSignature::of(db, id).name.clone(), AnyFunctionId::BuiltinDeriveImplMethod { method, .. } => { @@ -2337,7 +2343,7 @@ impl Function { } } - pub fn ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn ty(self, db: &dyn SourceDatabase) -> Type<'_> { match self.id { AnyFunctionId::FunctionId(id) => Type::from_value_def(db, id), AnyFunctionId::BuiltinDeriveImplMethod { method, impl_ } => { @@ -2352,7 +2358,7 @@ impl Function { } } - pub fn fn_ptr_type(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn fn_ptr_type(self, db: &dyn SourceDatabase) -> Type<'_> { match self.id { AnyFunctionId::FunctionId(id) => { let interner = DbInterner::new_no_crate(db); @@ -2373,7 +2379,7 @@ impl Function { } } - fn fn_sig<'db>(self, db: &'db dyn HirDatabase) -> (TypeOwnerId<'db>, PolyFnSig<'db>) { + fn fn_sig<'db>(self, db: &'db dyn SourceDatabase) -> (TypeOwnerId<'db>, PolyFnSig<'db>) { let fn_ptr = self.fn_ptr_type(db); let TyKind::FnPtr(sig_tys, hdr) = fn_ptr.ty.skip_binder().kind() else { unreachable!(); @@ -2381,19 +2387,19 @@ impl Function { (fn_ptr.owner, sig_tys.with(hdr)) } - fn erased_fn_sig<'db>(self, db: &'db dyn HirDatabase) -> (TypeOwnerId<'db>, FnSig<'db>) { + fn erased_fn_sig<'db>(self, db: &'db dyn SourceDatabase) -> (TypeOwnerId<'db>, FnSig<'db>) { let (owner, sig) = self.fn_sig(db); let sig = DbInterner::new_no_crate(db).instantiate_bound_regions_with_erased(sig); (owner, sig) } /// Get this function's return type - pub fn ret_type(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn ret_type(self, db: &dyn SourceDatabase) -> Type<'_> { let (owner, sig) = self.erased_fn_sig(db); Type { owner, ty: EarlyBinder::bind(sig.output()) } } - pub fn async_ret_type<'db>(self, db: &'db dyn HirDatabase) -> Option> { + pub fn async_ret_type<'db>(self, db: &'db dyn SourceDatabase) -> Option> { let AnyFunctionId::FunctionId(id) = self.id else { return None; }; @@ -2414,7 +2420,7 @@ impl Function { None } - pub fn has_self_param(self, db: &dyn HirDatabase) -> bool { + pub fn has_self_param(self, db: &dyn SourceDatabase) -> bool { match self.id { AnyFunctionId::FunctionId(id) => FunctionSignature::of(db, id).has_self_param(), AnyFunctionId::BuiltinDeriveImplMethod { method, .. } => match method { @@ -2429,11 +2435,11 @@ impl Function { } } - pub fn self_param(self, db: &dyn HirDatabase) -> Option { + pub fn self_param(self, db: &dyn SourceDatabase) -> Option { self.has_self_param(db).then_some(SelfParam { func: self }) } - pub fn assoc_fn_params(self, db: &dyn HirDatabase) -> Vec> { + pub fn assoc_fn_params(self, db: &dyn SourceDatabase) -> Vec> { let (owner, sig) = self.erased_fn_sig(db); let func = match self.id { AnyFunctionId::FunctionId(id) => Callee::Def(CallableDefId::FunctionId(id)), @@ -2452,7 +2458,7 @@ impl Function { .collect() } - pub fn num_params(self, db: &dyn HirDatabase) -> usize { + pub fn num_params(self, db: &dyn SourceDatabase) -> usize { match self.id { AnyFunctionId::FunctionId(id) => FunctionSignature::of(db, id).params.len(), AnyFunctionId::BuiltinDeriveImplMethod { .. } => { @@ -2461,12 +2467,12 @@ impl Function { } } - pub fn method_params(self, db: &dyn HirDatabase) -> Option>> { + pub fn method_params(self, db: &dyn SourceDatabase) -> Option>> { self.self_param(db)?; Some(self.params_without_self(db)) } - pub fn params_without_self(self, db: &dyn HirDatabase) -> Vec> { + pub fn params_without_self(self, db: &dyn SourceDatabase) -> Vec> { let mut params = self.assoc_fn_params(db); if self.has_self_param(db) { params.remove(0); @@ -2474,35 +2480,35 @@ impl Function { params } - pub fn is_const(self, db: &dyn HirDatabase) -> bool { + pub fn is_const(self, db: &dyn SourceDatabase) -> bool { match self.id { AnyFunctionId::FunctionId(id) => FunctionSignature::of(db, id).is_const(), AnyFunctionId::BuiltinDeriveImplMethod { .. } => false, } } - pub fn is_async(self, db: &dyn HirDatabase) -> bool { + pub fn is_async(self, db: &dyn SourceDatabase) -> bool { match self.id { AnyFunctionId::FunctionId(id) => FunctionSignature::of(db, id).is_async(), AnyFunctionId::BuiltinDeriveImplMethod { .. } => false, } } - pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool { + pub fn is_unsafe(self, db: &dyn SourceDatabase) -> bool { match self.id { AnyFunctionId::FunctionId(id) => FunctionSignature::of(db, id).is_unsafe(), AnyFunctionId::BuiltinDeriveImplMethod { .. } => false, } } - pub fn is_varargs(self, db: &dyn HirDatabase) -> bool { + pub fn is_varargs(self, db: &dyn SourceDatabase) -> bool { match self.id { AnyFunctionId::FunctionId(id) => FunctionSignature::of(db, id).is_varargs(), AnyFunctionId::BuiltinDeriveImplMethod { .. } => false, } } - pub fn extern_block(self, db: &dyn HirDatabase) -> Option { + pub fn extern_block(self, db: &dyn SourceDatabase) -> Option { match self.id { AnyFunctionId::FunctionId(id) => match id.lookup(db).container { ItemContainerId::ExternBlockId(id) => Some(ExternBlock { id }), @@ -2512,7 +2518,7 @@ impl Function { } } - pub fn returns_impl_future(self, db: &dyn HirDatabase) -> bool { + pub fn returns_impl_future(self, db: &dyn SourceDatabase) -> bool { if self.is_async(db) { return true; } @@ -2540,12 +2546,12 @@ impl Function { } /// Does this function have `#[test]` attribute? - pub fn is_test(self, db: &dyn HirDatabase) -> bool { + pub fn is_test(self, db: &dyn SourceDatabase) -> bool { self.attrs(db).contains(AttrFlags::IS_TEST) } /// is this a `fn main` or a function with an `export_name` of `main`? - pub fn is_main(self, db: &dyn HirDatabase) -> bool { + pub fn is_main(self, db: &dyn SourceDatabase) -> bool { match self.id { AnyFunctionId::FunctionId(id) => { self.exported_main(db) @@ -2556,7 +2562,7 @@ impl Function { } } - fn attrs(self, db: &dyn HirDatabase) -> AttrFlags { + fn attrs(self, db: &dyn SourceDatabase) -> AttrFlags { match self.id { AnyFunctionId::FunctionId(id) => AttrFlags::query(db, id.into()), AnyFunctionId::BuiltinDeriveImplMethod { .. } => AttrFlags::empty(), @@ -2564,28 +2570,28 @@ impl Function { } /// Is this a function with an `export_name` of `main`? - pub fn exported_main(self, db: &dyn HirDatabase) -> bool { + pub fn exported_main(self, db: &dyn SourceDatabase) -> bool { self.attrs(db).contains(AttrFlags::IS_EXPORT_NAME_MAIN) } /// Does this function have the ignore attribute? - pub fn is_ignore(self, db: &dyn HirDatabase) -> bool { + pub fn is_ignore(self, db: &dyn SourceDatabase) -> bool { self.attrs(db).contains(AttrFlags::IS_IGNORE) } /// Does this function have `#[bench]` attribute? - pub fn is_bench(self, db: &dyn HirDatabase) -> bool { + pub fn is_bench(self, db: &dyn SourceDatabase) -> bool { self.attrs(db).contains(AttrFlags::IS_BENCH) } /// Is this function marked as unstable with `#[feature]` attribute? - pub fn is_unstable(self, db: &dyn HirDatabase) -> bool { + pub fn is_unstable(self, db: &dyn SourceDatabase) -> bool { self.attrs(db).contains(AttrFlags::IS_UNSTABLE) } pub fn is_unsafe_to_call( self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, caller: Option, call_edition: Edition, ) -> bool { @@ -2625,14 +2631,14 @@ impl Function { /// Whether this function declaration has a definition. /// /// This is false in the case of required (not provided) trait methods. - pub fn has_body(self, db: &dyn HirDatabase) -> bool { + pub fn has_body(self, db: &dyn SourceDatabase) -> bool { match self.id { AnyFunctionId::FunctionId(id) => FunctionSignature::of(db, id).has_body(), AnyFunctionId::BuiltinDeriveImplMethod { .. } => true, } } - pub fn as_proc_macro(self, db: &dyn HirDatabase) -> Option { + pub fn as_proc_macro(self, db: &dyn SourceDatabase) -> Option { let AnyFunctionId::FunctionId(id) = self.id else { return None; }; @@ -2642,7 +2648,7 @@ impl Function { pub fn eval( self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, span_formatter: impl Fn(FileId, TextRange) -> String, ) -> Result> { let AnyFunctionId::FunctionId(id) = self.id else { @@ -2733,11 +2739,11 @@ impl<'db> Param<'db> { &self.ty } - pub fn name(&self, db: &dyn HirDatabase) -> Option { + pub fn name(&self, db: &dyn SourceDatabase) -> Option { Some(self.as_local(db)?.name(db)) } - pub fn as_local(&self, db: &'db dyn HirDatabase) -> Option> { + pub fn as_local(&self, db: &'db dyn SourceDatabase) -> Option> { match self.func { Callee::Def(CallableDefId::FunctionId(it)) => { let parent = DefWithBodyId::FunctionId(it); @@ -2781,7 +2787,7 @@ impl<'db> Param<'db> { } } - pub fn pattern_source(self, db: &dyn HirDatabase) -> Option { + pub fn pattern_source(self, db: &dyn SourceDatabase) -> Option { self.source(db).and_then(|p| p.value.right()?.pat()) } } @@ -2792,7 +2798,7 @@ pub struct SelfParam { } impl SelfParam { - pub fn access(self, db: &dyn HirDatabase) -> Access { + pub fn access(self, db: &dyn SourceDatabase) -> Access { match self.func.id { AnyFunctionId::FunctionId(id) => { let func_data = FunctionSignature::of(db, id); @@ -2826,14 +2832,14 @@ impl SelfParam { self.func } - pub fn ty<'db>(&self, db: &'db dyn HirDatabase) -> Type<'db> { + pub fn ty<'db>(&self, db: &'db dyn SourceDatabase) -> Type<'db> { let (owner, sig) = self.func.erased_fn_sig(db); Type { owner, ty: EarlyBinder::bind(sig.inputs()[0]) } } } impl HasVisibility for Function { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { match self.id { AnyFunctionId::FunctionId(id) => AssocItemId::from(id).assoc_visibility(db), AnyFunctionId::BuiltinDeriveImplMethod { .. } => Visibility::Public, @@ -2847,11 +2853,11 @@ pub struct ExternCrateDecl { } impl ExternCrateDecl { - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { self.id.module(db).into() } - pub fn resolved_crate(self, db: &dyn HirDatabase) -> Option { + pub fn resolved_crate(self, db: &dyn SourceDatabase) -> Option { let loc = self.id.lookup(db); let krate = loc.container.krate(db); let name = self.name(db); @@ -2864,13 +2870,13 @@ impl ExternCrateDecl { } } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { let loc = self.id.lookup(db); let source = loc.source(db); as_name_opt(source.value.name_ref()) } - pub fn alias(self, db: &dyn HirDatabase) -> Option { + pub fn alias(self, db: &dyn SourceDatabase) -> Option { let loc = self.id.lookup(db); let source = loc.source(db); let rename = source.value.rename()?; @@ -2884,7 +2890,7 @@ impl ExternCrateDecl { } /// Returns the name under which this crate is made accessible, taking `_` into account. - pub fn alias_or_name(self, db: &dyn HirDatabase) -> Option { + pub fn alias_or_name(self, db: &dyn SourceDatabase) -> Option { match self.alias(db) { Some(ImportAlias::Underscore) => None, Some(ImportAlias::Alias(alias)) => Some(alias), @@ -2894,7 +2900,7 @@ impl ExternCrateDecl { } impl HasVisibility for ExternCrateDecl { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { let loc = self.id.lookup(db); let source = loc.source(db); visibility_from_ast(db, self.id, source.map(|src| src.visibility())) @@ -2907,24 +2913,24 @@ pub struct Const { } impl Const { - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { Module { id: self.id.module(db) } } - pub fn name(self, db: &dyn HirDatabase) -> Option { + pub fn name(self, db: &dyn SourceDatabase) -> Option { ConstSignature::of(db, self.id).name.clone() } - pub fn value(self, db: &dyn HirDatabase) -> Option { + pub fn value(self, db: &dyn SourceDatabase) -> Option { self.source(db)?.value.body() } - pub fn ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn ty(self, db: &dyn SourceDatabase) -> Type<'_> { Type::from_value_def(db, self.id) } /// Evaluate the constant. - pub fn eval(self, db: &dyn HirDatabase) -> Result, ConstEvalError<'_>> { + pub fn eval(self, db: &dyn SourceDatabase) -> Result, ConstEvalError<'_>> { let interner = DbInterner::new_no_crate(db); let ty = db.value_ty(self.id.into()).unwrap().instantiate_identity().skip_norm_wip(); db.const_eval(self.id, GenericArgs::empty(interner), None).map(|it| EvaluatedConst { @@ -2936,7 +2942,7 @@ impl Const { } impl HasVisibility for Const { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { AssocItemId::from(self.id).assoc_visibility(db) } } @@ -2948,11 +2954,11 @@ pub struct EvaluatedConst<'db> { } impl<'db> EvaluatedConst<'db> { - pub fn render(&self, db: &dyn HirDatabase, display_target: DisplayTarget) -> String { + pub fn render(&self, db: &dyn SourceDatabase, display_target: DisplayTarget) -> String { format!("{}", self.allocation.display(db, display_target)) } - pub fn render_debug(&self, db: &'db dyn HirDatabase) -> Result> { + pub fn render_debug(&self, db: &'db dyn SourceDatabase) -> Result> { let ty = self.allocation.ty.kind(); if let TyKind::Int(_) | TyKind::Uint(_) = ty { let b = &self.allocation.memory; @@ -2977,27 +2983,27 @@ pub struct Static { } impl Static { - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { Module { id: self.id.module(db) } } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { StaticSignature::of(db, self.id).name.clone() } - pub fn is_mut(self, db: &dyn HirDatabase) -> bool { + pub fn is_mut(self, db: &dyn SourceDatabase) -> bool { StaticSignature::of(db, self.id).flags.contains(StaticFlags::MUTABLE) } - pub fn value(self, db: &dyn HirDatabase) -> Option { + pub fn value(self, db: &dyn SourceDatabase) -> Option { self.source(db)?.value.body() } - pub fn ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn ty(self, db: &dyn SourceDatabase) -> Type<'_> { Type::from_value_def(db, self.id) } - pub fn extern_block(self, db: &dyn HirDatabase) -> Option { + pub fn extern_block(self, db: &dyn SourceDatabase) -> Option { match self.id.lookup(db).container { ItemContainerId::ExternBlockId(id) => Some(ExternBlock { id }), _ => None, @@ -3005,7 +3011,7 @@ impl Static { } /// Evaluate the static initializer. - pub fn eval(self, db: &dyn HirDatabase) -> Result, ConstEvalError<'_>> { + pub fn eval(self, db: &dyn SourceDatabase) -> Result, ConstEvalError<'_>> { let ty = db.value_ty(self.id.into()).unwrap().instantiate_identity().skip_norm_wip(); db.const_eval_static(self.id).map(|it| EvaluatedConst { allocation: it, @@ -3016,7 +3022,7 @@ impl Static { } impl HasVisibility for Static { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { let loc = self.id.lookup(db); let source = loc.source(db); visibility_from_ast(db, self.id, source.map(|src| src.visibility())) @@ -3029,7 +3035,7 @@ pub struct Trait { } impl Trait { - pub fn lang(db: &dyn HirDatabase, krate: Crate, lang_item: LangItem) -> Option { + pub fn lang(db: &dyn SourceDatabase, krate: Crate, lang_item: LangItem) -> Option { let lang_items = hir_def::lang_item::lang_items(db, krate.id); match lang_item.from_lang_items(lang_items)? { LangItemTarget::TraitId(it) => Some(it.into()), @@ -3037,25 +3043,25 @@ impl Trait { } } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { Module { id: self.id.lookup(db).container } } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { TraitSignature::of(db, self.id).name.clone() } - pub fn direct_supertraits(self, db: &dyn HirDatabase) -> Vec { + pub fn direct_supertraits(self, db: &dyn SourceDatabase) -> Vec { let traits = direct_super_traits(db, self.into()); traits.iter().map(|tr| Trait::from(*tr)).collect() } - pub fn all_supertraits(self, db: &dyn HirDatabase) -> Vec { + pub fn all_supertraits(self, db: &dyn SourceDatabase) -> Vec { let traits = all_super_traits(db, self.into()); traits.iter().map(|tr| Trait::from(*tr)).collect() } - pub fn function(self, db: &dyn HirDatabase, name: impl PartialEq) -> Option { + pub fn function(self, db: &dyn SourceDatabase, name: impl PartialEq) -> Option { self.id.trait_items(db).items.iter().find(|(n, _)| name == *n).and_then(|&(_, it)| match it { AssocItemId::FunctionId(id) => Some(id.into()), @@ -3063,25 +3069,25 @@ impl Trait { }) } - pub fn items(self, db: &dyn HirDatabase) -> Vec { + pub fn items(self, db: &dyn SourceDatabase) -> Vec { self.id.trait_items(db).items.iter().map(|(_name, it)| (*it).into()).collect() } - pub fn items_with_supertraits(self, db: &dyn HirDatabase) -> Vec { + pub fn items_with_supertraits(self, db: &dyn SourceDatabase) -> Vec { self.all_supertraits(db).into_iter().flat_map(|tr| tr.items(db)).collect() } - pub fn is_auto(self, db: &dyn HirDatabase) -> bool { + pub fn is_auto(self, db: &dyn SourceDatabase) -> bool { TraitSignature::of(db, self.id).flags.contains(TraitFlags::AUTO) } - pub fn is_unsafe(&self, db: &dyn HirDatabase) -> bool { + pub fn is_unsafe(&self, db: &dyn SourceDatabase) -> bool { TraitSignature::of(db, self.id).flags.contains(TraitFlags::UNSAFE) } pub fn type_or_const_param_count( &self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, count_required_only: bool, ) -> usize { GenericParams::of(db,self.id.into()) @@ -3091,13 +3097,13 @@ impl Trait { .count() } - pub fn dyn_compatibility(&self, db: &dyn HirDatabase) -> Option { + pub fn dyn_compatibility(&self, db: &dyn SourceDatabase) -> Option { hir_ty::dyn_compatibility::dyn_compatibility(db, self.id) } pub fn dyn_compatibility_all_violations( &self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, ) -> Option> { let mut violations = vec![]; _ = hir_ty::dyn_compatibility::dyn_compatibility_with_callback( @@ -3111,12 +3117,12 @@ impl Trait { violations.is_empty().not().then_some(violations) } - fn all_macro_calls(&self, db: &dyn HirDatabase) -> Box<[(AstId, MacroCallId)]> { + fn all_macro_calls(&self, db: &dyn SourceDatabase) -> Box<[(AstId, MacroCallId)]> { self.id.trait_items(db).macro_calls.to_vec().into_boxed_slice() } /// `#[rust_analyzer::completions(...)]` mode. - pub fn complete(self, db: &dyn HirDatabase) -> Complete { + pub fn complete(self, db: &dyn SourceDatabase) -> Complete { Complete::extract(true, self.attrs(db).attrs) } @@ -3129,13 +3135,13 @@ impl Trait { // to import it will prefer to import it `as _` (but allow to import it normally as well). // // Malformed attributes will be ignored without warnings. - pub fn prefer_underscore_import(self, db: &dyn HirDatabase) -> bool { + pub fn prefer_underscore_import(self, db: &dyn SourceDatabase) -> bool { AttrFlags::query(db, self.id.into()).contains(AttrFlags::PREFER_UNDERSCORE_IMPORT) } } impl HasVisibility for Trait { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { let loc = self.id.lookup(db); let source = loc.source(db); visibility_from_ast(db, self.id, source.map(|src| src.visibility())) @@ -3148,25 +3154,25 @@ pub struct TypeAlias { } impl TypeAlias { - pub fn has_non_default_type_params(self, db: &dyn HirDatabase) -> bool { + pub fn has_non_default_type_params(self, db: &dyn SourceDatabase) -> bool { has_non_default_type_params(db, self.id.into()) } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { Module { id: self.id.module(db) } } - pub fn ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn ty(self, db: &dyn SourceDatabase) -> Type<'_> { Type::from_def(db, self.id) } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { TypeAliasSignature::of(db, self.id).name.clone() } } impl HasVisibility for TypeAlias { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { AssocItemId::from(self.id).assoc_visibility(db) } } @@ -3177,7 +3183,7 @@ pub struct ExternBlock { } impl ExternBlock { - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { Module { id: self.id.module(db) } } } @@ -3212,7 +3218,7 @@ impl BuiltinType { BuiltinType { inner: hir_def::builtin_type::BuiltinType::Bool } } - pub fn ty<'db>(self, db: &'db dyn HirDatabase) -> Type<'db> { + pub fn ty<'db>(self, db: &'db dyn SourceDatabase) -> Type<'db> { let interner = DbInterner::new_no_crate(db); Type::no_params(Type::builtin_type_crate(db), Ty::from_builtin_type(interner, self.inner)) } @@ -3280,11 +3286,11 @@ pub struct Macro { } impl Macro { - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { Module { id: self.id.module(db) } } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { match self.id { MacroId::Macro2Id(id) => { let loc = id.lookup(db); @@ -3310,7 +3316,7 @@ impl Macro { } } - pub fn is_macro_export(self, db: &dyn HirDatabase) -> bool { + pub fn is_macro_export(self, db: &dyn SourceDatabase) -> bool { matches!(self.id, MacroId::MacroRulesId(_) if AttrFlags::query(db, self.id.into()).contains(AttrFlags::IS_MACRO_EXPORT)) } @@ -3318,7 +3324,7 @@ impl Macro { matches!(self.id, MacroId::ProcMacroId(_)) } - pub fn kind(&self, db: &dyn HirDatabase) -> MacroKind { + pub fn kind(&self, db: &dyn SourceDatabase) -> MacroKind { match self.id { MacroId::Macro2Id(it) => match it.lookup(db).expander { MacroExpander::Declarative { .. } => MacroKind::Declarative, @@ -3346,14 +3352,14 @@ impl Macro { } } - pub fn is_fn_like(&self, db: &dyn HirDatabase) -> bool { + pub fn is_fn_like(&self, db: &dyn SourceDatabase) -> bool { matches!( self.kind(db), MacroKind::Declarative | MacroKind::DeclarativeBuiltIn | MacroKind::ProcMacro ) } - pub fn builtin_derive_kind(&self, db: &dyn HirDatabase) -> Option { + pub fn builtin_derive_kind(&self, db: &dyn SourceDatabase) -> Option { let expander = match self.id { MacroId::Macro2Id(it) => it.lookup(db).expander, MacroId::MacroRulesId(it) => it.lookup(db).expander, @@ -3365,7 +3371,7 @@ impl Macro { } } - pub fn is_env_or_option_env(&self, db: &dyn HirDatabase) -> bool { + pub fn is_env_or_option_env(&self, db: &dyn SourceDatabase) -> bool { match self.id { MacroId::Macro2Id(it) => { matches!(it.lookup(db).expander, MacroExpander::BuiltInEager(eager) if eager.is_env_or_option_env()) @@ -3378,7 +3384,7 @@ impl Macro { } /// Is this `asm!()`, or a variant of it (e.g. `global_asm!()`)? - pub fn is_asm_like(&self, db: &dyn HirDatabase) -> bool { + pub fn is_asm_like(&self, db: &dyn SourceDatabase) -> bool { match self.id { MacroId::Macro2Id(it) => { matches!(it.lookup(db).expander, MacroExpander::BuiltIn(m) if m.is_asm()) @@ -3390,15 +3396,15 @@ impl Macro { } } - pub fn is_attr(&self, db: &dyn HirDatabase) -> bool { + pub fn is_attr(&self, db: &dyn SourceDatabase) -> bool { matches!(self.kind(db), MacroKind::Attr | MacroKind::AttrBuiltIn) } - pub fn is_derive(&self, db: &dyn HirDatabase) -> bool { + pub fn is_derive(&self, db: &dyn SourceDatabase) -> bool { matches!(self.kind(db), MacroKind::Derive | MacroKind::DeriveBuiltIn) } - pub fn preferred_brace_style(&self, db: &dyn HirDatabase) -> Option { + pub fn preferred_brace_style(&self, db: &dyn SourceDatabase) -> Option { let attrs = self.attrs(db); MacroBraces::extract(attrs.attrs) } @@ -3447,7 +3453,7 @@ impl MacroBraces { pub struct BuiltinDeriveMacroKind(BuiltinDeriveExpander); impl HasVisibility for Macro { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { match self.id { MacroId::Macro2Id(id) => { let loc = id.lookup(db); @@ -3498,14 +3504,14 @@ impl ItemInNs { } /// Returns the crate defining this item (or `None` if `self` is built-in). - pub fn krate(&self, db: &dyn HirDatabase) -> Option { + pub fn krate(&self, db: &dyn SourceDatabase) -> Option { match self { ItemInNs::Types(did) | ItemInNs::Values(did) => did.module(db).map(|m| m.krate(db)), ItemInNs::Macros(id) => Some(id.module(db).krate(db)), } } - pub fn attrs(&self, db: &dyn HirDatabase) -> Option { + pub fn attrs(&self, db: &dyn SourceDatabase) -> Option { match self { ItemInNs::Types(it) | ItemInNs::Values(it) => it.attrs(db), ItemInNs::Macros(it) => Some(it.attrs(db)), @@ -3523,11 +3529,11 @@ pub enum ExternAssocItem { } pub trait AsExternAssocItem { - fn as_extern_assoc_item(self, db: &dyn HirDatabase) -> Option; + fn as_extern_assoc_item(self, db: &dyn SourceDatabase) -> Option; } impl AsExternAssocItem for Function { - fn as_extern_assoc_item(self, db: &dyn HirDatabase) -> Option { + fn as_extern_assoc_item(self, db: &dyn SourceDatabase) -> Option { let AnyFunctionId::FunctionId(id) = self.id else { return None; }; @@ -3536,13 +3542,13 @@ impl AsExternAssocItem for Function { } impl AsExternAssocItem for Static { - fn as_extern_assoc_item(self, db: &dyn HirDatabase) -> Option { + fn as_extern_assoc_item(self, db: &dyn SourceDatabase) -> Option { as_extern_assoc_item(db, ExternAssocItem::Static, self.id) } } impl AsExternAssocItem for TypeAlias { - fn as_extern_assoc_item(self, db: &dyn HirDatabase) -> Option { + fn as_extern_assoc_item(self, db: &dyn SourceDatabase) -> Option { as_extern_assoc_item(db, ExternAssocItem::TypeAlias, self.id) } } @@ -3572,11 +3578,11 @@ pub enum AssocItemContainer { } pub trait AsAssocItem { - fn as_assoc_item(self, db: &dyn HirDatabase) -> Option; + fn as_assoc_item(self, db: &dyn SourceDatabase) -> Option; } impl AsAssocItem for Function { - fn as_assoc_item(self, db: &dyn HirDatabase) -> Option { + fn as_assoc_item(self, db: &dyn SourceDatabase) -> Option { match self.id { AnyFunctionId::FunctionId(id) => as_assoc_item(db, AssocItem::Function, id), AnyFunctionId::BuiltinDeriveImplMethod { .. } => Some(AssocItem::Function(self)), @@ -3585,19 +3591,19 @@ impl AsAssocItem for Function { } impl AsAssocItem for Const { - fn as_assoc_item(self, db: &dyn HirDatabase) -> Option { + fn as_assoc_item(self, db: &dyn SourceDatabase) -> Option { as_assoc_item(db, AssocItem::Const, self.id) } } impl AsAssocItem for TypeAlias { - fn as_assoc_item(self, db: &dyn HirDatabase) -> Option { + fn as_assoc_item(self, db: &dyn SourceDatabase) -> Option { as_assoc_item(db, AssocItem::TypeAlias, self.id) } } impl AsAssocItem for ModuleDef { - fn as_assoc_item(self, db: &dyn HirDatabase) -> Option { + fn as_assoc_item(self, db: &dyn SourceDatabase) -> Option { match self { ModuleDef::Function(it) => it.as_assoc_item(db), ModuleDef::Const(it) => it.as_assoc_item(db), @@ -3608,7 +3614,7 @@ impl AsAssocItem for ModuleDef { } impl AsAssocItem for DefWithBody { - fn as_assoc_item(self, db: &dyn HirDatabase) -> Option { + fn as_assoc_item(self, db: &dyn SourceDatabase) -> Option { match self { DefWithBody::Function(it) => it.as_assoc_item(db), DefWithBody::Const(it) => it.as_assoc_item(db), @@ -3618,7 +3624,7 @@ impl AsAssocItem for DefWithBody { } impl AsAssocItem for GenericDef { - fn as_assoc_item(self, db: &dyn HirDatabase) -> Option { + fn as_assoc_item(self, db: &dyn SourceDatabase) -> Option { match self { GenericDef::Function(it) => it.as_assoc_item(db), GenericDef::Const(it) => it.as_assoc_item(db), @@ -3629,7 +3635,7 @@ impl AsAssocItem for GenericDef { } fn as_assoc_item<'db, ID, DEF, LOC>( - db: &(dyn HirDatabase + 'db), + db: &(dyn SourceDatabase + 'db), ctor: impl FnOnce(DEF) -> AssocItem, id: ID, ) -> Option @@ -3645,7 +3651,7 @@ where } fn as_extern_assoc_item<'db, ID, DEF, LOC>( - db: &(dyn HirDatabase + 'db), + db: &(dyn SourceDatabase + 'db), ctor: impl FnOnce(DEF) -> ExternAssocItem, id: ID, ) -> Option @@ -3663,7 +3669,7 @@ where } impl ExternAssocItem { - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { match self { Self::Function(it) => it.name(db), Self::Static(it) => it.name(db), @@ -3671,7 +3677,7 @@ impl ExternAssocItem { } } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { match self { Self::Function(f) => f.module(db), Self::Static(c) => c.module(db), @@ -3702,7 +3708,7 @@ impl ExternAssocItem { } impl AssocItem { - pub fn name(self, db: &dyn HirDatabase) -> Option { + pub fn name(self, db: &dyn SourceDatabase) -> Option { match self { AssocItem::Function(it) => Some(it.name(db)), AssocItem::Const(it) => it.name(db), @@ -3710,7 +3716,7 @@ impl AssocItem { } } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { match self { AssocItem::Function(f) => f.module(db), AssocItem::Const(c) => c.module(db), @@ -3718,7 +3724,7 @@ impl AssocItem { } } - pub fn container(self, db: &dyn HirDatabase) -> AssocItemContainer { + pub fn container(self, db: &dyn SourceDatabase) -> AssocItemContainer { let container = match self { AssocItem::Function(it) => match it.id { AnyFunctionId::FunctionId(id) => id.lookup(db).container, @@ -3740,28 +3746,28 @@ impl AssocItem { } } - pub fn container_trait(self, db: &dyn HirDatabase) -> Option { + pub fn container_trait(self, db: &dyn SourceDatabase) -> Option { match self.container(db) { AssocItemContainer::Trait(t) => Some(t), _ => None, } } - pub fn implemented_trait(self, db: &dyn HirDatabase) -> Option { + pub fn implemented_trait(self, db: &dyn SourceDatabase) -> Option { match self.container(db) { AssocItemContainer::Impl(i) => i.trait_(db), _ => None, } } - pub fn container_or_implemented_trait(self, db: &dyn HirDatabase) -> Option { + pub fn container_or_implemented_trait(self, db: &dyn SourceDatabase) -> Option { match self.container(db) { AssocItemContainer::Trait(t) => Some(t), AssocItemContainer::Impl(i) => i.trait_(db), } } - pub fn implementing_ty(self, db: &dyn HirDatabase) -> Option> { + pub fn implementing_ty(self, db: &dyn SourceDatabase) -> Option> { match self.container(db) { AssocItemContainer::Impl(i) => Some(i.self_ty(db)), _ => None, @@ -3791,7 +3797,7 @@ impl AssocItem { pub fn diagnostics<'db>( self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, acc: &mut Vec>, style_lints: bool, ) { @@ -3821,7 +3827,7 @@ impl AssocItem { } impl HasVisibility for AssocItem { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility { match self { AssocItem::Function(f) => f.visibility(db), AssocItem::Const(c) => c.visibility(db), @@ -3855,7 +3861,7 @@ impl_from!( ); impl GenericDef { - pub fn name(self, db: &dyn HirDatabase) -> Option { + pub fn name(self, db: &dyn SourceDatabase) -> Option { match self { GenericDef::Function(it) => Some(it.name(db)), GenericDef::Adt(it) => Some(it.name(db)), @@ -3867,7 +3873,7 @@ impl GenericDef { } } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { match self { GenericDef::Function(it) => it.module(db), GenericDef::Adt(it) => it.module(db), @@ -3879,7 +3885,7 @@ impl GenericDef { } } - pub fn params(self, db: &dyn HirDatabase) -> Vec { + pub fn params(self, db: &dyn SourceDatabase) -> Vec { let Ok(id) = self.try_into() else { // Let's pretend builtin derive impls don't have generic parameters. return Vec::new(); @@ -3899,7 +3905,7 @@ impl GenericDef { .collect() } - pub fn lifetime_params(self, db: &dyn HirDatabase) -> Vec { + pub fn lifetime_params(self, db: &dyn SourceDatabase) -> Vec { let Ok(id) = self.try_into() else { // Let's pretend builtin derive impls don't have generic parameters. return Vec::new(); @@ -3911,7 +3917,7 @@ impl GenericDef { .collect() } - pub fn type_or_const_params(self, db: &dyn HirDatabase) -> Vec { + pub fn type_or_const_params(self, db: &dyn SourceDatabase) -> Vec { let Ok(id) = self.try_into() else { // Let's pretend builtin derive impls don't have generic parameters. return Vec::new(); @@ -3943,7 +3949,7 @@ impl GenericDef { }) } - pub fn diagnostics<'db>(self, db: &'db dyn HirDatabase, acc: &mut Vec>) { + pub fn diagnostics<'db>(self, db: &'db dyn SourceDatabase, acc: &mut Vec>) { let Some(def) = self.id() else { return }; let generics = GenericParams::of(db, def); @@ -4026,7 +4032,7 @@ impl<'db> GenericSubstitution<'db> { } } - pub fn types(&self, db: &'db dyn HirDatabase) -> Vec<(Symbol, Type<'db>)> { + pub fn types(&self, db: &'db dyn SourceDatabase) -> Vec<(Symbol, Type<'db>)> { let container = match self.def { GenericDefId::ConstId(id) => Some(id.lookup(db).container), GenericDefId::FunctionId(id) => Some(id.lookup(db).container), @@ -4106,7 +4112,7 @@ impl<'db> LocalSource<'db> { } } - pub fn original_file(&self, db: &dyn HirDatabase) -> EditionedFileId { + pub fn original_file(&self, db: &dyn SourceDatabase) -> EditionedFileId { self.source.file_id.original_file(db) } @@ -4128,7 +4134,7 @@ impl<'db> LocalSource<'db> { } impl<'db> Local<'db> { - pub fn is_param(self, db: &dyn HirDatabase) -> bool { + pub fn is_param(self, db: &dyn SourceDatabase) -> bool { // FIXME: This parses! let src = self.primary_source(db); match src.source.value { @@ -4142,7 +4148,7 @@ impl<'db> Local<'db> { } } - pub fn as_self_param(self, db: &dyn HirDatabase) -> Option { + pub fn as_self_param(self, db: &dyn SourceDatabase) -> Option { match self.parent { ExpressionStoreOwnerId::Body(DefWithBodyId::FunctionId(func)) if self.is_self(db) => { Some(SelfParam { func: func.into() }) @@ -4151,30 +4157,30 @@ impl<'db> Local<'db> { } } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { ExpressionStore::of(db, self.parent)[self.binding_id].name.clone() } - pub fn is_self(self, db: &dyn HirDatabase) -> bool { + pub fn is_self(self, db: &dyn SourceDatabase) -> bool { self.name(db) == sym::self_ } - pub fn is_mut(self, db: &dyn HirDatabase) -> bool { + pub fn is_mut(self, db: &dyn SourceDatabase) -> bool { ExpressionStore::of(db, self.parent)[self.binding_id].mode == BindingAnnotation::Mutable } - pub fn is_ref(self, db: &dyn HirDatabase) -> bool { + pub fn is_ref(self, db: &dyn SourceDatabase) -> bool { matches!( ExpressionStore::of(db, self.parent)[self.binding_id].mode, BindingAnnotation::Ref | BindingAnnotation::RefMut ) } - pub fn parent(self, _db: &dyn HirDatabase) -> ExpressionStoreOwner { + pub fn parent(self, _db: &dyn SourceDatabase) -> ExpressionStoreOwner { self.parent.into() } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { self.parent(db).module(db) } @@ -4182,7 +4188,7 @@ impl<'db> Local<'db> { self.binding_id.into_raw().into_u32() } - pub fn ty(self, db: &'db dyn HirDatabase) -> Type<'db> { + pub fn ty(self, db: &'db dyn SourceDatabase) -> Type<'db> { let def = self.parent; let infer = InferenceResult::of(db, self.parent_infer); let ty = infer.binding_ty(self.binding_id); @@ -4190,7 +4196,7 @@ impl<'db> Local<'db> { } /// All definitions for this local. Example: `let (a$0, _) | (_, a$0) = it;` - pub fn sources(self, db: &dyn HirDatabase) -> Vec> { + pub fn sources(self, db: &dyn SourceDatabase) -> Vec> { let b; let (_, source_map) = match self.parent { ExpressionStoreOwnerId::Signature(generic_def_id) => { @@ -4231,7 +4237,7 @@ impl<'db> Local<'db> { } /// The leftmost definition for this local. Example: `let (a$0, _) | (_, a) = it;` - pub fn primary_source(self, db: &dyn HirDatabase) -> LocalSource<'db> { + pub fn primary_source(self, db: &dyn SourceDatabase) -> LocalSource<'db> { let b; let (_, source_map) = match self.parent { ExpressionStoreOwnerId::Signature(generic_def_id) => { @@ -4295,7 +4301,7 @@ impl DeriveHelper { Macro { id: self.derive } } - pub fn name(&self, db: &dyn HirDatabase) -> Name { + pub fn name(&self, db: &dyn SourceDatabase) -> Name { AttrFlags::derive_info(db, self.derive) .and_then(|it| it.helpers.get(self.idx as usize)) .map(|helper| Name::new_symbol_root(helper.clone())) @@ -4332,7 +4338,7 @@ pub struct ToolModule { } impl ToolModule { - pub(crate) fn by_name(db: &dyn HirDatabase, krate: Crate, name: &str) -> Option { + pub(crate) fn by_name(db: &dyn SourceDatabase, krate: Crate, name: &str) -> Option { let krate = krate.id; let idx = crate_def_map(db, krate).registered_tools().iter().position(|it| it.as_str() == name)? @@ -4340,7 +4346,7 @@ impl ToolModule { Some(ToolModule { krate, idx }) } - pub fn name(&self, db: &dyn HirDatabase) -> Name { + pub fn name(&self, db: &dyn SourceDatabase) -> Name { Name::new_symbol_root( crate_def_map(db, self.krate).registered_tools()[self.idx as usize].clone(), ) @@ -4358,15 +4364,15 @@ pub struct Label { } impl Label { - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { self.parent(db).module(db) } - pub fn parent(self, _db: &dyn HirDatabase) -> ExpressionStoreOwner { + pub fn parent(self, _db: &dyn SourceDatabase) -> ExpressionStoreOwner { self.parent.into() } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { ExpressionStore::of(db, self.parent)[self.label_id].name.clone() } } @@ -4380,7 +4386,7 @@ pub enum GenericParam { impl_from!(TypeParam, ConstParam, LifetimeParam for GenericParam); impl GenericParam { - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { match self { GenericParam::TypeParam(it) => it.module(db), GenericParam::ConstParam(it) => it.module(db), @@ -4388,7 +4394,7 @@ impl GenericParam { } } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { match self { GenericParam::TypeParam(it) => it.name(db), GenericParam::ConstParam(it) => it.name(db), @@ -4404,7 +4410,7 @@ impl GenericParam { } } - pub fn variance(self, db: &dyn HirDatabase) -> Option { + pub fn variance(self, db: &dyn SourceDatabase) -> Option { let parent = match self { GenericParam::TypeParam(it) => it.id.parent(), // const parameters are always invariant @@ -4462,21 +4468,21 @@ impl TypeParam { TypeOrConstParam { id: self.id.into() } } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { self.merge().name(db) } - pub fn parent(self, _db: &dyn HirDatabase) -> GenericDef { + pub fn parent(self, _db: &dyn SourceDatabase) -> GenericDef { self.id.parent().into() } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { self.id.parent().module(db).into() } /// Is this type parameter implicitly introduced (eg. `Self` in a trait or an `impl Trait` /// argument)? - pub fn is_implicit(self, db: &dyn HirDatabase) -> bool { + pub fn is_implicit(self, db: &dyn SourceDatabase) -> bool { let params = GenericParams::of(db, self.id.parent()); let data = ¶ms[self.id.local_id()]; match data.type_param().unwrap().provenance { @@ -4485,7 +4491,7 @@ impl TypeParam { } } - pub fn ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn ty(self, db: &dyn SourceDatabase) -> Type<'_> { let interner = DbInterner::new_no_crate(db); let index = hir_ty::type_or_const_param_idx(db, self.id.into()); let ty = Ty::new_param(interner, self.id, index); @@ -4495,7 +4501,7 @@ impl TypeParam { /// FIXME: this only lists trait bounds from the item defining the type /// parameter, not additional bounds that might be added e.g. by a method if /// the parameter comes from an impl! - pub fn trait_bounds(self, db: &dyn HirDatabase) -> Vec { + pub fn trait_bounds(self, db: &dyn SourceDatabase) -> Vec { let self_ty = self.ty(db).ty.instantiate_identity().skip_norm_wip(); GenericPredicates::query_explicit(db, self.id.parent()) .iter_identity() @@ -4508,7 +4514,7 @@ impl TypeParam { .collect() } - pub fn default(self, db: &dyn HirDatabase) -> Option> { + pub fn default(self, db: &dyn SourceDatabase) -> Option> { let ty = generic_arg_from_param(db, self.id.into())?; match ty.kind() { rustc_type_ir::GenericArgKind::Type(it) if !it.is_ty_error() => { @@ -4518,7 +4524,7 @@ impl TypeParam { } } - pub fn is_unstable(self, db: &dyn HirDatabase) -> bool { + pub fn is_unstable(self, db: &dyn SourceDatabase) -> bool { self.attrs(db).is_unstable() } } @@ -4529,16 +4535,16 @@ pub struct LifetimeParam { } impl LifetimeParam { - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { let params = GenericParams::of(db, self.id.parent); params[self.id.local_id].name.clone() } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { self.id.parent.module(db).into() } - pub fn parent(self, _db: &dyn HirDatabase) -> GenericDef { + pub fn parent(self, _db: &dyn SourceDatabase) -> GenericDef { self.id.parent.into() } } @@ -4553,7 +4559,7 @@ impl ConstParam { TypeOrConstParam { id: self.id.into() } } - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { let params = GenericParams::of(db, self.id.parent()); match params[self.id.local_id()].name() { Some(it) => it.clone(), @@ -4564,26 +4570,26 @@ impl ConstParam { } } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { self.id.parent().module(db).into() } - pub fn parent(self, _db: &dyn HirDatabase) -> GenericDef { + pub fn parent(self, _db: &dyn SourceDatabase) -> GenericDef { self.id.parent().into() } - pub fn ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn ty(self, db: &dyn SourceDatabase) -> Type<'_> { Type::new(self.id.parent(), db.const_param_ty(self.id)) } - pub fn default(self, db: &dyn HirDatabase, display_target: DisplayTarget) -> Option { + pub fn default(self, db: &dyn SourceDatabase, display_target: DisplayTarget) -> Option { let arg = generic_arg_from_param(db, self.id.into())?; Some(arg.display(db, display_target).to_string()) } pub fn default_source_code( self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, target_module: Module, ) -> Option { let arg = generic_arg_from_param(db, self.id.into())?; @@ -4591,7 +4597,10 @@ impl ConstParam { } } -fn generic_arg_from_param(db: &dyn HirDatabase, id: TypeOrConstParamId) -> Option> { +fn generic_arg_from_param( + db: &dyn SourceDatabase, + id: TypeOrConstParamId, +) -> Option> { let local_idx = hir_ty::type_or_const_param_idx(db, id); let defaults = db.generic_defaults(id.parent); let ty = defaults.get(local_idx as usize)?; @@ -4605,7 +4614,7 @@ pub struct TypeOrConstParam { } impl TypeOrConstParam { - pub fn name(self, db: &dyn HirDatabase) -> Name { + pub fn name(self, db: &dyn SourceDatabase) -> Name { let params = GenericParams::of(db, self.id.parent); match params[self.id.local_id].name() { Some(n) => n.clone(), @@ -4613,15 +4622,15 @@ impl TypeOrConstParam { } } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { self.id.parent.module(db).into() } - pub fn parent(self, _db: &dyn HirDatabase) -> GenericDef { + pub fn parent(self, _db: &dyn SourceDatabase) -> GenericDef { self.id.parent.into() } - pub fn split(self, db: &dyn HirDatabase) -> Either { + pub fn split(self, db: &dyn SourceDatabase) -> Either { let params = GenericParams::of(db, self.id.parent); match ¶ms[self.id.local_id] { TypeOrConstParamData::TypeParamData(_) => { @@ -4633,14 +4642,14 @@ impl TypeOrConstParam { } } - pub fn ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn ty(self, db: &dyn SourceDatabase) -> Type<'_> { match self.split(db) { Either::Left(it) => it.ty(db), Either::Right(it) => it.ty(db), } } - pub fn as_type_param(self, db: &dyn HirDatabase) -> Option { + pub fn as_type_param(self, db: &dyn SourceDatabase) -> Option { let params = GenericParams::of(db, self.id.parent); match ¶ms[self.id.local_id] { TypeOrConstParamData::TypeParamData(_) => { @@ -4650,7 +4659,7 @@ impl TypeOrConstParam { } } - pub fn as_const_param(self, db: &dyn HirDatabase) -> Option { + pub fn as_const_param(self, db: &dyn SourceDatabase) -> Option { let params = GenericParams::of(db, self.id.parent); match ¶ms[self.id.local_id] { TypeOrConstParamData::TypeParamData(_) => None, @@ -4667,12 +4676,12 @@ pub struct Impl { } impl Impl { - pub fn all_in_crate(db: &dyn HirDatabase, krate: Crate) -> Vec { + pub fn all_in_crate(db: &dyn SourceDatabase, krate: Crate) -> Vec { let mut result = Vec::new(); extend_with_def_map(db, crate_def_map(db, krate.id), &mut result); return result; - fn extend_with_def_map(db: &dyn HirDatabase, def_map: &DefMap, result: &mut Vec) { + fn extend_with_def_map(db: &dyn SourceDatabase, def_map: &DefMap, result: &mut Vec) { for (_, module) in def_map.modules() { result.extend(module.scope.impls().map(Impl::from)); result.extend(module.scope.builtin_derive_impls().map(Impl::from)); @@ -4686,7 +4695,7 @@ impl Impl { } } - pub fn all_in_module(db: &dyn HirDatabase, module: Module) -> Vec { + pub fn all_in_module(db: &dyn SourceDatabase, module: Module) -> Vec { module.impl_defs(db) } @@ -4695,7 +4704,7 @@ impl Impl { /// blanket impls, and only does a shallow type constructor check. In fact, this should've probably been on `Adt` /// etc., and not on `Type`. If you would want to create a precise list of all impls applying to a type, /// you would need to include blanket impls, and try to prove to predicates for each candidate. - pub fn all_for_type<'db>(db: &'db dyn HirDatabase, ty: Type<'db>) -> Vec { + pub fn all_for_type<'db>(db: &'db dyn SourceDatabase, ty: Type<'db>) -> Vec { let mut result = Vec::new(); let interner = DbInterner::new_no_crate(db); let Some(simplified_ty) = fast_reject::simplify_type( @@ -4738,7 +4747,7 @@ impl Impl { result } - pub fn all_for_trait(db: &dyn HirDatabase, trait_: Trait) -> Vec { + pub fn all_for_trait(db: &dyn SourceDatabase, trait_: Trait) -> Vec { let module = trait_.module(db).id; let mut all = Vec::new(); let mut handle_impls = |impls: &TraitImpls<'_>| { @@ -4758,7 +4767,7 @@ impl Impl { all } - pub fn trait_(self, db: &dyn HirDatabase) -> Option { + pub fn trait_(self, db: &dyn SourceDatabase) -> Option { match self.id { AnyImplId::ImplId(id) => { let trait_ref = db.impl_trait(id)?; @@ -4773,7 +4782,7 @@ impl Impl { } } - pub fn trait_ref(self, db: &dyn HirDatabase) -> Option> { + pub fn trait_ref(self, db: &dyn SourceDatabase) -> Option> { match self.id { AnyImplId::ImplId(id) => { let trait_ref = db.impl_trait(id)?.instantiate_identity().skip_norm_wip(); @@ -4791,7 +4800,7 @@ impl Impl { } } - pub fn self_ty(self, db: &dyn HirDatabase) -> Type<'_> { + pub fn self_ty(self, db: &dyn SourceDatabase) -> Type<'_> { match self.id { AnyImplId::ImplId(id) => { let ty = db.impl_self_ty(id).instantiate_identity().skip_norm_wip(); @@ -4808,7 +4817,7 @@ impl Impl { } } - pub fn items(self, db: &dyn HirDatabase) -> Vec { + pub fn items(self, db: &dyn SourceDatabase) -> Vec { match self.id { AnyImplId::ImplId(id) => { id.impl_items(db).items.iter().map(|&(_, it)| it.into()).collect() @@ -4827,35 +4836,35 @@ impl Impl { } } - pub fn is_negative(self, db: &dyn HirDatabase) -> bool { + pub fn is_negative(self, db: &dyn SourceDatabase) -> bool { match self.id { AnyImplId::ImplId(id) => ImplSignature::of(db, id).flags.contains(ImplFlags::NEGATIVE), AnyImplId::BuiltinDeriveImplId(_) => false, } } - pub fn is_unsafe(self, db: &dyn HirDatabase) -> bool { + pub fn is_unsafe(self, db: &dyn SourceDatabase) -> bool { match self.id { AnyImplId::ImplId(id) => ImplSignature::of(db, id).flags.contains(ImplFlags::UNSAFE), AnyImplId::BuiltinDeriveImplId(_) => false, } } - pub fn module(self, db: &dyn HirDatabase) -> Module { + pub fn module(self, db: &dyn SourceDatabase) -> Module { match self.id { AnyImplId::ImplId(id) => id.module(db).into(), AnyImplId::BuiltinDeriveImplId(id) => id.module(db).into(), } } - pub fn check_orphan_rules(self, db: &dyn HirDatabase) -> bool { + pub fn check_orphan_rules(self, db: &dyn SourceDatabase) -> bool { match self.id { AnyImplId::ImplId(id) => check_orphan_rules(db, id), AnyImplId::BuiltinDeriveImplId(_) => true, } } - fn all_macro_calls(&self, db: &dyn HirDatabase) -> Box<[(AstId, MacroCallId)]> { + fn all_macro_calls(&self, db: &dyn SourceDatabase) -> Box<[(AstId, MacroCallId)]> { match self.id { AnyImplId::ImplId(id) => id.impl_items(db).macro_calls.to_vec().into_boxed_slice(), AnyImplId::BuiltinDeriveImplId(_) => Box::default(), @@ -4909,7 +4918,7 @@ pub struct Closure<'db> { } impl<'db> Closure<'db> { - fn as_ty(&self, db: &'db dyn HirDatabase) -> Ty<'db> { + fn as_ty(&self, db: &'db dyn SourceDatabase) -> Ty<'db> { let interner = DbInterner::new_no_crate(db); match self.id { AnyClosureId::ClosureId(id) => Ty::new_closure(interner, id.into(), self.subst), @@ -4919,21 +4928,29 @@ impl<'db> Closure<'db> { } } - pub fn display_with_id(&self, db: &dyn HirDatabase, display_target: DisplayTarget) -> String { + pub fn display_with_id( + &self, + db: &dyn SourceDatabase, + display_target: DisplayTarget, + ) -> String { self.as_ty(db) .display(db, display_target) .with_closure_style(ClosureStyle::ClosureWithId) .to_string() } - pub fn display_with_impl(&self, db: &dyn HirDatabase, display_target: DisplayTarget) -> String { + pub fn display_with_impl( + &self, + db: &dyn SourceDatabase, + display_target: DisplayTarget, + ) -> String { self.as_ty(db) .display(db, display_target) .with_closure_style(ClosureStyle::ImplFn) .to_string() } - pub fn captured_items(&self, db: &'db dyn HirDatabase) -> Vec> { + pub fn captured_items(&self, db: &'db dyn SourceDatabase) -> Vec> { let closure = match self.id { AnyClosureId::ClosureId(it) => it.loc(db), AnyClosureId::CoroutineClosureId(it) => it.loc(db), @@ -4941,7 +4958,7 @@ impl<'db> Closure<'db> { captured_items(db, closure) } - pub fn fn_trait(&self, _db: &dyn HirDatabase) -> FnTrait { + pub fn fn_trait(&self, _db: &dyn SourceDatabase) -> FnTrait { match self.id { AnyClosureId::ClosureId(_) => match self.subst.as_closure().kind() { rustc_type_ir::ClosureKind::Fn => FnTrait::Fn, @@ -4965,13 +4982,13 @@ pub struct Coroutine<'db> { impl<'db> Coroutine<'db> { /// Returns the values captured by this coroutine. - pub fn captured_items(&self, db: &'db dyn HirDatabase) -> Vec> { + pub fn captured_items(&self, db: &'db dyn SourceDatabase) -> Vec> { captured_items(db, self.id.loc(db)) } } fn captured_items<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, closure: InternedClosure<'db>, ) -> Vec> { let InternedClosure { owner: infer_owner, expr: closure, .. } = closure; @@ -5045,7 +5062,7 @@ impl FnTrait { } } - pub fn get_id(self, db: &dyn HirDatabase, krate: Crate) -> Option { + pub fn get_id(self, db: &dyn SourceDatabase, krate: Crate) -> Option { Trait::lang(db, krate, self.lang_item()) } } @@ -5097,7 +5114,7 @@ impl<'db> ClosureCapture<'db> { } /// Converts the place to a name that can be inserted into source code. - pub fn place_to_name(&self, db: &dyn HirDatabase, edition: Edition) -> String { + pub fn place_to_name(&self, db: &dyn SourceDatabase, edition: Edition) -> String { let mut result = self.local().name(db).display(db, edition).to_string(); for (i, proj) in self.capture.place.projections.iter().enumerate() { match proj.kind { @@ -5127,7 +5144,7 @@ impl<'db> ClosureCapture<'db> { result } - pub fn display_place_source_code(&self, db: &dyn HirDatabase, edition: Edition) -> String { + pub fn display_place_source_code(&self, db: &dyn SourceDatabase, edition: Edition) -> String { let mut result = self.local().name(db).display(db, edition).to_string(); // We only need the derefs that have no field access after them, autoderef will do the rest. let mut last_derefs = 0; @@ -5163,13 +5180,13 @@ impl<'db> ClosureCapture<'db> { result } - pub fn ty(&self, db: &'db dyn HirDatabase) -> Type<'db> { + pub fn ty(&self, db: &'db dyn SourceDatabase) -> Type<'db> { Type::new_body(db, self.owner, self.capture.place.ty()) } /// The type that is stored in the closure, which is different from [`Self::ty()`], representing /// the place's type, when the capture is by ref. - pub fn captured_ty(&self, db: &'db dyn HirDatabase) -> Type<'db> { + pub fn captured_ty(&self, db: &'db dyn SourceDatabase) -> Type<'db> { Type::new_body(db, self.owner, self.capture.captured_ty(db)) } } @@ -5203,7 +5220,7 @@ impl CaptureUsages<'_> { } } - pub fn sources(&self, db: &dyn HirDatabase) -> Vec { + pub fn sources(&self, db: &dyn SourceDatabase) -> Vec { let (store, source_map) = ExpressionStore::with_source_map(db, self.parent); let mut result = Vec::with_capacity(self.sources.len()); for source in self.sources { @@ -5285,7 +5302,7 @@ impl TypeOwnerId<'_> { fn can_rebase_into( self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, rebase_into: Self, self_ty: EarlyBinder<'_, Ty<'_>>, ) -> bool { @@ -5360,7 +5377,7 @@ impl<'db> Type<'db> { Type { owner: TypeOwnerId::GenericDefId(owner), ty: EarlyBinder::bind(ty) } } - fn new_body(db: &dyn HirDatabase, owner: ExpressionStoreOwnerId, ty: Ty<'db>) -> Self { + fn new_body(db: &dyn SourceDatabase, owner: ExpressionStoreOwnerId, ty: Ty<'db>) -> Self { Self::new(owner.generic_def(db), ty) } @@ -5368,12 +5385,12 @@ impl<'db> Type<'db> { Type { owner: TypeOwnerId::NoParams(krate), ty: EarlyBinder::bind(ty) } } - fn builtin_type_crate(db: &'db dyn HirDatabase) -> base_db::Crate { + fn builtin_type_crate(db: &'db dyn SourceDatabase) -> base_db::Crate { // It doesn't really matter. all_crates(db)[0] } - fn from_def(db: &'db dyn HirDatabase, def: impl Into) -> Self { + fn from_def(db: &'db dyn SourceDatabase, def: impl Into) -> Self { let def = def.into(); let ty = db.ty(def); let owner = match def { @@ -5384,7 +5401,7 @@ impl<'db> Type<'db> { Type { owner, ty } } - fn from_value_def(db: &'db dyn HirDatabase, def: impl Into) -> Self { + fn from_value_def(db: &'db dyn SourceDatabase, def: impl Into) -> Self { let def = def.into(); let Some(ty) = db.value_ty(def) else { return Type::unknown(); @@ -5465,7 +5482,7 @@ impl<'db> Type<'db> { /// - `rebase_into` is in the context of a child of our context (for example, a function in an impl). pub fn try_rebase_into( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, rebase_into: &Type<'db>, ) -> Option { if self.owner.can_rebase_into(db, rebase_into.owner, self.ty) { @@ -5479,7 +5496,7 @@ impl<'db> Type<'db> { /// and returns that. pub fn rebase_into_or_error( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, rebase_into: &Type<'db>, ) -> Type<'db> { self.try_rebase_into(db, rebase_into).unwrap_or_else(|| self.instantiate_with_errors()) @@ -5487,7 +5504,7 @@ impl<'db> Type<'db> { pub fn try_rebase_into_owner( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, new_owner: GenericDef, ) -> Option { let new_owner = new_owner.id()?.into(); @@ -5500,7 +5517,7 @@ impl<'db> Type<'db> { pub fn rebase_into_owner_or_error( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, new_owner: GenericDef, ) -> Self { self.try_rebase_into_owner(db, new_owner).unwrap_or_else(|| self.instantiate_with_errors()) @@ -5514,13 +5531,13 @@ impl<'db> Type<'db> { ) } - pub fn new_slice(db: &'db dyn HirDatabase, ty: Self) -> Self { + pub fn new_slice(db: &'db dyn SourceDatabase, ty: Self) -> Self { let interner = DbInterner::new_no_crate(db); Type { owner: ty.owner, ty: ty.ty.map_bound(|ty| Ty::new_slice(interner, ty)) } } pub fn new_tuple( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, tys: impl IntoIterator>>, ) -> Self { let interner = DbInterner::new_no_crate(db); @@ -5575,7 +5592,7 @@ impl<'db> Type<'db> { matches!(self.ty.skip_binder().kind(), TyKind::Ref(..)) } - pub fn contains_reference(&self, db: &'db dyn HirDatabase) -> bool { + pub fn contains_reference(&self, db: &'db dyn SourceDatabase) -> bool { let interner = DbInterner::new_no_crate(db); return self .ty @@ -5584,7 +5601,7 @@ impl<'db> Type<'db> { .visit_with(&mut Visitor { interner }) .is_break(); - fn is_phantom_data(db: &dyn HirDatabase, adt_id: AdtId) -> bool { + fn is_phantom_data(db: &dyn SourceDatabase, adt_id: AdtId) -> bool { match adt_id { AdtId::StructId(s) => { let flags = StructSignature::of(db, s).flags; @@ -5669,7 +5686,7 @@ impl<'db> Type<'db> { self.as_reference().map(|(inner, _)| inner) } - pub fn add_reference(&self, db: &'db dyn HirDatabase, mutability: Mutability) -> Self { + pub fn add_reference(&self, db: &'db dyn SourceDatabase, mutability: Mutability) -> Self { let interner = DbInterner::new_no_crate(db); let ty_mutability = match mutability { Mutability::Shared => hir_ty::next_solver::Mutability::Not, @@ -5734,7 +5751,7 @@ impl<'db> Type<'db> { self.ty.skip_binder().is_ty_error() } - fn krate(&self, db: &'db dyn HirDatabase) -> base_db::Crate { + fn krate(&self, db: &'db dyn SourceDatabase) -> base_db::Crate { match self.owner { TypeOwnerId::GenericDefId(def) => hir_def::HasModule::krate(&def, db), TypeOwnerId::BuiltinDeriveImplId(def) => { @@ -5745,7 +5762,7 @@ impl<'db> Type<'db> { } } - fn param_env(&self, db: &'db dyn HirDatabase) -> ParamEnvAndCrate<'db> { + fn param_env(&self, db: &'db dyn SourceDatabase) -> ParamEnvAndCrate<'db> { let interner = DbInterner::new_no_crate(db); let krate = self.krate(db); match self.owner { @@ -5769,7 +5786,7 @@ impl<'db> Type<'db> { /// Checks that particular type `ty` implements `std::future::IntoFuture` or /// `std::future::Future` and returns the `Output` associated type. /// This function is used in `.await` syntax completion. - pub fn into_future_output(&self, db: &'db dyn HirDatabase) -> Option> { + pub fn into_future_output(&self, db: &'db dyn SourceDatabase) -> Option> { let env = self.param_env(db); let lang_items = hir_def::lang_item::lang_items(db, env.krate); let (trait_, output_assoc_type) = lang_items @@ -5790,7 +5807,7 @@ impl<'db> Type<'db> { } /// This does **not** resolve `IntoFuture`, only `Future`. - pub fn future_output(self, db: &'db dyn HirDatabase) -> Option> { + pub fn future_output(self, db: &'db dyn SourceDatabase) -> Option> { let krate = self.krate(db); let lang_items = hir_def::lang_item::lang_items(db, krate); let future_output = lang_items.FutureOutput?; @@ -5798,14 +5815,14 @@ impl<'db> Type<'db> { } /// This does **not** resolve `IntoIterator`, only `Iterator`. - pub fn iterator_item(self, db: &'db dyn HirDatabase) -> Option> { + pub fn iterator_item(self, db: &'db dyn SourceDatabase) -> Option> { let krate = self.krate(db); let lang_items = hir_def::lang_item::lang_items(db, krate); let iterator_item = lang_items.IteratorItem?; self.normalize_trait_assoc_type(db, &[], iterator_item.into()) } - pub fn impls_iterator(self, db: &'db dyn HirDatabase) -> bool { + pub fn impls_iterator(self, db: &'db dyn SourceDatabase) -> bool { let env = self.param_env(db); let lang_items = hir_def::lang_item::lang_items(db, env.krate); let Some(iterator_trait) = lang_items.Iterator else { @@ -5820,7 +5837,7 @@ impl<'db> Type<'db> { } /// Resolves the projection `::IntoIter` and returns the resulting type - pub fn into_iterator_iter(self, db: &'db dyn HirDatabase) -> Option> { + pub fn into_iterator_iter(self, db: &'db dyn SourceDatabase) -> Option> { let env = self.param_env(db); let lang_items = hir_def::lang_item::lang_items(db, env.krate); let trait_ = lang_items.IntoIterator?; @@ -5842,7 +5859,7 @@ impl<'db> Type<'db> { /// /// This function can be used to check if a particular type is callable, since FnOnce is a /// supertrait of Fn and FnMut, so all callable types implements at least FnOnce. - pub fn impls_fnonce(&self, db: &'db dyn HirDatabase) -> bool { + pub fn impls_fnonce(&self, db: &'db dyn SourceDatabase) -> bool { let env = self.param_env(db); let lang_items = hir_def::lang_item::lang_items(db, env.krate); let fnonce_trait = match lang_items.FnOnce { @@ -5859,7 +5876,12 @@ impl<'db> Type<'db> { } // FIXME: Find better API that also handles const generics - pub fn impls_trait(&self, db: &'db dyn HirDatabase, trait_: Trait, args: &[Type<'db>]) -> bool { + pub fn impls_trait( + &self, + db: &'db dyn SourceDatabase, + trait_: Trait, + args: &[Type<'db>], + ) -> bool { let env = self.param_env(db); let interner = DbInterner::new_no_crate(db); let (args, _owner) = @@ -5882,7 +5904,7 @@ impl<'db> Type<'db> { /// to this function. pub fn has_any_impl( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, trait_: Trait, args: &[Type<'db>], ) -> bool { @@ -5904,7 +5926,7 @@ impl<'db> Type<'db> { pub fn normalize_trait_assoc_type( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, args: &[Type<'db>], alias: TypeAlias, ) -> Option> { @@ -5927,7 +5949,7 @@ impl<'db> Type<'db> { if ty.is_ty_error() { None } else { Some(Type { owner, ty: EarlyBinder::bind(ty) }) } } - pub fn is_copy(&self, db: &'db dyn HirDatabase) -> bool { + pub fn is_copy(&self, db: &'db dyn SourceDatabase) -> bool { let env = self.param_env(db); let lang_items = hir_def::lang_item::lang_items(db, env.krate); let Some(copy_trait) = lang_items.Copy else { @@ -5936,7 +5958,7 @@ impl<'db> Type<'db> { self.impls_trait(db, copy_trait.into(), &[]) } - pub fn as_callable(&self, db: &'db dyn HirDatabase) -> Option> { + pub fn as_callable(&self, db: &'db dyn SourceDatabase) -> Option> { let interner = DbInterner::new_no_crate(db); let callee = match self.ty.skip_binder().kind() { TyKind::Closure(id, subst) => Callee::Closure(id.0, subst), @@ -5996,7 +6018,7 @@ impl<'db> Type<'db> { matches!(self.ty.skip_binder().kind(), TyKind::Array(..)) } - pub fn is_packed(&self, _db: &'db dyn HirDatabase) -> bool { + pub fn is_packed(&self, _db: &'db dyn SourceDatabase) -> bool { match self.ty.skip_binder().kind() { TyKind::Adt(adt_def, ..) => adt_def.is_packed(), _ => false, @@ -6034,7 +6056,7 @@ impl<'db> Type<'db> { self.ty.skip_binder().references_non_lt_error() } - pub fn fields(&self, db: &'db dyn HirDatabase) -> Vec<(Field, Self)> { + pub fn fields(&self, db: &'db dyn SourceDatabase) -> Vec<(Field, Self)> { let interner = DbInterner::new_no_crate(db); let (variant_id, substs) = match self.ty.skip_binder().kind() { TyKind::Adt(adt_def, substs) => { @@ -6058,7 +6080,7 @@ impl<'db> Type<'db> { .collect() } - pub fn tuple_fields(&self, _db: &'db dyn HirDatabase) -> Vec { + pub fn tuple_fields(&self, _db: &'db dyn SourceDatabase) -> Vec { if let TyKind::Tuple(substs) = self.ty.skip_binder().kind() { substs.iter().map(|ty| self.derived(ty)).collect() } else { @@ -6066,7 +6088,7 @@ impl<'db> Type<'db> { } } - pub fn as_array(&self, db: &'db dyn HirDatabase) -> Option<(Self, usize)> { + pub fn as_array(&self, db: &'db dyn SourceDatabase) -> Option<(Self, usize)> { if let TyKind::Array(ty, len) = self.ty.skip_binder().kind() { try_const_usize(db, len).map(|it| (self.derived(ty), it as usize)) } else { @@ -6077,7 +6099,7 @@ impl<'db> Type<'db> { // FIXME: We should probably remove this. pub fn fingerprint_for_trait_impl( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ) -> Option> { fast_reject::simplify_type( DbInterner::new_no_crate(db), @@ -6090,12 +6112,12 @@ impl<'db> Type<'db> { /// iterator won't yield the same type more than once even if the deref chain contains a cycle. pub fn autoderef( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ) -> impl Iterator> + use<'_, 'db> { self.autoderef_(db).map(move |ty| self.derived(ty)) } - fn autoderef_(&self, db: &'db dyn HirDatabase) -> impl Iterator> { + fn autoderef_(&self, db: &'db dyn SourceDatabase) -> impl Iterator> { let interner = DbInterner::new_no_crate(db); let env = self.param_env(db); // There should be no inference vars in types passed here @@ -6107,7 +6129,7 @@ impl<'db> Type<'db> { // lifetime problems, because we need to borrow temp `CrateImplDefs`. pub fn iterate_assoc_items( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, mut callback: impl FnMut(AssocItem) -> Option, ) -> Option { let mut slot = None; @@ -6120,7 +6142,7 @@ impl<'db> Type<'db> { fn iterate_assoc_items_dyn( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, callback: &mut dyn FnMut(AssocItemId) -> bool, ) { let mut handle_impls = |impls: &[ImplId]| { @@ -6210,7 +6232,7 @@ impl<'db> Type<'db> { /// ``` pub fn type_and_const_arguments<'a>( &'a self, - db: &'a dyn HirDatabase, + db: &'a dyn SourceDatabase, display_target: DisplayTarget, ) -> impl Iterator + 'a { self.ty @@ -6233,7 +6255,7 @@ impl<'db> Type<'db> { /// Combines lifetime indicators, type and constant parameters into a single `Iterator` pub fn generic_parameters<'a>( &'a self, - db: &'a dyn HirDatabase, + db: &'a dyn SourceDatabase, display_target: DisplayTarget, ) -> impl Iterator + 'a { // iterate the lifetime @@ -6249,7 +6271,7 @@ impl<'db> Type<'db> { pub fn iterate_method_candidates_with_traits( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, scope: &SemanticsScope<'_>, traits_in_scope: &FxHashSet, name: Option<&Name>, @@ -6271,7 +6293,7 @@ impl<'db> Type<'db> { pub fn iterate_method_candidates( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, scope: &SemanticsScope<'_>, name: Option<&Name>, callback: impl FnMut(Function) -> Option, @@ -6287,7 +6309,7 @@ impl<'db> Type<'db> { fn with_method_resolution( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: &Resolver<'db>, traits_in_scope: &FxHashSet, f: impl FnOnce(&MethodResolutionContext<'_, 'db>) -> R, @@ -6325,7 +6347,7 @@ impl<'db> Type<'db> { /// are considered inherent methods. pub fn iterate_method_candidates_split_inherent( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, scope: &SemanticsScope<'_>, traits_in_scope: &FxHashSet, name: Option<&Name>, @@ -6405,7 +6427,7 @@ impl<'db> Type<'db> { #[tracing::instrument(skip_all, fields(name = ?name))] pub fn iterate_path_candidates( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, scope: &SemanticsScope<'_>, traits_in_scope: &FxHashSet, name: Option<&Name>, @@ -6434,7 +6456,7 @@ impl<'db> Type<'db> { #[tracing::instrument(skip_all, fields(name = ?name))] pub fn iterate_path_candidates_split_inherent( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, scope: &SemanticsScope<'_>, traits_in_scope: &FxHashSet, name: Option<&Name>, @@ -6522,7 +6544,7 @@ impl<'db> Type<'db> { /// or an empty iterator otherwise. pub fn applicable_inherent_traits( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ) -> impl Iterator { let _p = tracing::info_span!("applicable_inherent_traits").entered(); self.autoderef_(db) @@ -6532,7 +6554,7 @@ impl<'db> Type<'db> { .map(Trait::from) } - pub fn env_traits(&self, db: &'db dyn HirDatabase) -> impl Iterator { + pub fn env_traits(&self, db: &'db dyn SourceDatabase) -> impl Iterator { let _p = tracing::info_span!("env_traits").entered(); let env = self.param_env(db); self.autoderef_(db) @@ -6551,7 +6573,10 @@ impl<'db> Type<'db> { .map(Trait::from) } - pub fn as_impl_traits(&self, db: &'db dyn HirDatabase) -> Option> { + pub fn as_impl_traits( + &self, + db: &'db dyn SourceDatabase, + ) -> Option> { self.ty.skip_binder().impl_trait_bounds(db).map(|it| { it.into_iter().filter_map(|pred| match pred.kind().skip_binder() { ClauseKind::Trait(trait_ref) => Some(Trait::from(trait_ref.def_id().0)), @@ -6560,7 +6585,7 @@ impl<'db> Type<'db> { }) } - pub fn as_associated_type_parent_trait(&self, db: &'db dyn HirDatabase) -> Option { + pub fn as_associated_type_parent_trait(&self, db: &'db dyn SourceDatabase) -> Option { let TyKind::Alias(AliasTy { kind: AliasTyKind::Projection { def_id }, .. }) = self.ty.skip_binder().kind() else { @@ -6578,9 +6603,9 @@ impl<'db> Type<'db> { /// Visits every type, including generic arguments, in this type. `callback` is called with type /// itself first, and then with its generic arguments. - pub fn walk(&self, db: &'db dyn HirDatabase, callback: impl FnMut(Type<'db>)) { + pub fn walk(&self, db: &'db dyn SourceDatabase, callback: impl FnMut(Type<'db>)) { struct Visitor<'db, F> { - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, owner: TypeOwnerId<'db>, callback: F, visited: FxHashSet>, @@ -6614,7 +6639,7 @@ impl<'db> Type<'db> { /// /// Note that we consider placeholder types to unify with everything. /// For example `Option` and `Option` unify although there is unresolved goal `T = U`. - pub fn could_unify_with(&self, db: &'db dyn HirDatabase, other: &Type<'db>) -> bool { + pub fn could_unify_with(&self, db: &'db dyn SourceDatabase, other: &Type<'db>) -> bool { self.owner.must_unify(other.owner); let env = self.param_env(db); let interner = DbInterner::new_no_crate(db); @@ -6629,7 +6654,7 @@ impl<'db> Type<'db> { /// /// This means that placeholder types are not considered to unify if there are any bounds set on /// them. For example `Option` and `Option` do not unify as we cannot show that `T = U` - pub fn could_unify_with_deeply(&self, db: &'db dyn HirDatabase, other: &Type<'db>) -> bool { + pub fn could_unify_with_deeply(&self, db: &'db dyn SourceDatabase, other: &Type<'db>) -> bool { self.owner.must_unify(other.owner); let env = self.param_env(db); let interner = DbInterner::new_no_crate(db); @@ -6640,7 +6665,7 @@ impl<'db> Type<'db> { hir_ty::could_unify_deeply(db, env, &tys) } - pub fn could_coerce_to(&self, db: &'db dyn HirDatabase, to: &Type<'db>) -> bool { + pub fn could_coerce_to(&self, db: &'db dyn SourceDatabase, to: &Type<'db>) -> bool { self.owner.must_unify(to.owner); let env = self.param_env(db); let interner = DbInterner::new_no_crate(db); @@ -6651,7 +6676,7 @@ impl<'db> Type<'db> { hir_ty::could_coerce(db, env, &tys) } - pub fn as_type_param(&self, _db: &'db dyn HirDatabase) -> Option { + pub fn as_type_param(&self, _db: &'db dyn SourceDatabase) -> Option { match self.ty.skip_binder().kind() { TyKind::Param(param) => Some(TypeParam { id: param.id }), _ => None, @@ -6659,20 +6684,20 @@ impl<'db> Type<'db> { } /// Returns unique `GenericParam`s contained in this type. - pub fn generic_params(&self, db: &'db dyn HirDatabase) -> FxHashSet { + pub fn generic_params(&self, db: &'db dyn SourceDatabase) -> FxHashSet { hir_ty::collect_params(&self.ty.skip_binder()) .into_iter() .map(|id| TypeOrConstParam { id }.split(db).either_into()) .collect() } - pub fn layout(&self, db: &'db dyn HirDatabase) -> Result, LayoutError> { + pub fn layout(&self, db: &'db dyn SourceDatabase) -> Result, LayoutError> { let env = self.param_env(db); db.layout_of_ty(self.ty.skip_binder().store(), env.store()) .map(|layout| Layout(layout, db.target_data_layout(env.krate).unwrap())) } - pub fn drop_glue(&self, db: &'db dyn HirDatabase) -> DropGlue { + pub fn drop_glue(&self, db: &'db dyn SourceDatabase) -> DropGlue { let env = self.param_env(db); let interner = DbInterner::new_with(db, env.krate); let infcx = interner.infer_ctxt().build(TypingMode::PostAnalysis); @@ -6688,11 +6713,11 @@ pub struct InlineAsmOperand { } impl InlineAsmOperand { - pub fn parent(self, _db: &dyn HirDatabase) -> ExpressionStoreOwner { + pub fn parent(self, _db: &dyn SourceDatabase) -> ExpressionStoreOwner { self.owner.into() } - pub fn name(&self, db: &dyn HirDatabase) -> Option { + pub fn name(&self, db: &dyn SourceDatabase) -> Option { let body = ExpressionStore::of(db, self.owner); match &body[self.expr] { hir_def::hir::Expr::InlineAsm(e) => e.operands.get(self.index)?.0.clone(), @@ -6770,7 +6795,7 @@ impl<'db> Callable<'db> { } } - pub fn receiver_param(&self, db: &'db dyn HirDatabase) -> Option<(SelfParam, Type<'db>)> { + pub fn receiver_param(&self, db: &'db dyn SourceDatabase) -> Option<(SelfParam, Type<'db>)> { if !self.is_bound_method { return None; } @@ -6965,7 +6990,7 @@ impl ScopeDef<'_> { items } - pub fn attrs(&self, db: &dyn HirDatabase) -> Option { + pub fn attrs(&self, db: &dyn SourceDatabase) -> Option { match self { ScopeDef::ModuleDef(it) => it.attrs(db), ScopeDef::GenericParam(it) => Some(it.attrs(db)), @@ -6977,7 +7002,7 @@ impl ScopeDef<'_> { } } - pub fn krate(&self, db: &dyn HirDatabase) -> Option { + pub fn krate(&self, db: &dyn SourceDatabase) -> Option { match self { ScopeDef::ModuleDef(it) => it.module(db).map(|m| m.krate(db)), ScopeDef::GenericParam(it) => Some(it.module(db).krate(db)), @@ -7026,8 +7051,8 @@ pub enum AutoBorrow { pub struct OverloadedDeref(pub Mutability); pub trait HasVisibility { - fn visibility(&self, db: &dyn HirDatabase) -> Visibility; - fn is_visible_from(&self, db: &dyn HirDatabase, module: Module) -> bool { + fn visibility(&self, db: &dyn SourceDatabase) -> Visibility; + fn is_visible_from(&self, db: &dyn SourceDatabase, module: Module) -> bool { let vis = self.visibility(db); vis.is_visible_from(db, module.id) } @@ -7062,129 +7087,129 @@ impl<'db> TraitPredicate<'db> { /// Trait for obtaining the defining crate of an item. pub trait HasCrate { - fn krate(&self, db: &dyn HirDatabase) -> Crate; + fn krate(&self, db: &dyn SourceDatabase) -> Crate; } impl HasCrate for T { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db).into() } } impl HasCrate for AssocItem { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for Struct { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for Union { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for Enum { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for Field { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.parent_def(db).module(db).krate(db) } } impl HasCrate for EnumVariant { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for Function { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for Const { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for TypeAlias { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for Type<'_> { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.krate(db).into() } } impl HasCrate for Macro { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for Trait { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for Static { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for Adt { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for Impl { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { self.module(db).krate(db) } } impl HasCrate for Module { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { Module::krate(*self, db) } } impl<'db> HasCrate for AnonConst<'db> { - fn krate(&self, db: &dyn HirDatabase) -> Crate { + fn krate(&self, db: &dyn SourceDatabase) -> Crate { hir_def::HasModule::krate(&self.id.loc(db).owner, db).into() } } pub trait HasContainer { - fn container(&self, db: &dyn HirDatabase) -> ItemContainer; + fn container(&self, db: &dyn SourceDatabase) -> ItemContainer; } impl HasContainer for ExternCrateDecl { - fn container(&self, db: &dyn HirDatabase) -> ItemContainer { + fn container(&self, db: &dyn SourceDatabase) -> ItemContainer { container_id_to_hir(self.id.lookup(db).container.into()) } } impl HasContainer for Module { - fn container(&self, db: &dyn HirDatabase) -> ItemContainer { + fn container(&self, db: &dyn SourceDatabase) -> ItemContainer { // FIXME: handle block expressions as modules (their parent is in a different DefMap) let def_map = self.id.def_map(db); match def_map[self.id].parent { @@ -7195,7 +7220,7 @@ impl HasContainer for Module { } impl HasContainer for Function { - fn container(&self, db: &dyn HirDatabase) -> ItemContainer { + fn container(&self, db: &dyn SourceDatabase) -> ItemContainer { match self.id { AnyFunctionId::FunctionId(id) => container_id_to_hir(id.lookup(db).container), AnyFunctionId::BuiltinDeriveImplMethod { impl_, .. } => { @@ -7206,62 +7231,62 @@ impl HasContainer for Function { } impl HasContainer for Struct { - fn container(&self, db: &dyn HirDatabase) -> ItemContainer { + fn container(&self, db: &dyn SourceDatabase) -> ItemContainer { ItemContainer::Module(Module { id: self.id.lookup(db).container }) } } impl HasContainer for Union { - fn container(&self, db: &dyn HirDatabase) -> ItemContainer { + fn container(&self, db: &dyn SourceDatabase) -> ItemContainer { ItemContainer::Module(Module { id: self.id.lookup(db).container }) } } impl HasContainer for Enum { - fn container(&self, db: &dyn HirDatabase) -> ItemContainer { + fn container(&self, db: &dyn SourceDatabase) -> ItemContainer { ItemContainer::Module(Module { id: self.id.lookup(db).container }) } } impl HasContainer for TypeAlias { - fn container(&self, db: &dyn HirDatabase) -> ItemContainer { + fn container(&self, db: &dyn SourceDatabase) -> ItemContainer { container_id_to_hir(self.id.lookup(db).container) } } impl HasContainer for Const { - fn container(&self, db: &dyn HirDatabase) -> ItemContainer { + fn container(&self, db: &dyn SourceDatabase) -> ItemContainer { container_id_to_hir(self.id.lookup(db).container) } } impl HasContainer for Static { - fn container(&self, db: &dyn HirDatabase) -> ItemContainer { + fn container(&self, db: &dyn SourceDatabase) -> ItemContainer { container_id_to_hir(self.id.lookup(db).container) } } impl HasContainer for Trait { - fn container(&self, db: &dyn HirDatabase) -> ItemContainer { + fn container(&self, db: &dyn SourceDatabase) -> ItemContainer { ItemContainer::Module(Module { id: self.id.lookup(db).container }) } } impl HasContainer for ExternBlock { - fn container(&self, db: &dyn HirDatabase) -> ItemContainer { + fn container(&self, db: &dyn SourceDatabase) -> ItemContainer { ItemContainer::Module(Module { id: self.id.lookup(db).container }) } } pub trait HasName { - fn name(&self, db: &dyn HirDatabase) -> Option; + fn name(&self, db: &dyn SourceDatabase) -> Option; } macro_rules! impl_has_name { ( $( $ty:ident ),* $(,)? ) => { $( impl HasName for $ty { - fn name(&self, db: &dyn HirDatabase) -> Option { + fn name(&self, db: &dyn SourceDatabase) -> Option { (*self).name(db).into() } } @@ -7304,7 +7329,7 @@ macro_rules! impl_has_name_no_db { ( $( $ty:ident ),* $(,)? ) => { $( impl HasName for $ty { - fn name(&self, _db: &dyn HirDatabase) -> Option { + fn name(&self, _db: &dyn SourceDatabase) -> Option { (*self).name().into() } } @@ -7315,19 +7340,19 @@ macro_rules! impl_has_name_no_db { impl_has_name_no_db!(StaticLifetime, BuiltinType, BuiltinAttr); impl HasName for Local<'_> { - fn name(&self, db: &dyn HirDatabase) -> Option { + fn name(&self, db: &dyn SourceDatabase) -> Option { (*self).name(db).into() } } impl HasName for TupleField<'_> { - fn name(&self, _db: &dyn HirDatabase) -> Option { + fn name(&self, _db: &dyn SourceDatabase) -> Option { (*self).name().into() } } impl HasName for Param<'_> { - fn name(&self, db: &dyn HirDatabase) -> Option { + fn name(&self, db: &dyn SourceDatabase) -> Option { self.name(db) } } @@ -7358,7 +7383,7 @@ pub enum DocLinkDef { } fn push_ty_diagnostics<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, acc: &mut Vec>, diagnostics: &[TyLoweringDiagnostic], source_map: &ExpressionStoreSourceMap, @@ -7409,7 +7434,7 @@ where } pub fn resolve_absolute_path<'a, I: Iterator + Clone + 'a>( - db: &'a dyn HirDatabase, + db: &'a dyn SourceDatabase, mut segments: I, ) -> impl Iterator + use<'a, I> { segments @@ -7486,7 +7511,7 @@ fn generic_args_from_tys<'db>( (args, owner) } -fn has_non_default_type_params(db: &dyn HirDatabase, generic_def: GenericDefId) -> bool { +fn has_non_default_type_params(db: &dyn SourceDatabase, generic_def: GenericDefId) -> bool { let params = GenericParams::of(db, generic_def); let defaults = db.generic_defaults(generic_def); params @@ -7500,7 +7525,7 @@ fn has_non_default_type_params(db: &dyn HirDatabase, generic_def: GenericDefId) } fn param_env_from_has_crate<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, id: impl hir_def::HasModule + Into + Copy, ) -> ParamEnvAndCrate<'db> { ParamEnvAndCrate { param_env: db.trait_environment(id.into()), krate: id.krate(db) } @@ -7508,18 +7533,18 @@ fn param_env_from_has_crate<'db>( // FIXME: We probably don't want to expose this. pub trait MacroCallIdExt { - fn loc(self, db: &dyn HirDatabase) -> &hir_expand::MacroCallLoc; + fn loc(self, db: &dyn SourceDatabase) -> &hir_expand::MacroCallLoc; } impl MacroCallIdExt for span::MacroCallId { #[inline] - fn loc(self, db: &dyn HirDatabase) -> &hir_expand::MacroCallLoc { + fn loc(self, db: &dyn SourceDatabase) -> &hir_expand::MacroCallLoc { hir_expand::MacroCallId::from(self).loc(db) } } // Like https://github.com/rust-lang/rust/blob/7c3c88f42ad444f4688b865591d84660be4ece2f/compiler/rustc_middle/src/ty/util.rs#L254-L310 pub fn struct_tail_raw<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, interner: DbInterner<'db>, mut ty: Ty<'db>, mut normalize: impl FnMut(Ty<'db>) -> Ty<'db>, diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index f298e25489a5..64e14884a466 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -169,7 +169,7 @@ type ExprToAnonConst<'db> = FxHashMap>; type DefAnonConstsMap<'db> = FxHashMap>; pub struct SemanticsImpl<'db> { - pub db: &'db dyn HirDatabase, + pub db: &'db dyn SourceDatabase, s2d_cache: RefCell>, /// MacroCall to its expansion's MacroCallId cache macro_call_cache: RefCell, MacroCallId>>, @@ -203,9 +203,9 @@ pub enum LintAttr { // Note: while this variant of `Semantics<'_, _>` might seem unused, as it does not // find actual use within the rust-analyzer project itself, it exists to enable the use // within e.g. tracked salsa functions in third-party crates that build upon `ra_ap_hir`. -impl Semantics<'_, dyn HirDatabase> { +impl Semantics<'_, dyn SourceDatabase> { /// Creates an instance that's weakly coupled to its underlying database type. - pub fn new_dyn(db: &'_ dyn HirDatabase) -> Semantics<'_, dyn HirDatabase> { + pub fn new_dyn(db: &'_ dyn SourceDatabase) -> Semantics<'_, dyn SourceDatabase> { let impl_ = SemanticsImpl::new(db); Semantics { db, imp: impl_ } } @@ -220,7 +220,7 @@ impl Semantics<'_, DB> { } // Note: We take `DB` as `?Sized` here in order to support type-erased -// use of `Semantics` via `Semantics<'_, dyn HirDatabase>`: +// use of `Semantics` via `Semantics<'_, dyn SourceDatabase>`: impl Semantics<'_, DB> { pub fn hir_file_for(&self, syntax_node: &SyntaxNode) -> HirFileId { self.imp.find_file(syntax_node).file_id @@ -459,7 +459,7 @@ impl Semantics<'_, DB> { } impl<'db> SemanticsImpl<'db> { - fn new(db: &'db dyn HirDatabase) -> Self { + fn new(db: &'db dyn SourceDatabase) -> Self { SemanticsImpl { db, s2d_cache: Default::default(), @@ -2715,7 +2715,7 @@ impl<'db> ToDef<'db> for ast::IdentPat { /// you'd better use the `resolve_` family of methods. #[derive(Debug)] pub struct SemanticsScope<'db> { - pub db: &'db dyn HirDatabase, + pub db: &'db dyn SourceDatabase, infer_body: Option>, file_id: HirFileId, resolver: Resolver<'db>, @@ -2884,7 +2884,7 @@ impl ops::Deref for VisibleTraits { } struct RenameConflictsVisitor<'a> { - db: &'a dyn HirDatabase, + db: &'a dyn SourceDatabase, owner: ExpressionStoreOwnerId, resolver: Resolver<'a>, body: &'a ExpressionStore, diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index caa7b39885fe..c46c7683f353 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -142,7 +142,7 @@ impl<'db> SourceToDefCache<'db> { pub(super) fn get_or_insert_include_for( &mut self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, file: EditionedFileId, ) -> Option { if let Some(&m) = self.included_file_cache.get(&file) { @@ -159,7 +159,7 @@ impl<'db> SourceToDefCache<'db> { pub(super) fn get_or_insert_expansion( &mut self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, macro_file: MacroCallId, ) -> &ExpansionInfo<'db> { self.expansion_info_cache.entry(macro_file).or_insert_with(|| { @@ -186,7 +186,7 @@ impl<'db> SourceToDefCache<'db> { } pub(super) struct SourceToDefCtx<'db, 'cache> { - pub(super) db: &'db dyn HirDatabase, + pub(super) db: &'db dyn SourceDatabase, pub(super) cache: &'cache mut SourceToDefCache<'db>, } @@ -745,7 +745,7 @@ impl_from! { } impl ChildContainer { - fn child_by_source(self, db: &dyn HirDatabase, file_id: HirFileId) -> DynMap { + fn child_by_source(self, db: &dyn SourceDatabase, file_id: HirFileId) -> DynMap { let _p = tracing::info_span!("ChildContainer::child_by_source").entered(); match self { ChildContainer::DefWithBodyId(it) => it.child_by_source(db, file_id), diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index e80567641baf..bf9634d96c79 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -108,7 +108,7 @@ pub(crate) enum BodyOrSig<'db> { impl<'db> SourceAnalyzer<'db> { pub(crate) fn new_for_body( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: DefWithBodyId, node: InFile<&SyntaxNode>, offset: Option, @@ -117,7 +117,7 @@ impl<'db> SourceAnalyzer<'db> { } pub(crate) fn new_for_body_no_infer( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: DefWithBodyId, node: InFile<&SyntaxNode>, offset: Option, @@ -126,7 +126,7 @@ impl<'db> SourceAnalyzer<'db> { } pub(crate) fn new_for_body_( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: DefWithBodyId, node @ InFile { file_id, .. }: InFile<&SyntaxNode>, offset: Option, @@ -158,7 +158,7 @@ impl<'db> SourceAnalyzer<'db> { } pub(crate) fn new_generic_def( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, sema: &SemanticsImpl<'db>, def: GenericDefId, node: InFile<&SyntaxNode>, @@ -168,7 +168,7 @@ impl<'db> SourceAnalyzer<'db> { } pub(crate) fn new_generic_def_no_infer( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, sema: &SemanticsImpl<'db>, def: GenericDefId, node: InFile<&SyntaxNode>, @@ -178,7 +178,7 @@ impl<'db> SourceAnalyzer<'db> { } pub(crate) fn new_generic_def_( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, sema: &SemanticsImpl<'db>, def: GenericDefId, node @ InFile { file_id, .. }: InFile<&SyntaxNode>, @@ -223,7 +223,7 @@ impl<'db> SourceAnalyzer<'db> { } pub(crate) fn new_variant_body( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, sema: &SemanticsImpl<'db>, def: VariantId, node @ InFile { file_id, .. }: InFile<&SyntaxNode>, @@ -349,7 +349,7 @@ impl<'db> SourceAnalyzer<'db> { ParamEnvAndCrate { param_env, krate: self.resolver.krate() } } - fn trait_environment(&self, db: &'db dyn HirDatabase) -> ParamEnvAndCrate<'db> { + fn trait_environment(&self, db: &'db dyn SourceDatabase) -> ParamEnvAndCrate<'db> { self.param_and(self.body_or_sig.as_ref().map_or_else( || ParamEnv::empty(DbInterner::new_no_crate(db)), |body_or_sig| { @@ -369,7 +369,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn evaluate_where_clause( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, where_clause: ast::WhereClause, ) -> PredicateEvaluationResult { let Some(owner) = self.owner() else { @@ -450,7 +450,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn type_of_type( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, ty: &ast::Type, ) -> Option> { let interner = DbInterner::new_no_crate(db); @@ -505,7 +505,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn expr_is_diverging( &self, - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, expr: &ast::Expr, ) -> Option { let expr_id = self.expr_id(expr.clone())?; @@ -534,7 +534,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn type_of_expr( &self, - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, expr: &ast::Expr, ) -> Option<(Type<'db>, Option>)> { let expr_id = self.expr_id(expr.clone())?; @@ -550,7 +550,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn type_of_pat( &self, - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, pat: &ast::Pat, ) -> Option<(Type<'db>, Option>)> { let expr_or_pat_id = self.pat_id(pat)?; @@ -573,7 +573,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn type_of_binding_in_pat( &self, - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, pat: &ast::IdentPat, ) -> Option> { let binding_id = self.binding_id_of_pat(pat)?; @@ -585,7 +585,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn type_of_self( &self, - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, _param: &ast::SelfParam, ) -> Option> { let binding = match self.body_or_sig.as_ref()? { @@ -598,7 +598,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn binding_mode_of_pat( &self, - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, pat: &ast::IdentPat, ) -> Option { let id = self.pat_id(&pat.clone().into())?; @@ -615,7 +615,7 @@ impl<'db> SourceAnalyzer<'db> { } pub(crate) fn pattern_adjustments( &self, - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, pat: &ast::Pat, ) -> Option; 1]>> { let pat_id = self.pat_id(pat)?; @@ -631,7 +631,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_method_call_as_callable( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, call: &ast::MethodCallExpr, ) -> Option> { let expr_id = self.expr_id(call.clone().into())?.as_expr()?; @@ -646,7 +646,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_method_call( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, call: &ast::MethodCallExpr, ) -> Option { let expr_id = self.expr_id(call.clone().into())?.as_expr()?; @@ -657,7 +657,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_method_call_fallback( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, call: &ast::MethodCallExpr, ) -> Option<(Either, Option>)> { let expr_id = self.expr_id(call.clone().into())?.as_expr()?; @@ -681,7 +681,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_expr_as_callable( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, call: &ast::Expr, ) -> Option> { let (orig, adjusted) = self.type_of_expr(db, &call.clone())?; @@ -703,7 +703,7 @@ impl<'db> SourceAnalyzer<'db> { &self, field_expr: ExprId, infer: &InferenceResult<'_>, - _db: &'db dyn HirDatabase, + _db: &'db dyn SourceDatabase, ) -> Option> { let body = self.store()?; if let Expr::Field { expr: object_expr, name: _ } = body[field_expr] { @@ -715,7 +715,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_field_fallback( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, field: &ast::FieldExpr, ) -> Option<(Either>, Function>, Option>)> { @@ -746,7 +746,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_range_pat( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, range_pat: &ast::RangePat, ) -> Option { self.resolve_range_struct( @@ -759,7 +759,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_range_expr( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, range_expr: &ast::RangeExpr, ) -> Option { self.resolve_range_struct( @@ -772,7 +772,7 @@ impl<'db> SourceAnalyzer<'db> { fn resolve_range_struct( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, op_kind: RangeOp, has_start: bool, has_end: bool, @@ -818,7 +818,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_await_to_poll( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, await_expr: &ast::AwaitExpr, ) -> Option { let mut ty = self.ty_of_expr(await_expr.expr()?)?; @@ -854,7 +854,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_prefix_expr( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, prefix_expr: &ast::PrefixExpr, ) -> Option { let lang_items = self.lang_items(db); @@ -889,7 +889,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_index_expr( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, index_expr: &ast::IndexExpr, ) -> Option { let base_ty = self.ty_of_expr(index_expr.base()?)?; @@ -915,7 +915,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_bin_expr( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, binop_expr: &ast::BinExpr, ) -> Option { let op = binop_expr.op_kind()?; @@ -933,7 +933,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_try_expr( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, try_expr: &ast::TryExpr, ) -> Option { let ty = self.ty_of_expr(try_expr.expr()?)?; @@ -948,7 +948,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_record_field( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, field: &ast::RecordExprField, ) -> Option<(Field, Option>, Type<'db>, GenericSubstitution<'db>)> { let record_expr = ast::RecordExpr::cast(field.syntax().parent().and_then(|p| p.parent())?)?; @@ -997,7 +997,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_record_pat_field( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, field: &ast::RecordPatField, ) -> Option<(Field, Type<'db>, GenericSubstitution<'db>)> { let interner = DbInterner::new_no_crate(db); @@ -1021,7 +1021,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_tuple_struct_pat_fields( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, tuple_struct_pat: &ast::TupleStructPat, ) -> Option)>> { let interner = DbInterner::new_no_crate(db); @@ -1043,7 +1043,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_bind_pat_to_const( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, pat: &ast::IdentPat, ) -> Option { let expr_or_pat_id = self.pat_id(&pat.clone().into())?; @@ -1085,7 +1085,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_offset_of_field( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, name_ref: &ast::NameRef, ) -> Option<(Either, GenericSubstitution<'db>)> { let offset_of_expr = ast::OffsetOfExpr::cast(name_ref.syntax().parent()?)?; @@ -1159,7 +1159,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_path( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, path: &ast::Path, ) -> Option<(PathResolution<'db>, Option>)> { let parent = path.syntax().parent(); @@ -1487,7 +1487,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn resolve_hir_path_per_ns( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, path: &ast::Path, ) -> Option> { let mut collector = @@ -1509,7 +1509,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn record_literal_missing_fields( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, literal: &ast::RecordExpr, ) -> Option)>> { let body = self.store()?; @@ -1525,7 +1525,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn record_literal_matched_fields( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, literal: &ast::RecordExpr, ) -> Option)>> { let body = self.store()?; @@ -1542,7 +1542,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn record_pattern_missing_fields( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, pattern: &ast::RecordPat, ) -> Option)>> { let body = self.store()?; @@ -1559,7 +1559,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn record_pattern_matched_fields( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, pattern: &ast::RecordPat, ) -> Option)>> { let body = self.store()?; @@ -1576,7 +1576,7 @@ impl<'db> SourceAnalyzer<'db> { fn missing_fields( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, substs: GenericArgs<'db>, variant: VariantId, missing_fields: Vec, @@ -1602,7 +1602,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn is_unsafe_macro_call_expr( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, macro_expr: InFile<&ast::MacroExpr>, ) -> bool { if let Some((def, body, sm, Some(infer))) = self.def() @@ -1626,7 +1626,7 @@ impl<'db> SourceAnalyzer<'db> { /// Returns the range of the implicit template argument and its resolution at the given `offset` pub(crate) fn resolve_offset_in_format_args( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, format_args: InFile<&ast::FormatArgsExpr>, offset: TextSize, ) -> Option<(TextRange, Option>)> { @@ -1668,7 +1668,7 @@ impl<'db> SourceAnalyzer<'db> { pub(crate) fn as_format_args_parts<'a>( &'a self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, format_args: InFile<&ast::FormatArgsExpr>, ) -> Option>)> + 'a> { let (hygiene, names) = self.store_sm()?.implicit_format_args(format_args)?; @@ -1701,7 +1701,7 @@ impl<'db> SourceAnalyzer<'db> { fn resolve_impl_method_or_trait_def( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, func: FunctionId, substs: GenericArgs<'db>, ) -> Function { @@ -1710,7 +1710,7 @@ impl<'db> SourceAnalyzer<'db> { fn resolve_impl_method_or_trait_def_with_subst( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, func: FunctionId, substs: GenericArgs<'db>, ) -> (Function, GenericArgs<'db>) { @@ -1730,7 +1730,7 @@ impl<'db> SourceAnalyzer<'db> { fn resolve_impl_const_or_trait_def_with_subst( &self, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, const_id: ConstId, subs: GenericArgs<'db>, ) -> (ConstId, GenericArgs<'db>) { @@ -1744,7 +1744,7 @@ impl<'db> SourceAnalyzer<'db> { method_resolution::lookup_impl_const(&infcx, env.param_env, const_id, subs) } - fn lang_items<'a>(&self, db: &'a dyn HirDatabase) -> &'a LangItems { + fn lang_items<'a>(&self, db: &'a dyn SourceDatabase) -> &'a LangItems { hir_def::lang_item::lang_items(db, self.resolver.krate()) } @@ -1756,7 +1756,7 @@ impl<'db> SourceAnalyzer<'db> { // Note: the `ExprId` here does not need to be accurate, what's important is that it points at the same // inference root. fn scope_for( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, scopes: &ExprScopes, source_map: &ExpressionStoreSourceMap, node: InFile<&SyntaxNode>, @@ -1775,7 +1775,7 @@ fn scope_for( } fn scope_for_offset( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, scopes: &ExprScopes, source_map: &ExpressionStoreSourceMap, from_file: HirFileId, @@ -1811,7 +1811,7 @@ fn scope_for_offset( // XXX: during completion, cursor might be outside of any particular // expression. Try to figure out the correct scope... fn adjust( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, scopes: &ExprScopes, source_map: &ExpressionStoreSourceMap, expr_range: TextRange, @@ -1850,7 +1850,7 @@ fn adjust( #[inline] pub(crate) fn resolve_hir_path<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: &Resolver<'db>, infer_body: Option>, path: &Path, @@ -1862,7 +1862,7 @@ pub(crate) fn resolve_hir_path<'db>( #[inline] pub(crate) fn resolve_hir_path_as_attr_macro( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, resolver: &Resolver<'_>, path: &Path, ) -> Option { @@ -1873,7 +1873,7 @@ pub(crate) fn resolve_hir_path_as_attr_macro( } fn resolve_hir_path_<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: &Resolver<'db>, infer_body: Option>, path: &Path, @@ -2039,7 +2039,7 @@ fn resolve_hir_path_<'db>( } fn resolve_hir_value_path<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: &Resolver<'db>, store_owner: Option, infer_body: Option>, @@ -2081,7 +2081,7 @@ fn resolve_hir_value_path<'db>( /// ``` /// then we know that `foo` in `my::foo::Bar` refers to the module, not the function. fn resolve_hir_path_qualifier<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, resolver: &Resolver<'db>, path: &Path, store: &ExpressionStore, @@ -2164,7 +2164,7 @@ fn resolve_hir_path_qualifier<'db>( }) } -pub(crate) fn name_hygiene(db: &dyn HirDatabase, name: InFile<&SyntaxNode>) -> HygieneId { +pub(crate) fn name_hygiene(db: &dyn SourceDatabase, name: InFile<&SyntaxNode>) -> HygieneId { let Some(macro_file) = name.file_id.macro_file() else { return HygieneId::ROOT; }; @@ -2174,7 +2174,7 @@ pub(crate) fn name_hygiene(db: &dyn HirDatabase, name: InFile<&SyntaxNode>) -> H } fn record_literal_matched_fields( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, infer: &InferenceResult<'_>, id: ExprId, expr: &Expr, @@ -2206,7 +2206,7 @@ fn record_literal_matched_fields( } fn record_pattern_matched_fields( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, infer: &InferenceResult<'_>, id: PatId, pat: &Pat, diff --git a/crates/hir/src/symbols.rs b/crates/hir/src/symbols.rs index 79a075ef8bc7..f3af5de1b007 100644 --- a/crates/hir/src/symbols.rs +++ b/crates/hir/src/symbols.rs @@ -93,7 +93,7 @@ struct SymbolCollectorWork { } pub struct SymbolCollector<'db> { - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, symbols: FxIndexSet>, work: Vec, current_container_name: Option, @@ -103,7 +103,7 @@ pub struct SymbolCollector<'db> { /// Given a [`ModuleId`] and a [`HirDatabase`], use the DefMap for the module's crate to collect /// all symbols that should be indexed for the given module. impl<'a> SymbolCollector<'a> { - pub fn new(db: &'a dyn HirDatabase, collect_pub_only: bool) -> Self { + pub fn new(db: &'a dyn SourceDatabase, collect_pub_only: bool) -> Self { SymbolCollector { db, symbols: Default::default(), @@ -114,7 +114,7 @@ impl<'a> SymbolCollector<'a> { } pub fn new_module( - db: &'a dyn HirDatabase, + db: &'a dyn SourceDatabase, module: Module, collect_pub_only: bool, ) -> Box<[FileSymbol<'a>]> { diff --git a/crates/hir/src/term_search.rs b/crates/hir/src/term_search.rs index 1cc6766bfb3b..b9726ffdbb37 100644 --- a/crates/hir/src/term_search.rs +++ b/crates/hir/src/term_search.rs @@ -110,7 +110,7 @@ impl<'db> LookupTable<'db> { } /// Find all `Expr`s that unify with the `ty` - fn find(&mut self, db: &'db dyn HirDatabase, ty: &Type<'db>) -> Option>> { + fn find(&mut self, db: &'db dyn SourceDatabase, ty: &Type<'db>) -> Option>> { let res = self .data .iter() @@ -135,7 +135,11 @@ impl<'db> LookupTable<'db> { /// /// For example if we have type `i32` in data and we query for `&i32` it map all the type /// trees we have for `i32` with `Expr::Reference` and returns them. - fn find_autoref(&mut self, db: &'db dyn HirDatabase, ty: &Type<'db>) -> Option>> { + fn find_autoref( + &mut self, + db: &'db dyn SourceDatabase, + ty: &Type<'db>, + ) -> Option>> { let res = self .data .iter() diff --git a/crates/hir/src/term_search/expr.rs b/crates/hir/src/term_search/expr.rs index 07994268696e..b4e4843153f2 100644 --- a/crates/hir/src/term_search/expr.rs +++ b/crates/hir/src/term_search/expr.rs @@ -303,7 +303,7 @@ impl<'db> Expr<'db> { /// Get type of the type tree. /// /// Same as getting the type of root node - pub fn ty(&self, db: &'db dyn HirDatabase) -> Type<'db> { + pub fn ty(&self, db: &'db dyn SourceDatabase) -> Type<'db> { match self { Expr::Const(it) => it.ty(db), Expr::Static(it) => it.ty(db), @@ -328,7 +328,7 @@ impl<'db> Expr<'db> { } /// List the traits used in type tree - pub fn traits_used(&self, db: &dyn HirDatabase) -> Vec { + pub fn traits_used(&self, db: &dyn SourceDatabase) -> Vec { let mut res = Vec::new(); if let Expr::Method { func, params, .. } = self { @@ -352,7 +352,7 @@ impl<'db> Expr<'db> { /// macro!().bar() /// ¯o!() /// ``` - fn contains_many_in_illegal_pos(&self, db: &dyn HirDatabase) -> bool { + fn contains_many_in_illegal_pos(&self, db: &dyn SourceDatabase) -> bool { match self { Expr::Method { target, func, .. } => { match func.as_assoc_item(db).and_then(|it| it.container_or_implemented_trait(db)) { diff --git a/crates/ide-assists/src/handlers/auto_import.rs b/crates/ide-assists/src/handlers/auto_import.rs index dd082476d2d6..a7370f580a33 100644 --- a/crates/ide-assists/src/handlers/auto_import.rs +++ b/crates/ide-assists/src/handlers/auto_import.rs @@ -314,7 +314,7 @@ pub(crate) fn relevance_score( } /// A heuristic that gives a higher score to modules that are more separated. -fn module_distance_heuristic(db: &dyn HirDatabase, current: &Module, item: &Module) -> usize { +fn module_distance_heuristic(db: &dyn SourceDatabase, current: &Module, item: &Module) -> usize { // get the path starting from the item to the respective crate roots let mut current_path = current.path_to_root(db); let mut item_path = item.path_to_root(db); diff --git a/crates/ide-assists/src/handlers/fix_visibility.rs b/crates/ide-assists/src/handlers/fix_visibility.rs index d0f5c7c5003d..22e17645e3d2 100644 --- a/crates/ide-assists/src/handlers/fix_visibility.rs +++ b/crates/ide-assists/src/handlers/fix_visibility.rs @@ -111,11 +111,11 @@ fn add_vis_to_referenced_module_def(acc: &mut Assists, ctx: &AssistContext<'_, ' } fn target_data_for_def( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: hir::ModuleDef, ) -> Option<(ast::AnyHasVisibility, TextRange, FileId, Option)> { fn offset_target_and_file_id( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, x: S, ) -> Option<(ast::AnyHasVisibility, TextRange, FileId)> where diff --git a/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/crates/ide-assists/src/handlers/generate_delegate_trait.rs index e21f1ab35984..f3c1dfbb4f89 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_trait.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_trait.rs @@ -178,7 +178,7 @@ impl Delegee { } } - fn signature(&self, db: &dyn HirDatabase, edition: Edition) -> String { + fn signature(&self, db: &dyn SourceDatabase, edition: Edition) -> String { let mut s = String::new(); let it = self.trait_(); diff --git a/crates/ide-assists/src/handlers/generate_function.rs b/crates/ide-assists/src/handlers/generate_function.rs index 3c3fde80f99e..a1afe9b5c613 100644 --- a/crates/ide-assists/src/handlers/generate_function.rs +++ b/crates/ide-assists/src/handlers/generate_function.rs @@ -1308,7 +1308,7 @@ fn next_space_for_fn_after_call_site(expr: ast::CallableExpr) -> Option Option<(FileId, GeneratedFunctionTarget)> { let module_source = target_module.definition_source(db); diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs index fd67617be45d..3f56b8a1d6ea 100644 --- a/crates/ide-assists/src/handlers/inline_call.rs +++ b/crates/ide-assists/src/handlers/inline_call.rs @@ -307,7 +307,7 @@ impl CallInfo { } fn get_fn_params<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, function: hir::Function, param_list: &ast::ParamList, make: &SyntaxFactory, diff --git a/crates/ide-assists/src/handlers/qualify_method_call.rs b/crates/ide-assists/src/handlers/qualify_method_call.rs index edf0a855c4fe..625cdeb36936 100644 --- a/crates/ide-assists/src/handlers/qualify_method_call.rs +++ b/crates/ide-assists/src/handlers/qualify_method_call.rs @@ -67,7 +67,7 @@ pub(crate) fn qualify_method_call(acc: &mut Assists, ctx: &AssistContext<'_, '_> Some(()) } -fn item_for_path_search(db: &dyn HirDatabase, item: ItemInNs) -> Option { +fn item_for_path_search(db: &dyn SourceDatabase, item: ItemInNs) -> Option { Some(match item { ItemInNs::Types(_) | ItemInNs::Values(_) => match item_as_assoc(db, item) { Some(assoc_item) => match assoc_item.container(db) { @@ -83,7 +83,7 @@ fn item_for_path_search(db: &dyn HirDatabase, item: ItemInNs) -> Option Option { +fn item_as_assoc(db: &dyn SourceDatabase, item: ItemInNs) -> Option { item.into_module_def().as_assoc_item(db) } diff --git a/crates/ide-assists/src/utils.rs b/crates/ide-assists/src/utils.rs index 670a030255cf..6fb2f74108c8 100644 --- a/crates/ide-assists/src/utils.rs +++ b/crates/ide-assists/src/utils.rs @@ -756,7 +756,7 @@ enum ReferenceConversionType { } impl<'db> ReferenceConversion<'db> { - fn type_to_string(&self, db: &'db dyn HirDatabase, module: hir::Module) -> String { + fn type_to_string(&self, db: &'db dyn SourceDatabase, module: hir::Module) -> String { match self.conversion { ReferenceConversionType::Copy => self .ty @@ -810,7 +810,11 @@ impl<'db> ReferenceConversion<'db> { } } - pub(crate) fn convert_type(&self, db: &'db dyn HirDatabase, module: hir::Module) -> ast::Type { + pub(crate) fn convert_type( + &self, + db: &'db dyn SourceDatabase, + module: hir::Module, + ) -> ast::Type { let ty = self.type_to_string(db, module); make::ty(&ty) } @@ -818,7 +822,7 @@ impl<'db> ReferenceConversion<'db> { pub(crate) fn convert_type_with_factory( &self, make: &SyntaxFactory, - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, module: hir::Module, ) -> ast::Type { let ty = self.type_to_string(db, module); @@ -863,7 +867,11 @@ pub(crate) fn convert_reference_type<'db>( .map(|(conversion, impls_deref)| ReferenceConversion { ty, conversion, impls_deref }) } -fn could_deref_to_target(ty: &hir::Type<'_>, target: &hir::Type<'_>, db: &dyn HirDatabase) -> bool { +fn could_deref_to_target( + ty: &hir::Type<'_>, + target: &hir::Type<'_>, + db: &dyn SourceDatabase, +) -> bool { let ty_ref = ty.add_reference(db, hir::Mutability::Shared); let target_ref = target.add_reference(db, hir::Mutability::Shared); ty_ref.could_coerce_to(db, &target_ref) @@ -871,14 +879,14 @@ fn could_deref_to_target(ty: &hir::Type<'_>, target: &hir::Type<'_>, db: &dyn Hi fn handle_copy( ty: &hir::Type<'_>, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, ) -> Option<(ReferenceConversionType, bool)> { ty.is_copy(db).then_some((ReferenceConversionType::Copy, true)) } fn handle_as_ref_str( ty: &hir::Type<'_>, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, famous_defs: &FamousDefs<'_, '_>, ) -> Option<(ReferenceConversionType, bool)> { let str_type = hir::BuiltinType::str().ty(db); @@ -889,7 +897,7 @@ fn handle_as_ref_str( fn handle_as_ref_slice( ty: &hir::Type<'_>, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, famous_defs: &FamousDefs<'_, '_>, ) -> Option<(ReferenceConversionType, bool)> { let type_argument = ty.type_arguments().next()?; @@ -903,7 +911,7 @@ fn handle_as_ref_slice( fn handle_dereferenced( ty: &hir::Type<'_>, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, famous_defs: &FamousDefs<'_, '_>, ) -> Option<(ReferenceConversionType, bool)> { let type_argument = ty.type_arguments().next()?; @@ -917,7 +925,7 @@ fn handle_dereferenced( fn handle_option_as_ref( ty: &hir::Type<'_>, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, famous_defs: &FamousDefs<'_, '_>, ) -> Option<(ReferenceConversionType, bool)> { if ty.as_adt() == famous_defs.core_option_Option()?.ty(db).as_adt() { @@ -929,7 +937,7 @@ fn handle_option_as_ref( fn handle_result_as_ref( ty: &hir::Type<'_>, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, famous_defs: &FamousDefs<'_, '_>, ) -> Option<(ReferenceConversionType, bool)> { if ty.as_adt() == famous_defs.core_result_Result()?.ty(db).as_adt() { diff --git a/crates/ide-completion/src/render/function.rs b/crates/ide-completion/src/render/function.rs index 4f70a90affbd..8d60f047ce1b 100644 --- a/crates/ide-completion/src/render/function.rs +++ b/crates/ide-completion/src/render/function.rs @@ -183,7 +183,7 @@ fn render( } fn compute_return_type_match( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, ctx: &RenderContext<'_, '_>, self_type: hir::Type<'_>, ret_type: &hir::Type<'_>, diff --git a/crates/ide-completion/src/render/literal.rs b/crates/ide-completion/src/render/literal.rs index 943ff5821969..05f2648ca575 100644 --- a/crates/ide-completion/src/render/literal.rs +++ b/crates/ide-completion/src/render/literal.rs @@ -166,7 +166,7 @@ impl Variant { if !fields_omitted { Some(visible_fields) } else { None } } - fn kind(self, db: &dyn HirDatabase) -> StructKind { + fn kind(self, db: &dyn SourceDatabase) -> StructKind { match self { Variant::Struct(it) => it.kind(db), Variant::EnumVariant(it) => it.kind(db), @@ -180,7 +180,7 @@ impl Variant { } } - fn docs(self, db: &dyn HirDatabase) -> Option> { + fn docs(self, db: &dyn SourceDatabase) -> Option> { match self { Variant::Struct(it) => it.docs(db), Variant::EnumVariant(it) => it.docs(db), @@ -196,7 +196,7 @@ impl Variant { } } - fn ty(self, db: &dyn HirDatabase) -> hir::Type<'_> { + fn ty(self, db: &dyn SourceDatabase) -> hir::Type<'_> { match self { Variant::Struct(it) => it.ty(db), Variant::EnumVariant(it) => it.parent_enum(db).ty(db), diff --git a/crates/ide-completion/src/render/macro_.rs b/crates/ide-completion/src/render/macro_.rs index 85a0761c17e0..fe51dc5be47d 100644 --- a/crates/ide-completion/src/render/macro_.rs +++ b/crates/ide-completion/src/render/macro_.rs @@ -113,7 +113,7 @@ fn banged_name(name: &str) -> SmolStr { } fn guess_macro_braces( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, macro_: hir::Macro, macro_name: &str, docs: Option<&Documentation<'_>>, diff --git a/crates/ide-completion/src/render/pattern.rs b/crates/ide-completion/src/render/pattern.rs index 13a83eb21632..9382c235d0a6 100644 --- a/crates/ide-completion/src/render/pattern.rs +++ b/crates/ide-completion/src/render/pattern.rs @@ -181,7 +181,7 @@ fn render_pat( } fn render_record_as_pat( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, snippet_cap: Option, fields: &[hir::Field], name: &str, diff --git a/crates/ide-completion/src/tests/flyimport.rs b/crates/ide-completion/src/tests/flyimport.rs index 8a5025caf901..0194e44612b2 100644 --- a/crates/ide-completion/src/tests/flyimport.rs +++ b/crates/ide-completion/src/tests/flyimport.rs @@ -1317,7 +1317,7 @@ mod baz { } mod bar { - fn test(db: &dyn crate::baz::HirDatabase) { + fn test(db: &dyn SourceDatabase) { db.metho$0 } } diff --git a/crates/ide-db/src/defs.rs b/crates/ide-db/src/defs.rs index c1fd002b3467..0e8aea85faff 100644 --- a/crates/ide-db/src/defs.rs +++ b/crates/ide-db/src/defs.rs @@ -926,7 +926,7 @@ impl<'db> From, InlineAsmOperand>> for Definition<'db } impl AsAssocItem for Definition<'_> { - fn as_assoc_item(self, db: &dyn hir::db::HirDatabase) -> Option { + fn as_assoc_item(self, db: &dyn SourceDatabase) -> Option { match self { Definition::Function(it) => it.as_assoc_item(db), Definition::Const(it) => it.as_assoc_item(db), @@ -937,7 +937,7 @@ impl AsAssocItem for Definition<'_> { } impl AsExternAssocItem for Definition<'_> { - fn as_extern_assoc_item(self, db: &dyn hir::db::HirDatabase) -> Option { + fn as_extern_assoc_item(self, db: &dyn SourceDatabase) -> Option { match self { Definition::Function(it) => it.as_extern_assoc_item(db), Definition::Static(it) => it.as_extern_assoc_item(db), diff --git a/crates/ide-db/src/documentation.rs b/crates/ide-db/src/documentation.rs index 407049f4b362..c1d1264222fa 100644 --- a/crates/ide-db/src/documentation.rs +++ b/crates/ide-db/src/documentation.rs @@ -30,19 +30,19 @@ impl<'db> Documentation<'db> { } pub trait HasDocs: HasAttrs + Copy { - fn docs(self, db: &dyn HirDatabase) -> Option> { + fn docs(self, db: &dyn SourceDatabase) -> Option> { let docs = match self.docs_with_rangemap(db)? { Cow::Borrowed(docs) => Documentation::new_borrowed(docs.docs()), Cow::Owned(docs) => Documentation::new_owned(docs.into_docs()), }; Some(docs) } - fn docs_with_rangemap(self, db: &dyn HirDatabase) -> Option> { + fn docs_with_rangemap(self, db: &dyn SourceDatabase) -> Option> { self.hir_docs(db).map(Cow::Borrowed) } fn resolve_doc_path( self, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, link: &str, ns: Option, is_inner_doc: hir::IsInnerDoc, @@ -77,7 +77,7 @@ impl_has_docs![ ]; impl HasDocs for hir::ExternCrateDecl { - fn docs(self, db: &dyn HirDatabase) -> Option> { + fn docs(self, db: &dyn SourceDatabase) -> Option> { let crate_docs = self.resolved_crate(db)?.hir_docs(db); let decl_docs = self.hir_docs(db); match (decl_docs, crate_docs) { @@ -97,7 +97,7 @@ impl HasDocs for hir::ExternCrateDecl { } } - fn docs_with_rangemap(self, db: &dyn HirDatabase) -> Option> { + fn docs_with_rangemap(self, db: &dyn SourceDatabase) -> Option> { let crate_docs = self.resolved_crate(db)?.hir_docs(db); let decl_docs = self.hir_docs(db); match (decl_docs, crate_docs) { diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs index 930cb993e1d3..2c789ca1e957 100644 --- a/crates/ide-db/src/lib.rs +++ b/crates/ide-db/src/lib.rs @@ -315,7 +315,7 @@ impl From for SymbolKind { } impl SymbolKind { - pub fn from_module_def(db: &dyn HirDatabase, it: hir::ModuleDef) -> Self { + pub fn from_module_def(db: &dyn SourceDatabase, it: hir::ModuleDef) -> Self { match it { hir::ModuleDef::Const(..) => SymbolKind::Const, hir::ModuleDef::EnumVariant(..) => SymbolKind::Variant, diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs index edec86285ba6..173a3bb214c3 100644 --- a/crates/ide-db/src/symbol_index.rs +++ b/crates/ide-db/src/symbol_index.rs @@ -188,7 +188,7 @@ impl Query { } /// The symbol indices of modules that make up a given crate. -pub fn crate_symbols(db: &dyn HirDatabase, krate: Crate) -> Box<[&SymbolIndex<'_>]> { +pub fn crate_symbols(db: &dyn SourceDatabase, krate: Crate) -> Box<[&SymbolIndex<'_>]> { let _p = tracing::info_span!("crate_symbols").entered(); krate.modules(db).into_iter().map(|module| SymbolIndex::module_symbols(db, module)).collect() } @@ -288,7 +288,7 @@ pub fn world_symbols(db: &RootDatabase, mut query: Query) -> Vec> /// 1. Finding crates matching the first segment /// 2. Walking down the module tree following subsequent segments fn resolve_path_to_modules( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, path_filter: &[String], anchor_to_crate: bool, case_sensitive: bool, @@ -387,12 +387,12 @@ where impl<'db> SymbolIndex<'db> { /// The symbol index for a given source root within library_roots. pub fn library_symbols( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, source_root_id: SourceRootId, ) -> &'db SymbolIndex<'db> { #[salsa::tracked(returns(ref))] fn library_symbols<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, source_root_id: InternedSourceRootId<'db>, ) -> SymbolIndex<'db> { let _p = tracing::info_span!("library_symbols").entered(); @@ -417,10 +417,10 @@ impl<'db> SymbolIndex<'db> { /// The symbol index for a given module. These modules should only be in source roots that /// are inside local_roots. - pub fn module_symbols(db: &dyn HirDatabase, module: Module) -> &SymbolIndex<'_> { + pub fn module_symbols(db: &dyn SourceDatabase, module: Module) -> &SymbolIndex<'_> { #[salsa::tracked(returns(ref))] fn module_symbols<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, module: hir::ModuleId, ) -> SymbolIndex<'db> { let _p = tracing::info_span!("module_symbols").entered(); @@ -440,9 +440,9 @@ impl<'db> SymbolIndex<'db> { } /// The symbol index for all extern prelude crates. - pub fn extern_prelude_symbols(db: &dyn HirDatabase) -> &SymbolIndex<'_> { + pub fn extern_prelude_symbols(db: &dyn SourceDatabase) -> &SymbolIndex<'_> { #[salsa::tracked(returns(ref))] - fn extern_prelude_symbols<'db>(db: &'db dyn HirDatabase) -> SymbolIndex<'db> { + fn extern_prelude_symbols<'db>(db: &'db dyn SourceDatabase) -> SymbolIndex<'db> { let _p = tracing::info_span!("extern_prelude_symbols").entered(); // We call this without attaching because this runs in parallel, so we need to attach here. diff --git a/crates/ide-db/src/traits.rs b/crates/ide-db/src/traits.rs index 4a560d30ba3c..dd01bd336c86 100644 --- a/crates/ide-db/src/traits.rs +++ b/crates/ide-db/src/traits.rs @@ -87,7 +87,7 @@ pub fn get_missing_assoc_items( /// Converts associated trait impl items to their trait definition counterpart pub(crate) fn convert_to_def_in_trait<'db>( - db: &'db dyn HirDatabase, + db: &'db dyn SourceDatabase, def: Definition<'db>, ) -> Definition<'db> { (|| { @@ -100,7 +100,7 @@ pub(crate) fn convert_to_def_in_trait<'db>( /// If this is an trait (impl) assoc item, returns the assoc item of the corresponding trait definition. pub(crate) fn as_trait_assoc_def<'db>( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: Definition<'db>, ) -> Option> { let assoc = def.as_assoc_item(db)?; @@ -112,7 +112,7 @@ pub(crate) fn as_trait_assoc_def<'db>( } fn assoc_item_of_trait<'db>( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, assoc: hir::AssocItem, trait_: hir::Trait, ) -> Option> { diff --git a/crates/ide-diagnostics/src/handlers/missing_fields.rs b/crates/ide-diagnostics/src/handlers/missing_fields.rs index 639be5e85a59..d2b840f39ad9 100644 --- a/crates/ide-diagnostics/src/handlers/missing_fields.rs +++ b/crates/ide-diagnostics/src/handlers/missing_fields.rs @@ -201,7 +201,7 @@ fn fixes(ctx: &DiagnosticsContext<'_, '_>, d: &hir::MissingFields) -> Option, - db: &dyn HirDatabase, + db: &dyn SourceDatabase, module: hir::Module, edition: Edition, ) -> ast::Type { diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 70d05cd3b5dc..57d146b2a6e2 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -208,7 +208,7 @@ pub(crate) fn extract_definitions_from_docs( } pub(crate) fn resolve_doc_path_for_def<'db>( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: Definition<'db>, link: &str, ns: Option, @@ -633,7 +633,7 @@ fn get_doc_base_urls( /// ^^^^^^^^^^^^^^^^^^^ /// ``` fn filename_and_frag_for_def<'db>( - db: &dyn HirDatabase, + db: &dyn SourceDatabase, def: Definition<'db>, ) -> Option<(Definition<'db>, String, Option)> { if let Some(assoc_item) = def.as_assoc_item(db) { @@ -740,7 +740,7 @@ fn filename_and_frag_for_def<'db>( /// https://doc.rust-lang.org/std/iter/trait.Iterator.html#tymethod.next /// ^^^^^^^^^^^^^^ /// ``` -fn get_assoc_item_fragment(db: &dyn HirDatabase, assoc_item: hir::AssocItem) -> Option { +fn get_assoc_item_fragment(db: &dyn SourceDatabase, assoc_item: hir::AssocItem) -> Option { Some(match assoc_item { AssocItem::Function(function) => { let is_trait_method = diff --git a/crates/ide/src/static_index.rs b/crates/ide/src/static_index.rs index 9e8d772cb3d1..8903c92b24a4 100644 --- a/crates/ide/src/static_index.rs +++ b/crates/ide/src/static_index.rs @@ -116,7 +116,7 @@ pub struct StaticIndexedFile { pub tokens: Vec<(TextRange, TokenId)>, } -fn all_modules(db: &dyn HirDatabase) -> Vec { +fn all_modules(db: &dyn SourceDatabase) -> Vec { let mut worklist: Vec<_> = Crate::all(db).into_iter().map(|krate| krate.root_module(db)).collect(); let mut modules = Vec::new(); diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index 56020b401780..92902938235e 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs @@ -211,7 +211,7 @@ pub(super) fn doc_comment( } } -fn module_def_to_hl_tag(db: &dyn HirDatabase, def: Definition<'_>) -> HlTag { +fn module_def_to_hl_tag(db: &dyn SourceDatabase, def: Definition<'_>) -> HlTag { let symbol = match def { Definition::Crate(_) | Definition::ExternCrateDecl(_) => SymbolKind::CrateRoot, Definition::Module(m) if m.is_crate_root(db) => SymbolKind::CrateRoot, diff --git a/crates/rust-analyzer/src/cli.rs b/crates/rust-analyzer/src/cli.rs index cc0efe9ee938..3910f321dd5a 100644 --- a/crates/rust-analyzer/src/cli.rs +++ b/crates/rust-analyzer/src/cli.rs @@ -80,7 +80,7 @@ fn print_memory_usage(mut host: AnalysisHost, vfs: Vfs) { eprintln!("{remaining:>8} Remaining"); } -fn full_name_of_item(db: &dyn HirDatabase, module: Module, name: Name) -> String { +fn full_name_of_item(db: &dyn SourceDatabase, module: Module, name: Name) -> String { module .path_segments(db) .chain(Some(name)) diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs index e50e1c26bb97..0269de97936c 100644 --- a/crates/rust-analyzer/src/cli/diagnostics.rs +++ b/crates/rust-analyzer/src/cli/diagnostics.rs @@ -126,7 +126,7 @@ impl flags::Diagnostics { } } -fn all_modules(db: &dyn HirDatabase) -> Vec { +fn all_modules(db: &dyn SourceDatabase) -> Vec { let mut worklist: Vec<_> = Crate::all(db).into_iter().map(|krate| krate.root_module(db)).collect(); let mut modules = Vec::new(); diff --git a/crates/rust-analyzer/src/cli/run_tests.rs b/crates/rust-analyzer/src/cli/run_tests.rs index 0f7ef84a0eb8..62e19c813cb0 100644 --- a/crates/rust-analyzer/src/cli/run_tests.rs +++ b/crates/rust-analyzer/src/cli/run_tests.rs @@ -76,7 +76,7 @@ impl flags::RunTests { } } -fn all_modules(db: &dyn HirDatabase) -> Vec { +fn all_modules(db: &dyn SourceDatabase) -> Vec { let mut worklist: Vec<_> = Crate::all(db) .into_iter() .filter(|x| x.origin(db).is_local()) diff --git a/crates/rust-analyzer/src/cli/unresolved_references.rs b/crates/rust-analyzer/src/cli/unresolved_references.rs index f8eacbb67058..e4695cb49944 100644 --- a/crates/rust-analyzer/src/cli/unresolved_references.rs +++ b/crates/rust-analyzer/src/cli/unresolved_references.rs @@ -97,7 +97,7 @@ impl flags::UnresolvedReferences { } } -fn all_modules(db: &dyn HirDatabase) -> Vec { +fn all_modules(db: &dyn SourceDatabase) -> Vec { let mut worklist: Vec<_> = Crate::all(db).into_iter().map(|krate| krate.root_module(db)).collect(); let mut modules = Vec::new(); From ea3a6d78d70dfba9ad00b6cc76435c587e428534 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Fri, 31 Jul 2026 04:06:25 +0300 Subject: [PATCH 3/7] Import `SourceDatabase` where it's missing I authored a script to use rust-analyzer's own autoimport assist to do that automatically on all files. Then added manually two more imports in interner.rs because the script didn't handle multiple modules in one file correctly. --- crates/hir-ty/src/autoderef.rs | 1 + crates/hir-ty/src/builtin_derive.rs | 1 + crates/hir-ty/src/consteval.rs | 2 +- crates/hir-ty/src/diagnostics/decl_check.rs | 1 + crates/hir-ty/src/diagnostics/expr.rs | 2 +- crates/hir-ty/src/diagnostics/match_check.rs | 1 + crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs | 1 + crates/hir-ty/src/diagnostics/unsafe_check.rs | 1 + crates/hir-ty/src/display.rs | 2 +- crates/hir-ty/src/drop.rs | 1 + crates/hir-ty/src/dyn_compatibility.rs | 1 + crates/hir-ty/src/infer.rs | 2 +- crates/hir-ty/src/infer/cast.rs | 1 + crates/hir-ty/src/infer/coerce.rs | 1 + crates/hir-ty/src/infer/diagnostics.rs | 1 + crates/hir-ty/src/infer/unify.rs | 2 +- crates/hir-ty/src/inhabitedness.rs | 1 + crates/hir-ty/src/layout.rs | 1 + crates/hir-ty/src/layout/adt.rs | 1 + crates/hir-ty/src/layout/target.rs | 2 +- crates/hir-ty/src/lower.rs | 2 +- crates/hir-ty/src/lower/path.rs | 1 + crates/hir-ty/src/method_resolution.rs | 2 +- crates/hir-ty/src/method_resolution/confirm.rs | 1 + crates/hir-ty/src/method_resolution/probe.rs | 2 +- crates/hir-ty/src/mir.rs | 1 + crates/hir-ty/src/mir/borrowck.rs | 1 + crates/hir-ty/src/mir/eval.rs | 2 +- crates/hir-ty/src/mir/lower.rs | 2 +- crates/hir-ty/src/mir/monomorphization.rs | 1 + crates/hir-ty/src/mir/pretty.rs | 1 + crates/hir-ty/src/next_solver.rs | 1 + crates/hir-ty/src/next_solver/consts/valtree.rs | 1 + crates/hir-ty/src/next_solver/generics.rs | 1 + crates/hir-ty/src/next_solver/interner.rs | 6 ++++-- crates/hir-ty/src/next_solver/ty.rs | 1 + crates/hir-ty/src/opaques.rs | 1 + crates/hir-ty/src/representability.rs | 1 + crates/hir-ty/src/specialization.rs | 1 + crates/hir-ty/src/target_feature.rs | 1 + crates/hir-ty/src/traits.rs | 2 +- crates/hir-ty/src/upvars.rs | 1 + crates/hir-ty/src/utils.rs | 5 ++++- crates/hir-ty/src/variance.rs | 1 + crates/hir/src/attrs.rs | 1 + crates/hir/src/diagnostics.rs | 1 + crates/hir/src/display.rs | 1 + crates/hir/src/has_source.rs | 1 + crates/hir/src/semantics.rs | 2 +- crates/hir/src/semantics/source_to_def.rs | 2 +- crates/hir/src/source_analyzer.rs | 1 + crates/hir/src/symbols.rs | 2 +- crates/hir/src/term_search.rs | 1 + crates/hir/src/term_search/expr.rs | 1 + crates/ide-assists/src/handlers/auto_import.rs | 1 + crates/ide-assists/src/handlers/fix_visibility.rs | 2 +- crates/ide-assists/src/handlers/generate_delegate_trait.rs | 1 + crates/ide-assists/src/handlers/generate_function.rs | 1 + crates/ide-assists/src/handlers/inline_call.rs | 2 +- crates/ide-assists/src/handlers/qualify_method_call.rs | 2 +- crates/ide-assists/src/utils.rs | 1 + crates/ide-completion/src/render/function.rs | 1 + crates/ide-completion/src/render/literal.rs | 1 + crates/ide-completion/src/render/macro_.rs | 1 + crates/ide-completion/src/render/pattern.rs | 1 + crates/ide-db/src/defs.rs | 1 + crates/ide-db/src/documentation.rs | 1 + crates/ide-db/src/symbol_index.rs | 4 ++-- crates/ide-db/src/traits.rs | 1 + crates/ide-diagnostics/src/handlers/missing_fields.rs | 1 + crates/ide/src/doc_links.rs | 2 +- crates/ide/src/syntax_highlighting/inject.rs | 4 ++-- crates/rust-analyzer/src/cli.rs | 1 + 73 files changed, 81 insertions(+), 26 deletions(-) diff --git a/crates/hir-ty/src/autoderef.rs b/crates/hir-ty/src/autoderef.rs index cf4a3ff79f5a..87304501e334 100644 --- a/crates/hir-ty/src/autoderef.rs +++ b/crates/hir-ty/src/autoderef.rs @@ -7,6 +7,7 @@ use std::fmt; +use base_db::SourceDatabase; use hir_def::{TraitId, TypeAliasId}; use rustc_type_ir::inherent::{IntoKind, Ty as _}; use tracing::debug; diff --git a/crates/hir-ty/src/builtin_derive.rs b/crates/hir-ty/src/builtin_derive.rs index 6f2b6bcbf703..56fd19325fdc 100644 --- a/crates/hir-ty/src/builtin_derive.rs +++ b/crates/hir-ty/src/builtin_derive.rs @@ -2,6 +2,7 @@ use std::ops::ControlFlow; +use base_db::SourceDatabase; use hir_def::{ AdtId, BuiltinDeriveImplId, BuiltinDeriveImplLoc, HasModule, LocalFieldId, TraitId, TypeOrConstParamId, TypeParamId, diff --git a/crates/hir-ty/src/consteval.rs b/crates/hir-ty/src/consteval.rs index 1629f35a226c..b20e3b66e1c2 100644 --- a/crates/hir-ty/src/consteval.rs +++ b/crates/hir-ty/src/consteval.rs @@ -3,7 +3,7 @@ #[cfg(test)] mod tests; -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use hir_def::{ ConstId, EnumVariantId, ExpressionStoreOwnerId, HasModule, StaticId, attrs::AttrFlags, diff --git a/crates/hir-ty/src/diagnostics/decl_check.rs b/crates/hir-ty/src/diagnostics/decl_check.rs index 7cc5107d65a9..7977c0da6b05 100644 --- a/crates/hir-ty/src/diagnostics/decl_check.rs +++ b/crates/hir-ty/src/diagnostics/decl_check.rs @@ -15,6 +15,7 @@ mod case_conv; use std::fmt; +use base_db::SourceDatabase; use hir_def::{ AdtId, ConstId, EnumId, EnumVariantId, FunctionId, HasModule, ItemContainerId, Lookup, ModuleDefId, ModuleId, StaticId, StructId, TraitId, TypeAliasId, UnionId, diff --git a/crates/hir-ty/src/diagnostics/expr.rs b/crates/hir-ty/src/diagnostics/expr.rs index 997dd459e4b4..5332a1084662 100644 --- a/crates/hir-ty/src/diagnostics/expr.rs +++ b/crates/hir-ty/src/diagnostics/expr.rs @@ -4,7 +4,7 @@ use std::fmt; -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use either::Either; use hir_def::{ AdtId, AssocItemId, CallableDefId, DefWithBodyId, HasModule, ItemContainerId, Lookup, diff --git a/crates/hir-ty/src/diagnostics/match_check.rs b/crates/hir-ty/src/diagnostics/match_check.rs index 1daad1ca745b..df18946170ef 100644 --- a/crates/hir-ty/src/diagnostics/match_check.rs +++ b/crates/hir-ty/src/diagnostics/match_check.rs @@ -9,6 +9,7 @@ mod pat_util; pub(crate) mod pat_analysis; +use base_db::SourceDatabase; use hir_def::{ AdtId, EnumVariantId, LocalFieldId, Lookup, VariantId, expr_store::{Body, path::Path}, diff --git a/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs b/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs index c79de2703140..bcdb244af3a3 100644 --- a/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs +++ b/crates/hir-ty/src/diagnostics/match_check/pat_analysis.rs @@ -2,6 +2,7 @@ use std::{cell::LazyCell, fmt}; +use base_db::SourceDatabase; use hir_def::{ EnumId, EnumVariantId, HasModule, LocalFieldId, ModuleId, VariantId, attrs::AttrFlags, signatures::VariantFields, unstable_features::UnstableFeatures, diff --git a/crates/hir-ty/src/diagnostics/unsafe_check.rs b/crates/hir-ty/src/diagnostics/unsafe_check.rs index 7254ac2a6532..571e6ecb7a58 100644 --- a/crates/hir-ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir-ty/src/diagnostics/unsafe_check.rs @@ -3,6 +3,7 @@ use std::mem; +use base_db::SourceDatabase; use either::Either; use hir_def::{ AdtId, CallableDefId, DefWithBodyId, ExpressionStoreOwnerId, FieldId, FunctionId, GenericDefId, diff --git a/crates/hir-ty/src/display.rs b/crates/hir-ty/src/display.rs index c92e045fc512..4f33870def06 100644 --- a/crates/hir-ty/src/display.rs +++ b/crates/hir-ty/src/display.rs @@ -7,7 +7,7 @@ use std::{ mem, }; -use base_db::{Crate, FxIndexMap}; +use base_db::{Crate, FxIndexMap, SourceDatabase}; use either::Either; use hir_def::{ ExpressionStoreOwnerId, FindPathConfig, GenericDefId, GenericParamId, HasModule, diff --git a/crates/hir-ty/src/drop.rs b/crates/hir-ty/src/drop.rs index c09d923d6fdd..e8f237354781 100644 --- a/crates/hir-ty/src/drop.rs +++ b/crates/hir-ty/src/drop.rs @@ -1,5 +1,6 @@ //! Utilities for computing drop info about types. +use base_db::SourceDatabase; use hir_def::{ AdtId, ImplId, signatures::{StructFlags, StructSignature}, diff --git a/crates/hir-ty/src/dyn_compatibility.rs b/crates/hir-ty/src/dyn_compatibility.rs index 3eca5a66ba59..a296f1209127 100644 --- a/crates/hir-ty/src/dyn_compatibility.rs +++ b/crates/hir-ty/src/dyn_compatibility.rs @@ -2,6 +2,7 @@ use std::ops::ControlFlow; +use base_db::SourceDatabase; use hir_def::{ AssocItemId, ConstId, FunctionId, GenericDefId, HasModule, TraitId, TypeAliasId, TypeOrConstParamId, TypeParamId, diff --git a/crates/hir-ty/src/infer.rs b/crates/hir-ty/src/infer.rs index cf6d291a02bf..4cd45320ab1a 100644 --- a/crates/hir-ty/src/infer.rs +++ b/crates/hir-ty/src/infer.rs @@ -39,7 +39,7 @@ use std::{ ops::Deref, }; -use base_db::{Crate, FxIndexMap}; +use base_db::{Crate, FxIndexMap, SourceDatabase}; use either::Either; use hir_def::{ AdtId, AssocItemId, AttrDefId, ConstId, DefWithBodyId, ExpressionStoreOwnerId, FieldId, diff --git a/crates/hir-ty/src/infer/cast.rs b/crates/hir-ty/src/infer/cast.rs index cac61b2ca81a..2a93ddd7e5f8 100644 --- a/crates/hir-ty/src/infer/cast.rs +++ b/crates/hir-ty/src/infer/cast.rs @@ -1,5 +1,6 @@ //! Type cast logic. Basically coercion + additional casts. +use base_db::SourceDatabase; use hir_def::{ AdtId, hir::ExprId, diff --git a/crates/hir-ty/src/infer/coerce.rs b/crates/hir-ty/src/infer/coerce.rs index a111c9d54da1..d9ae214a43b3 100644 --- a/crates/hir-ty/src/infer/coerce.rs +++ b/crates/hir-ty/src/infer/coerce.rs @@ -37,6 +37,7 @@ use std::ops::ControlFlow; +use base_db::SourceDatabase; use hir_def::{ CallableDefId, TraitId, attrs::AttrFlags, hir::ExprId, signatures::FunctionSignature, }; diff --git a/crates/hir-ty/src/infer/diagnostics.rs b/crates/hir-ty/src/infer/diagnostics.rs index 87311b6ab8b0..bf3abd3f98fa 100644 --- a/crates/hir-ty/src/infer/diagnostics.rs +++ b/crates/hir-ty/src/infer/diagnostics.rs @@ -5,6 +5,7 @@ use std::cell::{OnceCell, RefCell}; use std::ops::{Deref, DerefMut}; +use base_db::SourceDatabase; use either::Either; use hir_def::expr_store::path::Path; use hir_def::{ExpressionStoreOwnerId, GenericDefId}; diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs index 8c56fd9ee619..6a847447a3a0 100644 --- a/crates/hir-ty/src/infer/unify.rs +++ b/crates/hir-ty/src/infer/unify.rs @@ -2,7 +2,7 @@ use std::fmt; -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use hir_def::{ExpressionStoreOwnerId, GenericParamId, TraitId}; use rustc_hash::FxHashSet; use rustc_type_ir::{ diff --git a/crates/hir-ty/src/inhabitedness.rs b/crates/hir-ty/src/inhabitedness.rs index 9e09296cb6a4..10fe25e37d5a 100644 --- a/crates/hir-ty/src/inhabitedness.rs +++ b/crates/hir-ty/src/inhabitedness.rs @@ -1,6 +1,7 @@ //! Type inhabitedness logic. use std::ops::ControlFlow::{self, Break, Continue}; +use base_db::SourceDatabase; use hir_def::{ AdtId, EnumVariantId, ModuleId, VariantId, signatures::VariantFields, visibility::Visibility, }; diff --git a/crates/hir-ty/src/layout.rs b/crates/hir-ty/src/layout.rs index 23f21607f69a..a9321bd22b29 100644 --- a/crates/hir-ty/src/layout.rs +++ b/crates/hir-ty/src/layout.rs @@ -2,6 +2,7 @@ use std::fmt; +use base_db::SourceDatabase; use hir_def::{ AdtId, LocalFieldId, StructId, attrs::AttrFlags, diff --git a/crates/hir-ty/src/layout/adt.rs b/crates/hir-ty/src/layout/adt.rs index a01f78082adf..24f480b20a34 100644 --- a/crates/hir-ty/src/layout/adt.rs +++ b/crates/hir-ty/src/layout/adt.rs @@ -2,6 +2,7 @@ use std::cmp; +use base_db::SourceDatabase; use hir_def::{ AdtId, VariantId, attrs::AttrFlags, diff --git a/crates/hir-ty/src/layout/target.rs b/crates/hir-ty/src/layout/target.rs index 414a209f9a92..e381e0eec13c 100644 --- a/crates/hir-ty/src/layout/target.rs +++ b/crates/hir-ty/src/layout/target.rs @@ -1,6 +1,6 @@ //! Target dependent parameters needed for layouts -use base_db::{Crate, target::TargetLoadError}; +use base_db::{Crate, SourceDatabase, target::TargetLoadError}; use hir_def::layout::TargetDataLayout; use rustc_abi::{AddressSpace, AlignFromBytesError, TargetDataLayoutError}; diff --git a/crates/hir-ty/src/lower.rs b/crates/hir-ty/src/lower.rs index 577b392dcb88..73d1c46691f8 100644 --- a/crates/hir-ty/src/lower.rs +++ b/crates/hir-ty/src/lower.rs @@ -10,7 +10,7 @@ pub(crate) mod path; use std::{cell::OnceCell, iter, mem, sync::OnceLock}; -use base_db::salsa::update_fallback_db; +use base_db::{SourceDatabase, salsa::update_fallback_db}; use either::Either; use hir_def::{ AdtId, AssocItemId, CallableDefId, ConstId, ConstParamId, EnumId, EnumVariantId, diff --git a/crates/hir-ty/src/lower/path.rs b/crates/hir-ty/src/lower/path.rs index 885f5dfd2b6a..d53c4fc84a79 100644 --- a/crates/hir-ty/src/lower/path.rs +++ b/crates/hir-ty/src/lower/path.rs @@ -1,5 +1,6 @@ //! A wrapper around [`TyLoweringContext`] specifically for lowering paths. +use base_db::SourceDatabase; use either::Either; use hir_def::{ GenericDefId, GenericParamId, Lookup, TraitId, TypeParamId, diff --git a/crates/hir-ty/src/method_resolution.rs b/crates/hir-ty/src/method_resolution.rs index aa01524222bd..38d518bb3676 100644 --- a/crates/hir-ty/src/method_resolution.rs +++ b/crates/hir-ty/src/method_resolution.rs @@ -15,7 +15,7 @@ use salsa::Update; use span::Edition; use tracing::{debug, instrument}; -use base_db::{Crate, salsa::update_fallback_db}; +use base_db::{Crate, SourceDatabase, salsa::update_fallback_db}; use hir_def::{ AssocItemId, BlockIdLt, BuiltinDeriveImplId, ConstId, FunctionId, GenericParamId, HasModule, ImplId, ItemContainerId, ModuleId, TraitId, diff --git a/crates/hir-ty/src/method_resolution/confirm.rs b/crates/hir-ty/src/method_resolution/confirm.rs index c316365bd1c0..fce953831086 100644 --- a/crates/hir-ty/src/method_resolution/confirm.rs +++ b/crates/hir-ty/src/method_resolution/confirm.rs @@ -1,6 +1,7 @@ //! Confirmation step of method selection, meaning ensuring the selected candidate //! is valid and registering all obligations. +use base_db::SourceDatabase; use hir_def::{ FunctionId, GenericDefId, GenericParamId, TraitId, expr_store::path::{GenericArg as HirGenericArg, GenericArgs as HirGenericArgs}, diff --git a/crates/hir-ty/src/method_resolution/probe.rs b/crates/hir-ty/src/method_resolution/probe.rs index bb31737a0835..507f9d597cff 100644 --- a/crates/hir-ty/src/method_resolution/probe.rs +++ b/crates/hir-ty/src/method_resolution/probe.rs @@ -3,7 +3,7 @@ use std::{cell::RefCell, convert::Infallible, ops::ControlFlow}; -use base_db::FxIndexMap; +use base_db::{FxIndexMap, SourceDatabase}; use hir_def::{ AssocItemId, FunctionId, GenericParamId, ImplId, ItemContainerId, TraitId, hir::generics::GenericParams, diff --git a/crates/hir-ty/src/mir.rs b/crates/hir-ty/src/mir.rs index bac827d305d7..9b57a7df6993 100644 --- a/crates/hir-ty/src/mir.rs +++ b/crates/hir-ty/src/mir.rs @@ -2,6 +2,7 @@ use std::{fmt::Display, iter}; +use base_db::SourceDatabase; use hir_def::{ FieldId, LocalFieldId, StaticId, UnionId, VariantId, hir::{BindingId, Expr, ExprId, Ordering, PatId}, diff --git a/crates/hir-ty/src/mir/borrowck.rs b/crates/hir-ty/src/mir/borrowck.rs index 31b8cf2c8068..6d886b40ca9b 100644 --- a/crates/hir-ty/src/mir/borrowck.rs +++ b/crates/hir-ty/src/mir/borrowck.rs @@ -5,6 +5,7 @@ use std::iter; +use base_db::SourceDatabase; use either::Either; use hir_def::HasModule; use la_arena::ArenaMap; diff --git a/crates/hir-ty/src/mir/eval.rs b/crates/hir-ty/src/mir/eval.rs index 4df5ee664375..4ab6fb764cc6 100644 --- a/crates/hir-ty/src/mir/eval.rs +++ b/crates/hir-ty/src/mir/eval.rs @@ -2,7 +2,7 @@ use std::{borrow::Cow, cell::RefCell, fmt::Write, iter, mem, ops::Range}; -use base_db::{Crate, salsa::update_fallback_db, target::TargetLoadError}; +use base_db::{Crate, SourceDatabase, salsa::update_fallback_db, target::TargetLoadError}; use either::Either; use hir_def::{ AdtId, DefWithBodyId, EnumVariantId, FunctionId, HasModule, ItemContainerId, Lookup, StaticId, diff --git a/crates/hir-ty/src/mir/lower.rs b/crates/hir-ty/src/mir/lower.rs index e0f89b49ebb7..cbfbd2fdc1d3 100644 --- a/crates/hir-ty/src/mir/lower.rs +++ b/crates/hir-ty/src/mir/lower.rs @@ -2,7 +2,7 @@ use std::{fmt::Write, iter, mem}; -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use hir_def::{ AdtId, DefWithBodyId, EnumVariantId, ExpressionStoreOwnerId, GenericParamId, HasModule, ItemContainerId, LocalFieldId, Lookup, TraitId, diff --git a/crates/hir-ty/src/mir/monomorphization.rs b/crates/hir-ty/src/mir/monomorphization.rs index e6143e65327a..80a602c528cf 100644 --- a/crates/hir-ty/src/mir/monomorphization.rs +++ b/crates/hir-ty/src/mir/monomorphization.rs @@ -7,6 +7,7 @@ //! //! So the monomorphization should be called even if the substitution is empty. +use base_db::SourceDatabase; use rustc_type_ir::inherent::IntoKind; use rustc_type_ir::{ FallibleTypeFolder, TypeFlags, TypeFoldable, TypeSuperFoldable, TypeVisitableExt, diff --git a/crates/hir-ty/src/mir/pretty.rs b/crates/hir-ty/src/mir/pretty.rs index af73a833b906..171a966d7907 100644 --- a/crates/hir-ty/src/mir/pretty.rs +++ b/crates/hir-ty/src/mir/pretty.rs @@ -5,6 +5,7 @@ use std::{ mem, }; +use base_db::SourceDatabase; use hir_def::{ HasModule, VariantId, expr_store::ExpressionStore, diff --git a/crates/hir-ty/src/next_solver.rs b/crates/hir-ty/src/next_solver.rs index 443e3a76ad36..87f2efb152c7 100644 --- a/crates/hir-ty/src/next_solver.rs +++ b/crates/hir-ty/src/next_solver.rs @@ -31,6 +31,7 @@ pub mod util; use std::{mem::ManuallyDrop, sync::OnceLock}; pub use allocation::*; +use base_db::SourceDatabase; pub use binder::*; pub use consts::*; pub use def_id::*; diff --git a/crates/hir-ty/src/next_solver/consts/valtree.rs b/crates/hir-ty/src/next_solver/consts/valtree.rs index 597a5552cb73..a84bfee80cb4 100644 --- a/crates/hir-ty/src/next_solver/consts/valtree.rs +++ b/crates/hir-ty/src/next_solver/consts/valtree.rs @@ -1,5 +1,6 @@ use std::{fmt, hash::Hash, num::NonZero}; +use base_db::SourceDatabase; use intern::{Interned, InternedRef, impl_internable}; use macros::{GenericTypeVisitable, TypeFoldable, TypeVisitable}; use rustc_abi::{Size, TargetDataLayout}; diff --git a/crates/hir-ty/src/next_solver/generics.rs b/crates/hir-ty/src/next_solver/generics.rs index aa39a04dc8bf..16c2a82a9f94 100644 --- a/crates/hir-ty/src/next_solver/generics.rs +++ b/crates/hir-ty/src/next_solver/generics.rs @@ -1,5 +1,6 @@ //! Things related to generics in the next-trait-solver. +use base_db::SourceDatabase; use hir_def::{ GenericDefId, GenericParamId, TypeParamId, hir::generics::{GenericParamDataRef, LifetimeParamData}, diff --git a/crates/hir-ty/src/next_solver/interner.rs b/crates/hir-ty/src/next_solver/interner.rs index dcc084564506..9a87c3c35e37 100644 --- a/crates/hir-ty/src/next_solver/interner.rs +++ b/crates/hir-ty/src/next_solver/interner.rs @@ -10,7 +10,7 @@ use rustc_ast_ir::{FloatTy, IntTy, UintTy}; pub use tls_cache::clear_tls_solver_cache; pub use tls_db::{attach_db, attach_db_allow_change, with_attached_db}; -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use hir_def::{ AdtId, CallableDefId, EnumId, HasModule, ItemContainerId, StructId, TraitId, TypeAliasId, UnionId, VariantId, @@ -2398,6 +2398,8 @@ TrivialTypeTraversalImpls! { mod tls_db { use std::{cell::Cell, ptr::NonNull}; + use base_db::SourceDatabase; + use crate::db::HirDatabase; struct Attached { @@ -2515,7 +2517,7 @@ mod tls_cache { use crate::db::HirDatabase; use super::DbInterner; - use base_db::Nonce; + use base_db::{Nonce, SourceDatabase}; use rustc_type_ir::search_graph::GlobalCache; use salsa::Revision; use std::cell::RefCell; diff --git a/crates/hir-ty/src/next_solver/ty.rs b/crates/hir-ty/src/next_solver/ty.rs index a1311dff5b8f..b8f6a40cf674 100644 --- a/crates/hir-ty/src/next_solver/ty.rs +++ b/crates/hir-ty/src/next_solver/ty.rs @@ -2,6 +2,7 @@ use std::ops::ControlFlow; +use base_db::SourceDatabase; use hir_def::{ AdtId, HasModule, TypeParamId, hir::generics::{GenericParams, TypeOrConstParamData, TypeParamProvenance}, diff --git a/crates/hir-ty/src/opaques.rs b/crates/hir-ty/src/opaques.rs index d87031417d2d..14d904e2678e 100644 --- a/crates/hir-ty/src/opaques.rs +++ b/crates/hir-ty/src/opaques.rs @@ -1,5 +1,6 @@ //! Handling of opaque types, detection of defining scope and hidden type. +use base_db::SourceDatabase; use hir_def::{ AssocItemId, AssocItemLoc, DefWithBodyId, FunctionId, HasModule, ItemContainerId, TypeAliasId, signatures::ImplSignature, diff --git a/crates/hir-ty/src/representability.rs b/crates/hir-ty/src/representability.rs index f5c544e6b2bd..8e8e405f4544 100644 --- a/crates/hir-ty/src/representability.rs +++ b/crates/hir-ty/src/representability.rs @@ -1,5 +1,6 @@ //! Detecting whether a type is infinitely-sized. +use base_db::SourceDatabase; use hir_def::{AdtId, VariantId, hir::generics::GenericParams}; use rustc_type_ir::inherent::IntoKind; diff --git a/crates/hir-ty/src/specialization.rs b/crates/hir-ty/src/specialization.rs index 788cc708aafd..32e6a90a8e45 100644 --- a/crates/hir-ty/src/specialization.rs +++ b/crates/hir-ty/src/specialization.rs @@ -1,5 +1,6 @@ //! Impl specialization related things +use base_db::SourceDatabase; use hir_def::{HasModule, ImplId, signatures::ImplSignature, unstable_features::UnstableFeatures}; use tracing::debug; diff --git a/crates/hir-ty/src/target_feature.rs b/crates/hir-ty/src/target_feature.rs index 670d996285c2..7477e7e168a0 100644 --- a/crates/hir-ty/src/target_feature.rs +++ b/crates/hir-ty/src/target_feature.rs @@ -3,6 +3,7 @@ use std::borrow::Cow; use std::sync::LazyLock; +use base_db::SourceDatabase; use hir_def::FunctionId; use hir_def::attrs::AttrFlags; use intern::Symbol; diff --git a/crates/hir-ty/src/traits.rs b/crates/hir-ty/src/traits.rs index ec1e102e4f57..940d79d730e6 100644 --- a/crates/hir-ty/src/traits.rs +++ b/crates/hir-ty/src/traits.rs @@ -2,7 +2,7 @@ use std::{cell::OnceCell, hash::Hash}; -use base_db::Crate; +use base_db::{Crate, SourceDatabase}; use hir_def::{ AdtId, AssocItemId, ExpressionStoreOwnerId, GenericDefId, HasModule, ImplId, Lookup, TraitId, expr_store::ExpressionStore, diff --git a/crates/hir-ty/src/upvars.rs b/crates/hir-ty/src/upvars.rs index 9d8678ad53b0..e55e20e3b158 100644 --- a/crates/hir-ty/src/upvars.rs +++ b/crates/hir-ty/src/upvars.rs @@ -1,5 +1,6 @@ //! A simple query to collect tall locals (upvars) a closure use. +use base_db::SourceDatabase; use hir_def::{ DefWithBodyId, ExpressionStoreOwnerId, GenericDefId, VariantId, expr_store::{ExpressionStore, path::Path}, diff --git a/crates/hir-ty/src/utils.rs b/crates/hir-ty/src/utils.rs index d8559ddcc9f6..4191040cf38e 100644 --- a/crates/hir-ty/src/utils.rs +++ b/crates/hir-ty/src/utils.rs @@ -3,7 +3,10 @@ use std::iter::Enumerate; -use base_db::target::{self, TargetData}; +use base_db::{ + SourceDatabase, + target::{self, TargetData}, +}; use hir_def::{ EnumId, EnumVariantId, FunctionId, Lookup, TraitId, lang_item::LangItems, signatures::FunctionSignature, diff --git a/crates/hir-ty/src/variance.rs b/crates/hir-ty/src/variance.rs index 938bd9776b69..8d3dbbfc3c56 100644 --- a/crates/hir-ty/src/variance.rs +++ b/crates/hir-ty/src/variance.rs @@ -13,6 +13,7 @@ //! by the next salsa version. If not, we will likely have to adapt and go with the rustc approach //! while installing firewall per item queries to prevent invalidation issues. +use base_db::SourceDatabase; use hir_def::{ AdtId, GenericDefId, GenericParamId, VariantId, signatures::{StructFlags, StructSignature}, diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index e7675f5113b2..234a0510a339 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs @@ -1,5 +1,6 @@ //! Attributes & documentation for hir types. +use base_db::SourceDatabase; use cfg::CfgExpr; use either::Either; use hir_def::{ diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index be661f9cf705..c32efca80015 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -3,6 +3,7 @@ //! //! This probably isn't the best way to do this -- ideally, diagnostics should //! be expressed in terms of hir types themselves. +use base_db::SourceDatabase; use cfg::{CfgExpr, CfgOptions}; use either::Either; use hir_def::{ diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 81dc80510ddc..8de01d44b43f 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -1,5 +1,6 @@ //! HirDisplay implementations for various hir types. +use base_db::SourceDatabase; use either::Either; use hir_def::{ AdtId, BuiltinDeriveImplId, DefWithBodyId, ExpressionStoreOwnerId, FunctionId, GenericDefId, diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index 5aca9c2fb844..10e14ead5745 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs @@ -1,5 +1,6 @@ //! Provides set of implementation for hir's objects that allows get back location in file. +use base_db::SourceDatabase; use either::Either; use hir_def::{ CallableDefId, Lookup, MacroId, VariantId, diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 64e14884a466..e2269ee55e88 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -10,7 +10,7 @@ use std::{ ops::{self, ControlFlow, Not}, }; -use base_db::{FxIndexSet, all_crates, toolchain_channel}; +use base_db::{FxIndexSet, SourceDatabase, all_crates, toolchain_channel}; use either::Either; use hir_def::{ BuiltinDeriveImplId, DefWithBodyId, ExpressionStoreOwnerId, GenericDefId, HasModule, MacroId, diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index c46c7683f353..55f4196abd40 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -85,7 +85,7 @@ //! active crate for a given position, and then provide an API to resolve all //! syntax nodes against this specific crate. -use base_db::relevant_crates; +use base_db::{SourceDatabase, relevant_crates}; use either::Either; use hir_def::{ AdtId, BlockId, BuiltinDeriveImplId, ConstId, ConstParamId, DefWithBodyId, EnumId, diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index bf9634d96c79..7c1315923983 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -10,6 +10,7 @@ use std::{ iter::{self, once}, }; +use base_db::SourceDatabase; use either::Either; use hir_def::{ AdtId, AssocItemId, CallableDefId, ConstId, DefWithBodyId, ExpressionStoreOwnerId, FieldId, diff --git a/crates/hir/src/symbols.rs b/crates/hir/src/symbols.rs index f3af5de1b007..c32c8564c253 100644 --- a/crates/hir/src/symbols.rs +++ b/crates/hir/src/symbols.rs @@ -2,7 +2,7 @@ use std::marker::PhantomData; -use base_db::{FxIndexSet, salsa::Update}; +use base_db::{FxIndexSet, SourceDatabase, salsa::Update}; use either::Either; use hir_def::{ AdtId, AssocItemId, AstIdLoc, Complete, DefWithBodyId, ExternCrateId, HasModule, ImplId, diff --git a/crates/hir/src/term_search.rs b/crates/hir/src/term_search.rs index b9726ffdbb37..0e233b03d664 100644 --- a/crates/hir/src/term_search.rs +++ b/crates/hir/src/term_search.rs @@ -1,5 +1,6 @@ //! Term search +use base_db::SourceDatabase; use hir_def::type_ref::Mutability; use hir_ty::db::HirDatabase; use itertools::Itertools; diff --git a/crates/hir/src/term_search/expr.rs b/crates/hir/src/term_search/expr.rs index b4e4843153f2..3def15f943a5 100644 --- a/crates/hir/src/term_search/expr.rs +++ b/crates/hir/src/term_search/expr.rs @@ -1,5 +1,6 @@ //! Type tree for term search +use base_db::SourceDatabase; use hir_def::FindPathConfig; use hir_expand::mod_path::ModPath; use hir_ty::{ diff --git a/crates/ide-assists/src/handlers/auto_import.rs b/crates/ide-assists/src/handlers/auto_import.rs index a7370f580a33..f1e9d8f59383 100644 --- a/crates/ide-assists/src/handlers/auto_import.rs +++ b/crates/ide-assists/src/handlers/auto_import.rs @@ -4,6 +4,7 @@ use either::Either; use hir::{Module, Type, db::HirDatabase}; use ide_db::{ active_parameter::ActiveParameter, + base_db::SourceDatabase, helpers::mod_path_to_ast, imports::{ import_assets::{ImportAssets, ImportCandidate, LocatedImport, TraitImportCandidate}, diff --git a/crates/ide-assists/src/handlers/fix_visibility.rs b/crates/ide-assists/src/handlers/fix_visibility.rs index 22e17645e3d2..2c638a721922 100644 --- a/crates/ide-assists/src/handlers/fix_visibility.rs +++ b/crates/ide-assists/src/handlers/fix_visibility.rs @@ -1,5 +1,5 @@ use hir::{HasSource, HasVisibility, ModuleDef, PathResolution, ScopeDef, db::HirDatabase}; -use ide_db::FileId; +use ide_db::{FileId, base_db::SourceDatabase}; use syntax::{ AstNode, TextRange, ast::{self, HasVisibility as _, syntax_factory::SyntaxFactory}, diff --git a/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/crates/ide-assists/src/handlers/generate_delegate_trait.rs index f3c1dfbb4f89..2140ccd28a5b 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_trait.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_trait.rs @@ -9,6 +9,7 @@ use hir::{HasVisibility, db::HirDatabase}; use ide_db::{ FxHashMap, FxHashSet, assists::{AssistId, GroupLabel}, + base_db::SourceDatabase, path_transform::PathTransform, syntax_helpers::suggest_name, }; diff --git a/crates/ide-assists/src/handlers/generate_function.rs b/crates/ide-assists/src/handlers/generate_function.rs index a1afe9b5c613..34aebdbefc72 100644 --- a/crates/ide-assists/src/handlers/generate_function.rs +++ b/crates/ide-assists/src/handlers/generate_function.rs @@ -4,6 +4,7 @@ use hir::{ }; use ide_db::{ FileId, FxHashMap, FxHashSet, RootDatabase, SnippetCap, + base_db::SourceDatabase, defs::{Definition, NameRefClass}, famous_defs::FamousDefs, helpers::is_editable_crate, diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs index 3f56b8a1d6ea..fd5b359d0e4e 100644 --- a/crates/ide-assists/src/handlers/inline_call.rs +++ b/crates/ide-assists/src/handlers/inline_call.rs @@ -4,7 +4,7 @@ use either::Either; use hir::{FileRange, PathResolution, Semantics, TypeInfo, db::HirDatabase, sym}; use ide_db::{ EditionedFileId, FxHashMap, RootDatabase, - base_db::Crate, + base_db::{Crate, SourceDatabase}, defs::Definition, imports::insert_use::remove_use_tree_if_simple, path_transform::PathTransform, diff --git a/crates/ide-assists/src/handlers/qualify_method_call.rs b/crates/ide-assists/src/handlers/qualify_method_call.rs index 625cdeb36936..4b85d3bb8e2d 100644 --- a/crates/ide-assists/src/handlers/qualify_method_call.rs +++ b/crates/ide-assists/src/handlers/qualify_method_call.rs @@ -1,5 +1,5 @@ use hir::{AsAssocItem, AssocItem, AssocItemContainer, ItemInNs, ModuleDef, db::HirDatabase}; -use ide_db::assists::AssistId; +use ide_db::{assists::AssistId, base_db::SourceDatabase}; use syntax::{AstNode, ast}; use crate::{ diff --git a/crates/ide-assists/src/utils.rs b/crates/ide-assists/src/utils.rs index 6fb2f74108c8..e928fd049d82 100644 --- a/crates/ide-assists/src/utils.rs +++ b/crates/ide-assists/src/utils.rs @@ -10,6 +10,7 @@ use hir::{ use ide_db::{ RootDatabase, assists::ExprFillDefaultMode, + base_db::SourceDatabase, famous_defs::FamousDefs, path_transform::PathTransform, syntax_helpers::{node_ext::preorder_expr, prettify_macro_expansion}, diff --git a/crates/ide-completion/src/render/function.rs b/crates/ide-completion/src/render/function.rs index 8d60f047ce1b..49b7217bb4d9 100644 --- a/crates/ide-completion/src/render/function.rs +++ b/crates/ide-completion/src/render/function.rs @@ -1,5 +1,6 @@ //! Renderer for function calls. +use base_db::SourceDatabase; use hir::{AsAssocItem, HirDisplay, db::HirDatabase}; use ide_db::{SnippetCap, SymbolKind}; use itertools::Itertools; diff --git a/crates/ide-completion/src/render/literal.rs b/crates/ide-completion/src/render/literal.rs index 05f2648ca575..3666ffe7cc60 100644 --- a/crates/ide-completion/src/render/literal.rs +++ b/crates/ide-completion/src/render/literal.rs @@ -1,5 +1,6 @@ //! Renderer for `enum` variants. +use base_db::SourceDatabase; use hir::{StructKind, db::HirDatabase}; use ide_db::{ SymbolKind, diff --git a/crates/ide-completion/src/render/macro_.rs b/crates/ide-completion/src/render/macro_.rs index fe51dc5be47d..12af2761d8a6 100644 --- a/crates/ide-completion/src/render/macro_.rs +++ b/crates/ide-completion/src/render/macro_.rs @@ -1,5 +1,6 @@ //! Renderer for macro invocations. +use base_db::SourceDatabase; use hir::{HirDisplay, db::HirDatabase}; use ide_db::{SymbolKind, documentation::Documentation}; use syntax::{SmolStr, ToSmolStr, format_smolstr}; diff --git a/crates/ide-completion/src/render/pattern.rs b/crates/ide-completion/src/render/pattern.rs index 9382c235d0a6..dede64d804ad 100644 --- a/crates/ide-completion/src/render/pattern.rs +++ b/crates/ide-completion/src/render/pattern.rs @@ -1,5 +1,6 @@ //! Renderer for patterns. +use base_db::SourceDatabase; use hir::{Name, StructKind, db::HirDatabase}; use ide_db::{SnippetCap, documentation::HasDocs}; use itertools::Itertools; diff --git a/crates/ide-db/src/defs.rs b/crates/ide-db/src/defs.rs index 0e8aea85faff..a05f54ef1a8e 100644 --- a/crates/ide-db/src/defs.rs +++ b/crates/ide-db/src/defs.rs @@ -11,6 +11,7 @@ use crate::RootDatabase; use crate::documentation::{Documentation, HasDocs}; use crate::famous_defs::FamousDefs; use arrayvec::ArrayVec; +use base_db::SourceDatabase; use either::Either; use hir::{ Adt, AsAssocItem, AsExternAssocItem, AssocItem, AttributeTemplate, BuiltinAttr, BuiltinType, diff --git a/crates/ide-db/src/documentation.rs b/crates/ide-db/src/documentation.rs index c1d1264222fa..cc6e2d44c0f0 100644 --- a/crates/ide-db/src/documentation.rs +++ b/crates/ide-db/src/documentation.rs @@ -1,6 +1,7 @@ //! Documentation attribute related utilities. use std::borrow::Cow; +use base_db::SourceDatabase; use hir::{HasAttrs, db::HirDatabase, resolve_doc_path_on}; /// Holds documentation diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs index 173a3bb214c3..f1feb1afe5ee 100644 --- a/crates/ide-db/src/symbol_index.rs +++ b/crates/ide-db/src/symbol_index.rs @@ -28,8 +28,8 @@ use std::{ }; use base_db::{ - CrateOrigin, InternedSourceRootId, LangCrateOrigin, LibraryRoots, LocalRoots, SourceRootId, - salsa::Update, source_root_crates, + CrateOrigin, InternedSourceRootId, LangCrateOrigin, LibraryRoots, LocalRoots, SourceDatabase, + SourceRootId, salsa::Update, source_root_crates, }; use fst::{Automaton, Streamer, raw::IndexedValue}; use hir::{ diff --git a/crates/ide-db/src/traits.rs b/crates/ide-db/src/traits.rs index dd01bd336c86..05bf46446e93 100644 --- a/crates/ide-db/src/traits.rs +++ b/crates/ide-db/src/traits.rs @@ -1,6 +1,7 @@ //! Functionality for obtaining data related to traits from the DB. use crate::{RootDatabase, defs::Definition}; +use base_db::SourceDatabase; use hir::{AsAssocItem, HasCrate, Semantics, db::HirDatabase, sym}; use rustc_hash::FxHashSet; use syntax::{AstNode, ast}; diff --git a/crates/ide-diagnostics/src/handlers/missing_fields.rs b/crates/ide-diagnostics/src/handlers/missing_fields.rs index d2b840f39ad9..18f1551da343 100644 --- a/crates/ide-diagnostics/src/handlers/missing_fields.rs +++ b/crates/ide-diagnostics/src/handlers/missing_fields.rs @@ -5,6 +5,7 @@ use hir::{ use ide_db::{ FxHashMap, assists::{Assist, ExprFillDefaultMode}, + base_db::SourceDatabase, famous_defs::FamousDefs, imports::import_assets::item_for_path_search, source_change::SourceChange, diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 57d146b2a6e2..89429206f13e 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -17,7 +17,7 @@ use hir::{ }; use ide_db::{ RootDatabase, - base_db::{CrateOrigin, LangCrateOrigin, ReleaseChannel, toolchain_channel}, + base_db::{CrateOrigin, LangCrateOrigin, ReleaseChannel, SourceDatabase, toolchain_channel}, defs::{Definition, NameClass, NameRefClass}, documentation::{Documentation, HasDocs}, helpers::pick_best_token, diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index 92902938235e..6c197070633d 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs @@ -2,8 +2,8 @@ use hir::{EditionedFileId, HirFileId, InFile, Semantics, db::HirDatabase}; use ide_db::{ - SymbolKind, defs::Definition, documentation::Documentation, range_mapper::RangeMapper, - rust_doc::is_rust_fence, + SymbolKind, base_db::SourceDatabase, defs::Definition, documentation::Documentation, + range_mapper::RangeMapper, rust_doc::is_rust_fence, }; use syntax::{ SyntaxNode, TextRange, TextSize, diff --git a/crates/rust-analyzer/src/cli.rs b/crates/rust-analyzer/src/cli.rs index 3910f321dd5a..4fa046aec7f1 100644 --- a/crates/rust-analyzer/src/cli.rs +++ b/crates/rust-analyzer/src/cli.rs @@ -24,6 +24,7 @@ use anyhow::Result; use hir::{Module, Name}; use hir_ty::db::HirDatabase; use ide::{AnalysisHost, Edition}; +use ide_db::base_db::SourceDatabase; use itertools::Itertools; use vfs::Vfs; From 85b0ec0f234c6122b90bc1e4ad02447f789d782d Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Fri, 31 Jul 2026 04:09:17 +0300 Subject: [PATCH 4/7] Manually fix some places that didn't have `HirDatabase` imported --- crates/hir-ty/src/infer/callee.rs | 1 + .../src/infer/closure/analysis/expr_use_visitor.rs | 1 + crates/hir-ty/src/infer/expr.rs | 1 + crates/hir-ty/src/infer/pat.rs | 1 + crates/hir-ty/src/infer/path.rs | 1 + crates/hir-ty/src/mir/eval/shim.rs | 1 + crates/hir-ty/src/next_solver/generic_arg.rs | 9 ++++++--- crates/hir-ty/src/next_solver/infer/errors.rs | 2 +- crates/hir-ty/src/next_solver/solver.rs | 2 +- 9 files changed, 14 insertions(+), 5 deletions(-) diff --git a/crates/hir-ty/src/infer/callee.rs b/crates/hir-ty/src/infer/callee.rs index 7331f7a8a4d2..9712609fc764 100644 --- a/crates/hir-ty/src/infer/callee.rs +++ b/crates/hir-ty/src/infer/callee.rs @@ -14,6 +14,7 @@ use rustc_type_ir::{ use crate::{ Adjust, Adjustment, AutoBorrow, autoderef::{GeneralAutoderef, InferenceContextAutoderef}, + db::HirDatabase, infer::{ AllowTwoPhase, AutoBorrowMutability, Expectation, InferenceContext, InferenceDiagnostic, expr::{ExprIsRead, TupleArgumentsFlag}, diff --git a/crates/hir-ty/src/infer/closure/analysis/expr_use_visitor.rs b/crates/hir-ty/src/infer/closure/analysis/expr_use_visitor.rs index 4d300f5048a5..f970307077e3 100644 --- a/crates/hir-ty/src/infer/closure/analysis/expr_use_visitor.rs +++ b/crates/hir-ty/src/infer/closure/analysis/expr_use_visitor.rs @@ -23,6 +23,7 @@ use tracing::{debug, instrument, trace}; use crate::{ Adjust, Adjustment, AutoBorrow, Span, + db::HirDatabase, infer::{ ByRef, CaptureSourceStack, DerefPatBorrowMode, InferenceContext, PatAdjust, PatAdjustment, UpvarCapture, closure::analysis::BorrowKind, diff --git a/crates/hir-ty/src/infer/expr.rs b/crates/hir-ty/src/infer/expr.rs index 570df6b871df..5521f80d8164 100644 --- a/crates/hir-ty/src/infer/expr.rs +++ b/crates/hir-ty/src/infer/expr.rs @@ -29,6 +29,7 @@ use tracing::debug; use crate::{ Adjust, Adjustment, CallableDefId, Rawness, Span, consteval::literal_ty, + db::HirDatabase, infer::{AllowTwoPhase, BreakableKind, coerce::CoerceMany, find_continuable, pat::PatOrigin}, lower::lower_mutability, method_resolution::{self, CandidateId, MethodCallee, MethodError}, diff --git a/crates/hir-ty/src/infer/pat.rs b/crates/hir-ty/src/infer/pat.rs index f464de06cd30..8c48915b0a45 100644 --- a/crates/hir-ty/src/infer/pat.rs +++ b/crates/hir-ty/src/infer/pat.rs @@ -27,6 +27,7 @@ use tracing::{debug, instrument, trace}; use crate::{ BindingMode, InferenceDiagnostic, Span, + db::HirDatabase, infer::{ AllowTwoPhase, ByRef, Expectation, InferenceContext, PatAdjust, PatAdjustment, expr::ExprIsRead, diff --git a/crates/hir-ty/src/infer/path.rs b/crates/hir-ty/src/infer/path.rs index 47a905fc142c..ca9f26c2ad5a 100644 --- a/crates/hir-ty/src/infer/path.rs +++ b/crates/hir-ty/src/infer/path.rs @@ -13,6 +13,7 @@ use stdx::never; use crate::{ ExplicitDropMethodUseKind, InferenceDiagnostic, Span, ValueTyDefId, + db::HirDatabase, infer::{ InferenceTyLoweringVarsCtx, diagnostics::InferenceTyLoweringContext as TyLoweringContext, }, diff --git a/crates/hir-ty/src/mir/eval/shim.rs b/crates/hir-ty/src/mir/eval/shim.rs index e569b32bd779..029ca9afc964 100644 --- a/crates/hir-ty/src/mir/eval/shim.rs +++ b/crates/hir-ty/src/mir/eval/shim.rs @@ -9,6 +9,7 @@ use rustc_type_ir::inherent::{GenericArgs as _, IntoKind, SliceLike, Ty as _}; use stdx::never; use crate::{ + db::HirDatabase, display::DisplayTarget, drop::{DropGlue, has_drop_glue}, mir::eval::{ diff --git a/crates/hir-ty/src/next_solver/generic_arg.rs b/crates/hir-ty/src/next_solver/generic_arg.rs index 483811f9e6f0..118cfe4880ac 100644 --- a/crates/hir-ty/src/next_solver/generic_arg.rs +++ b/crates/hir-ty/src/next_solver/generic_arg.rs @@ -20,9 +20,12 @@ use rustc_type_ir::{ walk::TypeWalker, }; -use crate::next_solver::{ - ConstInterned, RegionInterned, TyInterned, impl_foldable_for_interned_slice, - impl_foldable_for_stored_type, interned_slice, +use crate::{ + db::HirDatabase, + next_solver::{ + ConstInterned, RegionInterned, TyInterned, impl_foldable_for_interned_slice, + impl_foldable_for_stored_type, interned_slice, + }, }; use super::{ diff --git a/crates/hir-ty/src/next_solver/infer/errors.rs b/crates/hir-ty/src/next_solver/infer/errors.rs index c3e9caa1c676..37ce51b743d1 100644 --- a/crates/hir-ty/src/next_solver/infer/errors.rs +++ b/crates/hir-ty/src/next_solver/infer/errors.rs @@ -12,7 +12,7 @@ use tracing::{instrument, trace}; use crate::{ Span, - db::GeneralConstId, + db::{GeneralConstId, HirDatabase}, next_solver::{ AliasTerm, AnyImplId, Binder, ClauseKind, Const, ConstKind, DbInterner, HostEffectPredicate, PolyTraitPredicate, Predicate, PredicateKind, SolverContext, Term, diff --git a/crates/hir-ty/src/next_solver/solver.rs b/crates/hir-ty/src/next_solver/solver.rs index 5486a565815d..f6fe0810abd6 100644 --- a/crates/hir-ty/src/next_solver/solver.rs +++ b/crates/hir-ty/src/next_solver/solver.rs @@ -16,7 +16,7 @@ use tracing::debug; use crate::{ ParamEnvAndCrate, Span, - db::GeneralConstId, + db::{GeneralConstId, HirDatabase}, next_solver::{ AliasTy, AnyImplId, CanonicalVarKind, Clause, ClauseKind, CoercePredicate, ErrorGuaranteed, GenericArgs, ImplOrTraitAssocTermId, OpaqueTyIdWrapper, ParamEnv, Predicate, PredicateKind, From fcec18e4055aa590934a22ab761ffe5cc1ce45a7 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Fri, 31 Jul 2026 04:12:20 +0300 Subject: [PATCH 5/7] Some more manual fixes - Implement `as_dyn()` for DBs - Remove usage of `as_dyn()` in tests, it's now a compile error - Replace `HirDatabase::zalsa_register_downcaster()` with `SourceDatabase::zalsa_register_downcaster()` --- crates/hir-def/src/test_db.rs | 4 ++++ crates/hir-ty/src/mir/lower/tests.rs | 6 +++--- crates/hir-ty/src/test_db.rs | 4 ++++ crates/ide-assists/src/tests.rs | 4 ++-- crates/ide-completion/src/tests.rs | 2 +- crates/ide-db/src/lib.rs | 4 ++++ 6 files changed, 18 insertions(+), 6 deletions(-) diff --git a/crates/hir-def/src/test_db.rs b/crates/hir-def/src/test_db.rs index 4433522c1832..69bd73b6798a 100644 --- a/crates/hir-def/src/test_db.rs +++ b/crates/hir-def/src/test_db.rs @@ -145,6 +145,10 @@ impl SourceDatabase for TestDB { fn line_column(&self, _file: FileId, _offset: syntax::TextSize) -> Result<(u32, u32), ()> { Err(()) } + + fn as_dyn(&self) -> &dyn SourceDatabase { + self + } } impl TestDB { diff --git a/crates/hir-ty/src/mir/lower/tests.rs b/crates/hir-ty/src/mir/lower/tests.rs index fdd67fc4fb62..f287246a8c06 100644 --- a/crates/hir-ty/src/mir/lower/tests.rs +++ b/crates/hir-ty/src/mir/lower/tests.rs @@ -6,7 +6,7 @@ use crate::{InferBodyId, db::HirDatabase, setup_tracing, test_db::TestDB}; fn lower_mir(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let _tracing = setup_tracing(); let (db, file_ids) = TestDB::with_many_files(ra_fixture); - crate::attach_db(db.as_dyn(), || { + crate::attach_db(&db, || { let file_id = *file_ids.last().unwrap(); let module_id = db.module_for_file(file_id.file_id(&db)); let def_map = module_id.def_map(&db); @@ -54,7 +54,7 @@ fn foo() { fn check_borrowck(#[rust_analyzer::rust_fixture] ra_fixture: &str) { let _tracing = setup_tracing(); let (db, file_ids) = TestDB::with_many_files(ra_fixture); - crate::attach_db(db.as_dyn(), || { + crate::attach_db(&db, || { let file_id = *file_ids.last().unwrap(); let module_id = db.module_for_file(file_id.file_id(&db)); let def_map = module_id.def_map(&db); @@ -78,7 +78,7 @@ fn check_borrowck(#[rust_analyzer::rust_fixture] ra_fixture: &str) { } for body in bodies { - let _ = InferBodyId::from(body).borrowck(db.as_dyn()); + let _ = InferBodyId::from(body).borrowck(&db); } }) } diff --git a/crates/hir-ty/src/test_db.rs b/crates/hir-ty/src/test_db.rs index 59fda51781d2..ea9f97c3e85a 100644 --- a/crates/hir-ty/src/test_db.rs +++ b/crates/hir-ty/src/test_db.rs @@ -136,6 +136,10 @@ impl SourceDatabase for TestDB { fn line_column(&self, _file: FileId, _offset: syntax::TextSize) -> Result<(u32, u32), ()> { Err(()) } + + fn as_dyn(&self) -> &dyn SourceDatabase { + self + } } #[salsa::db] diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs index 3624099b13bc..c16c1a607e31 100644 --- a/crates/ide-assists/src/tests.rs +++ b/crates/ide-assists/src/tests.rs @@ -114,7 +114,7 @@ fn assists( range: ide_db::FileRange, ) -> Vec { hir::attach_db(db, || { - HirDatabase::zalsa_register_downcaster(db); + SourceDatabase::zalsa_register_downcaster(db); crate::assists(db, config, resolve, range) }) } @@ -350,7 +350,7 @@ fn check_with_config( }; let mut acc = Assists::new(&ctx, resolve); hir::attach_db(&db, || { - HirDatabase::zalsa_register_downcaster(&db); + SourceDatabase::zalsa_register_downcaster(&db); handler(&mut acc, &ctx); }); let mut res = acc.finish(); diff --git a/crates/ide-completion/src/tests.rs b/crates/ide-completion/src/tests.rs index e574d4de0ac7..b55a3b0b4c6e 100644 --- a/crates/ide-completion/src/tests.rs +++ b/crates/ide-completion/src/tests.rs @@ -310,7 +310,7 @@ pub(crate) fn get_all_items( ) -> Vec { let (db, position) = position(code); let res = hir::attach_db(&db, || { - HirDatabase::zalsa_register_downcaster(&db); + SourceDatabase::zalsa_register_downcaster(&db); crate::completions(&db, &config, position, trigger_character) }) .map_or_else(Vec::default, Into::into); diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs index 2c789ca1e957..3632e485e731 100644 --- a/crates/ide-db/src/lib.rs +++ b/crates/ide-db/src/lib.rs @@ -181,6 +181,10 @@ impl SourceDatabase for RootDatabase { fn line_column(&self, file: FileId, offset: syntax::TextSize) -> Result<(u32, u32), ()> { line_index(self, file).try_line_col(offset).map(|lc| (lc.line, lc.col)).ok_or(()) } + + fn as_dyn(&self) -> &dyn SourceDatabase { + self + } } impl Default for RootDatabase { From c1357b05e3585abd83cb49ec520e9ffc2b426876 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Fri, 31 Jul 2026 04:16:43 +0300 Subject: [PATCH 6/7] Run `cargo fix` to remove unused `HirDatabase` imports --- crates/hir-ty/src/autoderef.rs | 1 - crates/hir-ty/src/diagnostics/unsafe_check.rs | 1 - crates/hir-ty/src/infer/diagnostics.rs | 2 +- crates/hir-ty/src/infer/unify.rs | 1 - crates/hir-ty/src/layout/target.rs | 2 -- crates/hir-ty/src/next_solver.rs | 1 - crates/hir-ty/src/next_solver/generics.rs | 2 -- crates/hir-ty/src/next_solver/interner.rs | 3 --- crates/hir-ty/src/next_solver/ty.rs | 2 +- crates/hir-ty/src/target_feature.rs | 2 -- crates/hir-ty/src/upvars.rs | 2 -- crates/hir/src/has_source.rs | 2 +- crates/hir/src/semantics/source_to_def.rs | 5 +---- crates/ide-assists/src/handlers/fix_visibility.rs | 2 +- crates/ide-assists/src/handlers/qualify_method_call.rs | 2 +- crates/ide-assists/src/tests.rs | 2 +- crates/ide-completion/src/render/macro_.rs | 2 +- crates/ide-completion/src/tests.rs | 1 - crates/ide-db/src/documentation.rs | 2 +- crates/ide-db/src/lib.rs | 2 +- crates/ide-db/src/symbol_index.rs | 1 - crates/ide-db/src/traits.rs | 2 +- crates/ide/src/doc_links.rs | 4 +--- crates/ide/src/static_index.rs | 2 +- crates/ide/src/syntax_highlighting/inject.rs | 2 +- crates/rust-analyzer/src/cli.rs | 1 - crates/rust-analyzer/src/cli/diagnostics.rs | 2 +- crates/rust-analyzer/src/cli/run_tests.rs | 1 - crates/rust-analyzer/src/cli/unresolved_references.rs | 2 +- 29 files changed, 16 insertions(+), 40 deletions(-) diff --git a/crates/hir-ty/src/autoderef.rs b/crates/hir-ty/src/autoderef.rs index 87304501e334..928557c08729 100644 --- a/crates/hir-ty/src/autoderef.rs +++ b/crates/hir-ty/src/autoderef.rs @@ -14,7 +14,6 @@ use tracing::debug; use crate::{ ParamEnvAndCrate, Span, - db::HirDatabase, infer::InferenceContext, next_solver::{ Canonical, DbInterner, ParamEnv, TraitRef, Ty, TyKind, TypingMode, diff --git a/crates/hir-ty/src/diagnostics/unsafe_check.rs b/crates/hir-ty/src/diagnostics/unsafe_check.rs index 571e6ecb7a58..6753b86db4fb 100644 --- a/crates/hir-ty/src/diagnostics/unsafe_check.rs +++ b/crates/hir-ty/src/diagnostics/unsafe_check.rs @@ -19,7 +19,6 @@ use span::Edition; use crate::{ InferenceResult, TargetFeatures, - db::HirDatabase, next_solver::{CallableIdWrapper, TyKind, abi::Safety}, utils::{TargetFeatureIsSafeInTarget, is_fn_unsafe_to_call, target_feature_is_safe_in_target}, }; diff --git a/crates/hir-ty/src/infer/diagnostics.rs b/crates/hir-ty/src/infer/diagnostics.rs index bf3abd3f98fa..21a4efdc1ab9 100644 --- a/crates/hir-ty/src/infer/diagnostics.rs +++ b/crates/hir-ty/src/infer/diagnostics.rs @@ -21,7 +21,7 @@ use thin_vec::ThinVec; use crate::lower::LifetimeLoweringMode; use crate::{ InferenceDiagnostic, InferenceTyDiagnosticSource, Span, TyLoweringDiagnostic, - db::{AnonConstId, HirDatabase}, + db::AnonConstId, generics::Generics, infer::unify::InferenceTable, lower::{ diff --git a/crates/hir-ty/src/infer/unify.rs b/crates/hir-ty/src/infer/unify.rs index 6a847447a3a0..792f2a6a569a 100644 --- a/crates/hir-ty/src/infer/unify.rs +++ b/crates/hir-ty/src/infer/unify.rs @@ -15,7 +15,6 @@ use thin_vec::ThinVec; use crate::{ InferenceDiagnostic, Span, - db::HirDatabase, next_solver::{ Canonical, ClauseKind, Const, ConstKind, DbInterner, ErrorGuaranteed, GenericArg, GenericArgs, ParamEnv, Predicate, PredicateKind, Region, SolverDefId, Term, TraitRef, Ty, diff --git a/crates/hir-ty/src/layout/target.rs b/crates/hir-ty/src/layout/target.rs index e381e0eec13c..cac3d6a7c204 100644 --- a/crates/hir-ty/src/layout/target.rs +++ b/crates/hir-ty/src/layout/target.rs @@ -4,8 +4,6 @@ use base_db::{Crate, SourceDatabase, target::TargetLoadError}; use hir_def::layout::TargetDataLayout; use rustc_abi::{AddressSpace, AlignFromBytesError, TargetDataLayoutError}; -use crate::db::HirDatabase; - #[salsa::tracked(returns(as_ref))] pub fn target_data_layout_query( db: &dyn SourceDatabase, diff --git a/crates/hir-ty/src/next_solver.rs b/crates/hir-ty/src/next_solver.rs index 87f2efb152c7..80bd545f3e11 100644 --- a/crates/hir-ty/src/next_solver.rs +++ b/crates/hir-ty/src/next_solver.rs @@ -44,7 +44,6 @@ use rustc_type_ir::MayBeErased; pub use solver::*; pub use ty::*; -use crate::db::HirDatabase; pub use crate::lower::ImplTraitIdx; pub use rustc_ast_ir::Mutability; diff --git a/crates/hir-ty/src/next_solver/generics.rs b/crates/hir-ty/src/next_solver/generics.rs index 16c2a82a9f94..277bbe59e73d 100644 --- a/crates/hir-ty/src/next_solver/generics.rs +++ b/crates/hir-ty/src/next_solver/generics.rs @@ -6,8 +6,6 @@ use hir_def::{ hir::generics::{GenericParamDataRef, LifetimeParamData}, }; -use crate::db::HirDatabase; - use super::{Ctor, DbInterner, SolverDefId}; pub(crate) fn generics<'db>(interner: DbInterner<'db>, def: SolverDefId<'db>) -> Generics<'db> { diff --git a/crates/hir-ty/src/next_solver/interner.rs b/crates/hir-ty/src/next_solver/interner.rs index 9a87c3c35e37..6b46d5cb068d 100644 --- a/crates/hir-ty/src/next_solver/interner.rs +++ b/crates/hir-ty/src/next_solver/interner.rs @@ -2400,8 +2400,6 @@ mod tls_db { use base_db::SourceDatabase; - use crate::db::HirDatabase; - struct Attached { database: Cell>>, } @@ -2514,7 +2512,6 @@ mod tls_db { } mod tls_cache { - use crate::db::HirDatabase; use super::DbInterner; use base_db::{Nonce, SourceDatabase}; diff --git a/crates/hir-ty/src/next_solver/ty.rs b/crates/hir-ty/src/next_solver/ty.rs index b8f6a40cf674..55e53fdcea3b 100644 --- a/crates/hir-ty/src/next_solver/ty.rs +++ b/crates/hir-ty/src/next_solver/ty.rs @@ -27,7 +27,7 @@ use rustc_type_ir::{ }; use crate::{ - db::{HirDatabase, InternedOpaqueTyId}, + db::InternedOpaqueTyId, lower::GenericPredicates, next_solver::{ AdtDef, AliasTy, Binder, CallableIdWrapper, Clause, ClauseKind, ClosureIdWrapper, Const, diff --git a/crates/hir-ty/src/target_feature.rs b/crates/hir-ty/src/target_feature.rs index 7477e7e168a0..2b3ddc13c1d1 100644 --- a/crates/hir-ty/src/target_feature.rs +++ b/crates/hir-ty/src/target_feature.rs @@ -9,8 +9,6 @@ use hir_def::attrs::AttrFlags; use intern::Symbol; use rustc_hash::{FxHashMap, FxHashSet}; -use crate::db::HirDatabase; - #[derive(Debug, Default, Clone)] pub struct TargetFeatures<'db> { pub(crate) enabled: Cow<'db, FxHashSet>, diff --git a/crates/hir-ty/src/upvars.rs b/crates/hir-ty/src/upvars.rs index e55e20e3b158..0353132d6834 100644 --- a/crates/hir-ty/src/upvars.rs +++ b/crates/hir-ty/src/upvars.rs @@ -10,8 +10,6 @@ use hir_def::{ use hir_expand::mod_path::PathKind; use rustc_hash::{FxHashMap, FxHashSet}; -use crate::db::HirDatabase; - #[derive(Debug, Clone, PartialEq, Eq, Hash)] // Kept sorted. pub struct Upvars(Box<[BindingId]>); diff --git a/crates/hir/src/has_source.rs b/crates/hir/src/has_source.rs index 10e14ead5745..cc04191feebc 100644 --- a/crates/hir/src/has_source.rs +++ b/crates/hir/src/has_source.rs @@ -16,7 +16,7 @@ use tt::TextRange; use crate::{ Adt, AnyFunctionId, Callee, Const, Enum, EnumVariant, ExternCrateDecl, Field, FieldSource, Function, Impl, InlineAsmOperand, Label, LifetimeParam, LocalSource, Macro, Module, Param, - SelfParam, Static, Struct, Trait, TypeAlias, TypeOrConstParam, Union, Variant, db::HirDatabase, + SelfParam, Static, Struct, Trait, TypeAlias, TypeOrConstParam, Union, Variant, }; pub trait HasSource: Sized { diff --git a/crates/hir/src/semantics/source_to_def.rs b/crates/hir/src/semantics/source_to_def.rs index 55f4196abd40..44c400d7c989 100644 --- a/crates/hir/src/semantics/source_to_def.rs +++ b/crates/hir/src/semantics/source_to_def.rs @@ -114,10 +114,7 @@ use syntax::{ }; use tt::TextRange; -use crate::{ - InFile, InlineAsmOperand, SemanticsImpl, db::HirDatabase, - semantics::child_by_source::ChildBySource, -}; +use crate::{InFile, InlineAsmOperand, SemanticsImpl, semantics::child_by_source::ChildBySource}; #[derive(Default)] pub(super) struct SourceToDefCache<'db> { diff --git a/crates/ide-assists/src/handlers/fix_visibility.rs b/crates/ide-assists/src/handlers/fix_visibility.rs index 2c638a721922..089f5d961522 100644 --- a/crates/ide-assists/src/handlers/fix_visibility.rs +++ b/crates/ide-assists/src/handlers/fix_visibility.rs @@ -1,4 +1,4 @@ -use hir::{HasSource, HasVisibility, ModuleDef, PathResolution, ScopeDef, db::HirDatabase}; +use hir::{HasSource, HasVisibility, ModuleDef, PathResolution, ScopeDef}; use ide_db::{FileId, base_db::SourceDatabase}; use syntax::{ AstNode, TextRange, diff --git a/crates/ide-assists/src/handlers/qualify_method_call.rs b/crates/ide-assists/src/handlers/qualify_method_call.rs index 4b85d3bb8e2d..90371835811e 100644 --- a/crates/ide-assists/src/handlers/qualify_method_call.rs +++ b/crates/ide-assists/src/handlers/qualify_method_call.rs @@ -1,4 +1,4 @@ -use hir::{AsAssocItem, AssocItem, AssocItemContainer, ItemInNs, ModuleDef, db::HirDatabase}; +use hir::{AsAssocItem, AssocItem, AssocItemContainer, ItemInNs, ModuleDef}; use ide_db::{assists::AssistId, base_db::SourceDatabase}; use syntax::{AstNode, ast}; diff --git a/crates/ide-assists/src/tests.rs b/crates/ide-assists/src/tests.rs index c16c1a607e31..eaeddb454664 100644 --- a/crates/ide-assists/src/tests.rs +++ b/crates/ide-assists/src/tests.rs @@ -1,7 +1,7 @@ mod generated; use expect_test::expect; -use hir::{Semantics, db::HirDatabase, setup_tracing}; +use hir::{Semantics, setup_tracing}; use ide_db::{ EditionedFileId, FileRange, RootDatabase, SnippetCap, assists::ExprFillDefaultMode, diff --git a/crates/ide-completion/src/render/macro_.rs b/crates/ide-completion/src/render/macro_.rs index 12af2761d8a6..abd2bd7b9513 100644 --- a/crates/ide-completion/src/render/macro_.rs +++ b/crates/ide-completion/src/render/macro_.rs @@ -1,7 +1,7 @@ //! Renderer for macro invocations. use base_db::SourceDatabase; -use hir::{HirDisplay, db::HirDatabase}; +use hir::HirDisplay; use ide_db::{SymbolKind, documentation::Documentation}; use syntax::{SmolStr, ToSmolStr, format_smolstr}; diff --git a/crates/ide-completion/src/tests.rs b/crates/ide-completion/src/tests.rs index b55a3b0b4c6e..c5e1cf508a2d 100644 --- a/crates/ide-completion/src/tests.rs +++ b/crates/ide-completion/src/tests.rs @@ -26,7 +26,6 @@ mod visibility; use base_db::SourceDatabase; use expect_test::Expect; -use hir::db::HirDatabase; use hir::{PrefixKind, setup_tracing}; use ide_db::{ FilePosition, RootDatabase, SnippetCap, diff --git a/crates/ide-db/src/documentation.rs b/crates/ide-db/src/documentation.rs index cc6e2d44c0f0..e4f859dd9463 100644 --- a/crates/ide-db/src/documentation.rs +++ b/crates/ide-db/src/documentation.rs @@ -2,7 +2,7 @@ use std::borrow::Cow; use base_db::SourceDatabase; -use hir::{HasAttrs, db::HirDatabase, resolve_doc_path_on}; +use hir::{HasAttrs, resolve_doc_path_on}; /// Holds documentation #[derive(Debug, Clone, PartialEq, Eq, Hash)] diff --git a/crates/ide-db/src/lib.rs b/crates/ide-db/src/lib.rs index 3632e485e731..ed191a9d6ef7 100644 --- a/crates/ide-db/src/lib.rs +++ b/crates/ide-db/src/lib.rs @@ -63,7 +63,7 @@ use base_db::{ CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, Files, Nonce, SourceDatabase, SourceRoot, SourceRootId, SourceRootInput, set_all_crates_with_durability, }; -use hir::{FilePositionWrapper, FileRangeWrapper, db::HirDatabase}; +use hir::{FilePositionWrapper, FileRangeWrapper}; use triomphe::Arc; use crate::line_index::LineIndex; diff --git a/crates/ide-db/src/symbol_index.rs b/crates/ide-db/src/symbol_index.rs index f1feb1afe5ee..a87888c222e7 100644 --- a/crates/ide-db/src/symbol_index.rs +++ b/crates/ide-db/src/symbol_index.rs @@ -34,7 +34,6 @@ use base_db::{ use fst::{Automaton, Streamer, raw::IndexedValue}; use hir::{ Crate, Module, - db::HirDatabase, import_map::{AssocSearchMode, SearchMode}, symbols::{FileSymbol, SymbolCollector}, }; diff --git a/crates/ide-db/src/traits.rs b/crates/ide-db/src/traits.rs index 05bf46446e93..b726ed4ca33f 100644 --- a/crates/ide-db/src/traits.rs +++ b/crates/ide-db/src/traits.rs @@ -2,7 +2,7 @@ use crate::{RootDatabase, defs::Definition}; use base_db::SourceDatabase; -use hir::{AsAssocItem, HasCrate, Semantics, db::HirDatabase, sym}; +use hir::{AsAssocItem, HasCrate, Semantics, sym}; use rustc_hash::FxHashSet; use syntax::{AstNode, ast}; diff --git a/crates/ide/src/doc_links.rs b/crates/ide/src/doc_links.rs index 89429206f13e..6515e29375e8 100644 --- a/crates/ide/src/doc_links.rs +++ b/crates/ide/src/doc_links.rs @@ -12,9 +12,7 @@ use pulldown_cmark_to_cmark::{Options as CMarkOptions, cmark_with_options}; use stdx::format_to; use url::Url; -use hir::{ - Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrsWithOwner, HasAttrs, db::HirDatabase, -}; +use hir::{Adt, AsAssocItem, AssocItem, AssocItemContainer, AttrsWithOwner, HasAttrs}; use ide_db::{ RootDatabase, base_db::{CrateOrigin, LangCrateOrigin, ReleaseChannel, SourceDatabase, toolchain_channel}, diff --git a/crates/ide/src/static_index.rs b/crates/ide/src/static_index.rs index 8903c92b24a4..8f41b8d85c65 100644 --- a/crates/ide/src/static_index.rs +++ b/crates/ide/src/static_index.rs @@ -3,7 +3,7 @@ use arrayvec::ArrayVec; use either::Either; -use hir::{Crate, Module, Semantics, db::HirDatabase}; +use hir::{Crate, Module, Semantics}; use ide_db::{ FileId, FileRange, FxHashMap, FxHashSet, RootDatabase, base_db::{SourceDatabase, VfsPath}, diff --git a/crates/ide/src/syntax_highlighting/inject.rs b/crates/ide/src/syntax_highlighting/inject.rs index 6c197070633d..4f8925687f29 100644 --- a/crates/ide/src/syntax_highlighting/inject.rs +++ b/crates/ide/src/syntax_highlighting/inject.rs @@ -1,6 +1,6 @@ //! "Recursive" Syntax highlighting for code in doctests and fixtures. -use hir::{EditionedFileId, HirFileId, InFile, Semantics, db::HirDatabase}; +use hir::{EditionedFileId, HirFileId, InFile, Semantics}; use ide_db::{ SymbolKind, base_db::SourceDatabase, defs::Definition, documentation::Documentation, range_mapper::RangeMapper, rust_doc::is_rust_fence, diff --git a/crates/rust-analyzer/src/cli.rs b/crates/rust-analyzer/src/cli.rs index 4fa046aec7f1..10888f6367f0 100644 --- a/crates/rust-analyzer/src/cli.rs +++ b/crates/rust-analyzer/src/cli.rs @@ -22,7 +22,6 @@ use std::io::Read; use anyhow::Result; use hir::{Module, Name}; -use hir_ty::db::HirDatabase; use ide::{AnalysisHost, Edition}; use ide_db::base_db::SourceDatabase; use itertools::Itertools; diff --git a/crates/rust-analyzer/src/cli/diagnostics.rs b/crates/rust-analyzer/src/cli/diagnostics.rs index 0269de97936c..77a60fe3e1d2 100644 --- a/crates/rust-analyzer/src/cli/diagnostics.rs +++ b/crates/rust-analyzer/src/cli/diagnostics.rs @@ -4,7 +4,7 @@ use project_model::{CargoConfig, RustLibSource}; use rustc_hash::FxHashSet; -use hir::{Crate, Module, db::HirDatabase, sym}; +use hir::{Crate, Module, sym}; use ide::{AnalysisHost, AssistResolveStrategy, Diagnostic, DiagnosticsConfig, Severity}; use ide_db::{base_db::SourceDatabase, line_index}; use load_cargo::{LoadCargoConfig, ProcMacroServerChoice, load_workspace_at}; diff --git a/crates/rust-analyzer/src/cli/run_tests.rs b/crates/rust-analyzer/src/cli/run_tests.rs index 62e19c813cb0..8f0dbb1d6f91 100644 --- a/crates/rust-analyzer/src/cli/run_tests.rs +++ b/crates/rust-analyzer/src/cli/run_tests.rs @@ -1,7 +1,6 @@ //! Run all tests in a project, similar to `cargo test`, but using the mir interpreter. use hir::{Crate, Module}; -use hir_ty::db::HirDatabase; use ide_db::{base_db::SourceDatabase, line_index}; use profile::StopWatch; use project_model::{CargoConfig, RustLibSource}; diff --git a/crates/rust-analyzer/src/cli/unresolved_references.rs b/crates/rust-analyzer/src/cli/unresolved_references.rs index e4695cb49944..dbea2807a587 100644 --- a/crates/rust-analyzer/src/cli/unresolved_references.rs +++ b/crates/rust-analyzer/src/cli/unresolved_references.rs @@ -1,5 +1,5 @@ //! Reports references in code that the IDE layer cannot resolve. -use hir::{AnyDiagnostic, Crate, Module, Semantics, db::HirDatabase, sym}; +use hir::{AnyDiagnostic, Crate, Module, Semantics, sym}; use ide::{AnalysisHost, RootDatabase, TextRange}; use ide_db::{FxHashSet, base_db::SourceDatabase, defs::NameRefClass, line_index}; use load_cargo::{LoadCargoConfig, ProcMacroServerChoice, load_workspace_at}; From fa5a5080e5d19489e0ba1e558df6f4d0f4714250 Mon Sep 17 00:00:00 2001 From: Chayim Refael Friedman Date: Fri, 31 Jul 2026 04:18:52 +0300 Subject: [PATCH 7/7] Remove some unused iimports that `cargo fix` didn't fix for some reason --- crates/hir-ty/src/diagnostics/match_check.rs | 1 - crates/hir-ty/src/infer/coerce.rs | 2 +- crates/hir/src/attrs.rs | 1 - crates/hir/src/diagnostics.rs | 1 - crates/hir/src/display.rs | 1 - crates/hir/src/term_search/expr.rs | 5 +---- crates/ide-assists/src/handlers/auto_import.rs | 2 +- crates/ide-assists/src/handlers/generate_delegate_trait.rs | 2 +- crates/ide-assists/src/handlers/inline_call.rs | 2 +- crates/ide-assists/src/utils.rs | 5 +---- crates/ide-completion/src/render/function.rs | 2 +- crates/ide-completion/src/render/literal.rs | 2 +- crates/ide-completion/src/render/pattern.rs | 2 +- crates/ide-diagnostics/src/handlers/missing_fields.rs | 4 +--- 14 files changed, 10 insertions(+), 22 deletions(-) diff --git a/crates/hir-ty/src/diagnostics/match_check.rs b/crates/hir-ty/src/diagnostics/match_check.rs index df18946170ef..e6bdaddbb630 100644 --- a/crates/hir-ty/src/diagnostics/match_check.rs +++ b/crates/hir-ty/src/diagnostics/match_check.rs @@ -24,7 +24,6 @@ use stdx::{always, never, variance::PhantomCovariantLifetime}; use crate::{ ByRef, InferenceResult, - db::HirDatabase, display::{HirDisplay, HirDisplayError, HirFormatter}, infer::BindingMode, next_solver::{GenericArgs, Mutability, Ty, TyKind}, diff --git a/crates/hir-ty/src/infer/coerce.rs b/crates/hir-ty/src/infer/coerce.rs index d9ae214a43b3..c043af071bc8 100644 --- a/crates/hir-ty/src/infer/coerce.rs +++ b/crates/hir-ty/src/infer/coerce.rs @@ -55,7 +55,7 @@ use tracing::{debug, instrument}; use crate::{ Adjust, Adjustment, AutoBorrow, ParamEnvAndCrate, PointerCast, Span, TargetFeatures, autoderef::Autoderef, - db::{HirDatabase, InternedClosure, InternedClosureId}, + db::{InternedClosure, InternedClosureId}, infer::{AllowTwoPhase, AutoBorrowMutability, InferenceContext, expr::ExprIsRead}, next_solver::{ Binder, BoundConst, BoundRegion, BoundRegionKind, BoundTy, BoundTyKind, CallableIdWrapper, diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index 234a0510a339..17b7c5535bd0 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs @@ -18,7 +18,6 @@ use hir_expand::{ name::Name, }; use hir_ty::{ - db::HirDatabase, method_resolution::{self, CandidateId, MethodError, MethodResolutionContext}, next_solver::{DbInterner, TypingMode, infer::DbInternerInferExt}, }; diff --git a/crates/hir/src/diagnostics.rs b/crates/hir/src/diagnostics.rs index c32efca80015..5acb5dfe6c57 100644 --- a/crates/hir/src/diagnostics.rs +++ b/crates/hir/src/diagnostics.rs @@ -19,7 +19,6 @@ use hir_expand::{HirFileId, InFile, mod_path::ModPath, name::Name}; use hir_ty::{ CastError, ExplicitDropMethodUseKind, InferenceDiagnostic, InferenceTyDiagnosticSource, PathGenericsSource, PathLoweringDiagnostic, TyLoweringDiagnostic, - db::HirDatabase, diagnostics::{BodyValidationDiagnostic, UnsafetyReason}, display::{DisplayTarget, HirDisplay}, next_solver::{DbInterner, EarlyBinder}, diff --git a/crates/hir/src/display.rs b/crates/hir/src/display.rs index 8de01d44b43f..2eb6ee851071 100644 --- a/crates/hir/src/display.rs +++ b/crates/hir/src/display.rs @@ -20,7 +20,6 @@ use hir_def::{ use hir_expand::name::Name; use hir_ty::{ GenericPredicates, - db::HirDatabase, display::{ HirDisplay, HirDisplayWithExpressionStore, HirFormatter, Result, SizedByDefault, hir_display_with_store, write_bounds_like_dyn_trait_with_prefix, write_params_bounds, diff --git a/crates/hir/src/term_search/expr.rs b/crates/hir/src/term_search/expr.rs index 3def15f943a5..dbae9946353f 100644 --- a/crates/hir/src/term_search/expr.rs +++ b/crates/hir/src/term_search/expr.rs @@ -3,10 +3,7 @@ use base_db::SourceDatabase; use hir_def::FindPathConfig; use hir_expand::mod_path::ModPath; -use hir_ty::{ - db::HirDatabase, - display::{DisplaySourceCodeError, DisplayTarget, HirDisplay}, -}; +use hir_ty::display::{DisplaySourceCodeError, DisplayTarget, HirDisplay}; use itertools::Itertools; use span::Edition; diff --git a/crates/ide-assists/src/handlers/auto_import.rs b/crates/ide-assists/src/handlers/auto_import.rs index f1e9d8f59383..53bf490e994c 100644 --- a/crates/ide-assists/src/handlers/auto_import.rs +++ b/crates/ide-assists/src/handlers/auto_import.rs @@ -1,7 +1,7 @@ use std::cmp::Reverse; use either::Either; -use hir::{Module, Type, db::HirDatabase}; +use hir::{Module, Type}; use ide_db::{ active_parameter::ActiveParameter, base_db::SourceDatabase, diff --git a/crates/ide-assists/src/handlers/generate_delegate_trait.rs b/crates/ide-assists/src/handlers/generate_delegate_trait.rs index 2140ccd28a5b..c65a0fe9427f 100644 --- a/crates/ide-assists/src/handlers/generate_delegate_trait.rs +++ b/crates/ide-assists/src/handlers/generate_delegate_trait.rs @@ -5,7 +5,7 @@ use crate::{ utils::convert_param_list_to_arg_list, }; use either::Either; -use hir::{HasVisibility, db::HirDatabase}; +use hir::HasVisibility; use ide_db::{ FxHashMap, FxHashSet, assists::{AssistId, GroupLabel}, diff --git a/crates/ide-assists/src/handlers/inline_call.rs b/crates/ide-assists/src/handlers/inline_call.rs index fd5b359d0e4e..0199316dcf59 100644 --- a/crates/ide-assists/src/handlers/inline_call.rs +++ b/crates/ide-assists/src/handlers/inline_call.rs @@ -1,7 +1,7 @@ use std::collections::BTreeSet; use either::Either; -use hir::{FileRange, PathResolution, Semantics, TypeInfo, db::HirDatabase, sym}; +use hir::{FileRange, PathResolution, Semantics, TypeInfo, sym}; use ide_db::{ EditionedFileId, FxHashMap, RootDatabase, base_db::{Crate, SourceDatabase}, diff --git a/crates/ide-assists/src/utils.rs b/crates/ide-assists/src/utils.rs index e928fd049d82..a66f61a42269 100644 --- a/crates/ide-assists/src/utils.rs +++ b/crates/ide-assists/src/utils.rs @@ -3,10 +3,7 @@ use std::slice; pub(crate) use gen_trait_fn_body::gen_trait_fn_body; -use hir::{ - HasAttrs as HirHasAttrs, HirDisplay, InFile, ModuleDef, PathResolution, Semantics, - db::HirDatabase, -}; +use hir::{HasAttrs as HirHasAttrs, HirDisplay, InFile, ModuleDef, PathResolution, Semantics}; use ide_db::{ RootDatabase, assists::ExprFillDefaultMode, diff --git a/crates/ide-completion/src/render/function.rs b/crates/ide-completion/src/render/function.rs index 49b7217bb4d9..913b13bb0475 100644 --- a/crates/ide-completion/src/render/function.rs +++ b/crates/ide-completion/src/render/function.rs @@ -1,7 +1,7 @@ //! Renderer for function calls. use base_db::SourceDatabase; -use hir::{AsAssocItem, HirDisplay, db::HirDatabase}; +use hir::{AsAssocItem, HirDisplay}; use ide_db::{SnippetCap, SymbolKind}; use itertools::Itertools; use stdx::{format_to, to_lower_snake_case}; diff --git a/crates/ide-completion/src/render/literal.rs b/crates/ide-completion/src/render/literal.rs index 3666ffe7cc60..23355b37c48a 100644 --- a/crates/ide-completion/src/render/literal.rs +++ b/crates/ide-completion/src/render/literal.rs @@ -1,7 +1,7 @@ //! Renderer for `enum` variants. use base_db::SourceDatabase; -use hir::{StructKind, db::HirDatabase}; +use hir::StructKind; use ide_db::{ SymbolKind, documentation::{Documentation, HasDocs}, diff --git a/crates/ide-completion/src/render/pattern.rs b/crates/ide-completion/src/render/pattern.rs index dede64d804ad..21da5b599b16 100644 --- a/crates/ide-completion/src/render/pattern.rs +++ b/crates/ide-completion/src/render/pattern.rs @@ -1,7 +1,7 @@ //! Renderer for patterns. use base_db::SourceDatabase; -use hir::{Name, StructKind, db::HirDatabase}; +use hir::{Name, StructKind}; use ide_db::{SnippetCap, documentation::HasDocs}; use itertools::Itertools; use syntax::{Edition, SmolStr, ToSmolStr}; diff --git a/crates/ide-diagnostics/src/handlers/missing_fields.rs b/crates/ide-diagnostics/src/handlers/missing_fields.rs index 18f1551da343..1306ab6def7a 100644 --- a/crates/ide-diagnostics/src/handlers/missing_fields.rs +++ b/crates/ide-diagnostics/src/handlers/missing_fields.rs @@ -1,7 +1,5 @@ use either::Either; -use hir::{ - AssocItem, FindPathConfig, HasVisibility, HirDisplay, InFile, Type, db::HirDatabase, sym, -}; +use hir::{AssocItem, FindPathConfig, HasVisibility, HirDisplay, InFile, Type, sym}; use ide_db::{ FxHashMap, assists::{Assist, ExprFillDefaultMode},