From 9faea2364dee4fbc9391ad233c570b70256ef002 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 13 Mar 2020 16:05:46 +0100 Subject: Use `dyn Trait` for working with databse It improves compile time in `--release` mode quite a bit, it doesn't really slow things down and, conceptually, it seems closer to what we want the physical architecture to look like (we don't want to monomorphise EVERYTHING in a single leaf crate). --- crates/ra_hir_ty/src/autoderef.rs | 8 +- crates/ra_hir_ty/src/db.rs | 4 +- crates/ra_hir_ty/src/display.rs | 50 ++++--- crates/ra_hir_ty/src/expr.rs | 19 +-- crates/ra_hir_ty/src/infer.rs | 38 +++--- crates/ra_hir_ty/src/infer/coerce.rs | 8 +- crates/ra_hir_ty/src/infer/expr.rs | 23 ++-- crates/ra_hir_ty/src/infer/pat.rs | 8 +- crates/ra_hir_ty/src/infer/path.rs | 15 +- crates/ra_hir_ty/src/infer/unify.rs | 18 +-- crates/ra_hir_ty/src/lib.rs | 36 ++--- crates/ra_hir_ty/src/lower.rs | 220 +++++++++++++++--------------- crates/ra_hir_ty/src/method_resolution.rs | 43 +++--- crates/ra_hir_ty/src/test_db.rs | 18 ++- crates/ra_hir_ty/src/traits.rs | 12 +- crates/ra_hir_ty/src/traits/builtin.rs | 36 +++-- crates/ra_hir_ty/src/traits/chalk.rs | 111 ++++++++------- crates/ra_hir_ty/src/utils.rs | 16 +-- 18 files changed, 337 insertions(+), 346 deletions(-) (limited to 'crates/ra_hir_ty') diff --git a/crates/ra_hir_ty/src/autoderef.rs b/crates/ra_hir_ty/src/autoderef.rs index f32d5786a..53e81e85d 100644 --- a/crates/ra_hir_ty/src/autoderef.rs +++ b/crates/ra_hir_ty/src/autoderef.rs @@ -20,7 +20,7 @@ use crate::{ const AUTODEREF_RECURSION_LIMIT: usize = 10; pub fn autoderef<'a>( - db: &'a impl HirDatabase, + db: &'a dyn HirDatabase, krate: Option, ty: InEnvironment>, ) -> impl Iterator> + 'a { @@ -32,7 +32,7 @@ pub fn autoderef<'a>( } pub(crate) fn deref( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, ty: InEnvironment<&Canonical>, ) -> Option> { @@ -44,7 +44,7 @@ pub(crate) fn deref( } fn deref_by_trait( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, ty: InEnvironment<&Canonical>, ) -> Option> { @@ -54,7 +54,7 @@ fn deref_by_trait( }; let target = db.trait_data(deref_trait).associated_type_by_name(&name![Target])?; - let generic_params = generics(db, target.into()); + let generic_params = generics(db.upcast(), target.into()); if generic_params.len() != 1 { // the Target type + Deref trait should only have one generic parameter, // namely Deref's Self type diff --git a/crates/ra_hir_ty/src/db.rs b/crates/ra_hir_ty/src/db.rs index 74b309005..11fc2ac3d 100644 --- a/crates/ra_hir_ty/src/db.rs +++ b/crates/ra_hir_ty/src/db.rs @@ -7,7 +7,7 @@ use hir_def::{ VariantId, }; use ra_arena::map::ArenaMap; -use ra_db::{impl_intern_key, salsa, CrateId}; +use ra_db::{impl_intern_key, salsa, CrateId, Upcast}; use ra_prof::profile; use crate::{ @@ -20,7 +20,7 @@ use hir_expand::name::Name; #[salsa::query_group(HirDatabaseStorage)] #[salsa::requires(salsa::Database)] -pub trait HirDatabase: DefDatabase { +pub trait HirDatabase: DefDatabase + Upcast { #[salsa::invoke(infer_wait)] fn infer(&self, def: DefWithBodyId) -> Arc; diff --git a/crates/ra_hir_ty/src/display.rs b/crates/ra_hir_ty/src/display.rs index 14e089cf4..a6ef44a31 100644 --- a/crates/ra_hir_ty/src/display.rs +++ b/crates/ra_hir_ty/src/display.rs @@ -9,8 +9,8 @@ use crate::{ use hir_def::{generics::TypeParamProvenance, AdtId, AssocContainerId, Lookup}; use hir_expand::name::Name; -pub struct HirFormatter<'a, 'b, DB> { - pub db: &'a DB, +pub struct HirFormatter<'a, 'b> { + pub db: &'a dyn HirDatabase, fmt: &'a mut fmt::Formatter<'b>, buf: String, curr_size: usize, @@ -19,20 +19,20 @@ pub struct HirFormatter<'a, 'b, DB> { } pub trait HirDisplay { - fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result; + fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result; - fn display<'a, DB>(&'a self, db: &'a DB) -> HirDisplayWrapper<'a, DB, Self> + fn display<'a>(&'a self, db: &'a dyn HirDatabase) -> HirDisplayWrapper<'a, Self> where Self: Sized, { HirDisplayWrapper(db, self, None, false) } - fn display_truncated<'a, DB>( + fn display_truncated<'a>( &'a self, - db: &'a DB, + db: &'a dyn HirDatabase, max_size: Option, - ) -> HirDisplayWrapper<'a, DB, Self> + ) -> HirDisplayWrapper<'a, Self> where Self: Sized, { @@ -40,10 +40,7 @@ pub trait HirDisplay { } } -impl<'a, 'b, DB> HirFormatter<'a, 'b, DB> -where - DB: HirDatabase, -{ +impl<'a, 'b> HirFormatter<'a, 'b> { pub fn write_joined( &mut self, iter: impl IntoIterator, @@ -84,11 +81,10 @@ where } } -pub struct HirDisplayWrapper<'a, DB, T>(&'a DB, &'a T, Option, bool); +pub struct HirDisplayWrapper<'a, T>(&'a dyn HirDatabase, &'a T, Option, bool); -impl<'a, DB, T> fmt::Display for HirDisplayWrapper<'a, DB, T> +impl<'a, T> fmt::Display for HirDisplayWrapper<'a, T> where - DB: HirDatabase, T: HirDisplay, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { @@ -106,13 +102,13 @@ where const TYPE_HINT_TRUNCATION: &str = "…"; impl HirDisplay for &Ty { - fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { + fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { HirDisplay::hir_fmt(*self, f) } } impl HirDisplay for ApplicationTy { - fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { + fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { if f.should_truncate() { return write!(f, "{}", TYPE_HINT_TRUNCATION); } @@ -178,7 +174,7 @@ impl HirDisplay for ApplicationTy { } } if self.parameters.len() > 0 { - let generics = generics(f.db, def.into()); + let generics = generics(f.db.upcast(), def.into()); let (parent_params, self_param, type_params, _impl_trait_params) = generics.provenance_split(); let total_len = parent_params + self_param + type_params; @@ -238,7 +234,7 @@ impl HirDisplay for ApplicationTy { } } TypeCtor::AssociatedType(type_alias) => { - let trait_ = match type_alias.lookup(f.db).container { + let trait_ = match type_alias.lookup(f.db.upcast()).container { AssocContainerId::TraitId(it) => it, _ => panic!("not an associated type"), }; @@ -272,7 +268,7 @@ impl HirDisplay for ApplicationTy { } impl HirDisplay for ProjectionTy { - fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { + fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { if f.should_truncate() { return write!(f, "{}", TYPE_HINT_TRUNCATION); } @@ -290,7 +286,7 @@ impl HirDisplay for ProjectionTy { } impl HirDisplay for Ty { - fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { + fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { if f.should_truncate() { return write!(f, "{}", TYPE_HINT_TRUNCATION); } @@ -299,7 +295,7 @@ impl HirDisplay for Ty { Ty::Apply(a_ty) => a_ty.hir_fmt(f)?, Ty::Projection(p_ty) => p_ty.hir_fmt(f)?, Ty::Placeholder(id) => { - let generics = generics(f.db, id.parent); + let generics = generics(f.db.upcast(), id.parent); let param_data = &generics.params.types[id.local_id]; match param_data.provenance { TypeParamProvenance::TypeParamList | TypeParamProvenance::TraitSelf => { @@ -334,7 +330,7 @@ impl HirDisplay for Ty { fn write_bounds_like_dyn_trait( predicates: &[GenericPredicate], - f: &mut HirFormatter, + f: &mut HirFormatter, ) -> fmt::Result { // Note: This code is written to produce nice results (i.e. // corresponding to surface Rust) for types that can occur in @@ -398,7 +394,7 @@ fn write_bounds_like_dyn_trait( } impl TraitRef { - fn hir_fmt_ext(&self, f: &mut HirFormatter, use_as: bool) -> fmt::Result { + fn hir_fmt_ext(&self, f: &mut HirFormatter, use_as: bool) -> fmt::Result { if f.should_truncate() { return write!(f, "{}", TYPE_HINT_TRUNCATION); } @@ -420,19 +416,19 @@ impl TraitRef { } impl HirDisplay for TraitRef { - fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { + fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { self.hir_fmt_ext(f, false) } } impl HirDisplay for &GenericPredicate { - fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { + fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { HirDisplay::hir_fmt(*self, f) } } impl HirDisplay for GenericPredicate { - fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { + fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { if f.should_truncate() { return write!(f, "{}", TYPE_HINT_TRUNCATION); } @@ -456,7 +452,7 @@ impl HirDisplay for GenericPredicate { } impl HirDisplay for Obligation { - fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { + fn hir_fmt(&self, f: &mut HirFormatter) -> fmt::Result { match self { Obligation::Trait(tr) => write!(f, "Implements({})", tr.display(f.db)), Obligation::Projection(proj) => write!( diff --git a/crates/ra_hir_ty/src/expr.rs b/crates/ra_hir_ty/src/expr.rs index d8cdf5266..b7b476b4c 100644 --- a/crates/ra_hir_ty/src/expr.rs +++ b/crates/ra_hir_ty/src/expr.rs @@ -46,7 +46,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { ExprValidator { func, infer, sink } } - pub fn validate_body(&mut self, db: &impl HirDatabase) { + pub fn validate_body(&mut self, db: &dyn HirDatabase) { let body = db.body(self.func.into()); for e in body.exprs.iter() { @@ -67,7 +67,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { _path: &Option, fields: &[RecordLitField], spread: Option, - db: &impl HirDatabase, + db: &dyn HirDatabase, ) { if spread.is_some() { return; @@ -80,7 +80,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { return; } - let variant_data = variant_data(db, variant_def); + let variant_data = variant_data(db.upcast(), variant_def); let lit_fields: FxHashSet<_> = fields.iter().map(|f| &f.name).collect(); let missed_fields: Vec = variant_data @@ -102,7 +102,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { if let Ok(source_ptr) = source_map.expr_syntax(id) { if let Some(expr) = source_ptr.value.left() { - let root = source_ptr.file_syntax(db); + let root = source_ptr.file_syntax(db.upcast()); if let ast::Expr::RecordLit(record_lit) = expr.to_node(&root) { if let Some(field_list) = record_lit.record_field_list() { self.sink.push(MissingFields { @@ -116,12 +116,7 @@ impl<'a, 'b> ExprValidator<'a, 'b> { } } - fn validate_results_in_tail_expr( - &mut self, - body_id: ExprId, - id: ExprId, - db: &impl HirDatabase, - ) { + fn validate_results_in_tail_expr(&mut self, body_id: ExprId, id: ExprId, db: &dyn HirDatabase) { // the mismatch will be on the whole block currently let mismatch = match self.infer.type_mismatch_for_expr(body_id) { Some(m) => m, @@ -130,8 +125,8 @@ impl<'a, 'b> ExprValidator<'a, 'b> { let std_result_path = path![std::result::Result]; - let resolver = self.func.resolver(db); - let std_result_enum = match resolver.resolve_known_enum(db, &std_result_path) { + let resolver = self.func.resolver(db.upcast()); + let std_result_enum = match resolver.resolve_known_enum(db.upcast(), &std_result_path) { Some(it) => it, _ => return, }; diff --git a/crates/ra_hir_ty/src/infer.rs b/crates/ra_hir_ty/src/infer.rs index 947833412..246b0e9be 100644 --- a/crates/ra_hir_ty/src/infer.rs +++ b/crates/ra_hir_ty/src/infer.rs @@ -63,9 +63,9 @@ mod pat; mod coerce; /// The entry point of type inference. -pub(crate) fn infer_query(db: &impl HirDatabase, def: DefWithBodyId) -> Arc { +pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc { let _p = profile("infer_query"); - let resolver = def.resolver(db); + let resolver = def.resolver(db.upcast()); let mut ctx = InferenceContext::new(db, def, resolver); match def { @@ -164,7 +164,7 @@ impl InferenceResult { } pub fn add_diagnostics( &self, - db: &impl HirDatabase, + db: &dyn HirDatabase, owner: FunctionId, sink: &mut DiagnosticSink, ) { @@ -190,8 +190,8 @@ impl Index for InferenceResult { /// The inference context contains all information needed during type inference. #[derive(Clone, Debug)] -struct InferenceContext<'a, D: HirDatabase> { - db: &'a D, +struct InferenceContext<'a> { + db: &'a dyn HirDatabase, owner: DefWithBodyId, body: Arc, resolver: Resolver, @@ -208,8 +208,8 @@ struct InferenceContext<'a, D: HirDatabase> { return_ty: Ty, } -impl<'a, D: HirDatabase> InferenceContext<'a, D> { - fn new(db: &'a D, owner: DefWithBodyId, resolver: Resolver) -> Self { +impl<'a> InferenceContext<'a> { + fn new(db: &'a dyn HirDatabase, owner: DefWithBodyId, resolver: Resolver) -> Self { InferenceContext { result: InferenceResult::default(), table: unify::InferenceTable::new(), @@ -425,7 +425,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let ctx = crate::lower::TyLoweringContext::new(self.db, &self.resolver); // FIXME: this should resolve assoc items as well, see this example: // https://play.rust-lang.org/?gist=087992e9e22495446c01c0d4e2d69521 - return match resolver.resolve_path_in_type_ns_fully(self.db, path.mod_path()) { + return match resolver.resolve_path_in_type_ns_fully(self.db.upcast(), path.mod_path()) { Some(TypeNs::AdtId(AdtId::StructId(strukt))) => { let substs = Ty::substs_from_path(&ctx, path, strukt.into()); let ty = self.db.ty(strukt.into()); @@ -439,7 +439,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { (ty, Some(var.into())) } Some(TypeNs::SelfType(impl_id)) => { - let generics = crate::utils::generics(self.db, impl_id.into()); + let generics = crate::utils::generics(self.db.upcast(), impl_id.into()); let substs = Substs::type_params_for_generics(&generics); let ty = self.db.impl_self_ty(impl_id).subst(&substs); let variant = ty_variant(&ty); @@ -500,13 +500,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { fn resolve_into_iter_item(&self) -> Option { let path = path![std::iter::IntoIterator]; - let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; + let trait_ = self.resolver.resolve_known_trait(self.db.upcast(), &path)?; self.db.trait_data(trait_).associated_type_by_name(&name![Item]) } fn resolve_ops_try_ok(&self) -> Option { let path = path![std::ops::Try]; - let trait_ = self.resolver.resolve_known_trait(self.db, &path)?; + let trait_ = self.resolver.resolve_known_trait(self.db.upcast(), &path)?; self.db.trait_data(trait_).associated_type_by_name(&name![Ok]) } @@ -532,37 +532,37 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { fn resolve_range_full(&self) -> Option { let path = path![std::ops::RangeFull]; - let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; + let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?; Some(struct_.into()) } fn resolve_range(&self) -> Option { let path = path![std::ops::Range]; - let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; + let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?; Some(struct_.into()) } fn resolve_range_inclusive(&self) -> Option { let path = path![std::ops::RangeInclusive]; - let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; + let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?; Some(struct_.into()) } fn resolve_range_from(&self) -> Option { let path = path![std::ops::RangeFrom]; - let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; + let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?; Some(struct_.into()) } fn resolve_range_to(&self) -> Option { let path = path![std::ops::RangeTo]; - let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; + let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?; Some(struct_.into()) } fn resolve_range_to_inclusive(&self) -> Option { let path = path![std::ops::RangeToInclusive]; - let struct_ = self.resolver.resolve_known_struct(self.db, &path)?; + let struct_ = self.resolver.resolve_known_struct(self.db.upcast(), &path)?; Some(struct_.into()) } @@ -676,13 +676,13 @@ mod diagnostics { impl InferenceDiagnostic { pub(super) fn add_to( &self, - db: &impl HirDatabase, + db: &dyn HirDatabase, owner: FunctionId, sink: &mut DiagnosticSink, ) { match self { InferenceDiagnostic::NoSuchField { expr, field } => { - let file = owner.lookup(db).source(db).file_id; + let file = owner.lookup(db.upcast()).source(db.upcast()).file_id; let (_, source_map) = db.body_with_source_map(owner.into()); let field = source_map.field_syntax(*expr, *field); sink.push(NoSuchField { file, field }) diff --git a/crates/ra_hir_ty/src/infer/coerce.rs b/crates/ra_hir_ty/src/infer/coerce.rs index 95ac3c713..959b1e212 100644 --- a/crates/ra_hir_ty/src/infer/coerce.rs +++ b/crates/ra_hir_ty/src/infer/coerce.rs @@ -7,13 +7,11 @@ use hir_def::{lang_item::LangItemTarget, type_ref::Mutability}; use test_utils::tested_by; -use crate::{ - autoderef, db::HirDatabase, traits::Solution, Obligation, Substs, TraitRef, Ty, TypeCtor, -}; +use crate::{autoderef, traits::Solution, Obligation, Substs, TraitRef, Ty, TypeCtor}; use super::{unify::TypeVarValue, InEnvironment, InferTy, InferenceContext}; -impl<'a, D: HirDatabase> InferenceContext<'a, D> { +impl<'a> InferenceContext<'a> { /// Unify two types, but may coerce the first one to the second one /// using "implicit coercion rules" if needed. pub(super) fn coerce(&mut self, from_ty: &Ty, to_ty: &Ty) -> bool { @@ -126,7 +124,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { _ => return None, }; - let generic_params = crate::utils::generics(self.db, coerce_unsized_trait.into()); + let generic_params = crate::utils::generics(self.db.upcast(), coerce_unsized_trait.into()); if generic_params.len() != 2 { // The CoerceUnsized trait should have two generic params: Self and T. return None; diff --git a/crates/ra_hir_ty/src/infer/expr.rs b/crates/ra_hir_ty/src/infer/expr.rs index e89cc7298..1fdb235a0 100644 --- a/crates/ra_hir_ty/src/infer/expr.rs +++ b/crates/ra_hir_ty/src/infer/expr.rs @@ -14,9 +14,7 @@ use hir_expand::name::Name; use ra_syntax::ast::RangeOp; use crate::{ - autoderef, - db::HirDatabase, - method_resolution, op, + autoderef, method_resolution, op, traits::InEnvironment, utils::{generics, variant_data, Generics}, ApplicationTy, Binders, CallableDef, InferTy, IntTy, Mutability, Obligation, Substs, TraitRef, @@ -25,7 +23,7 @@ use crate::{ use super::{BindingMode, Expectation, InferenceContext, InferenceDiagnostic, TypeMismatch}; -impl<'a, D: HirDatabase> InferenceContext<'a, D> { +impl<'a> InferenceContext<'a> { pub(super) fn infer_expr(&mut self, tgt_expr: ExprId, expected: &Expectation) -> Ty { let ty = self.infer_expr_inner(tgt_expr, expected); let could_unify = self.unify(&ty, &expected.ty); @@ -184,7 +182,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } Expr::Path(p) => { // FIXME this could be more efficient... - let resolver = resolver_for_expr(self.db, self.owner, tgt_expr); + let resolver = resolver_for_expr(self.db.upcast(), self.owner, tgt_expr); self.infer_path(&resolver, p, tgt_expr.into()).unwrap_or(Ty::Unknown) } Expr::Continue => Ty::simple(TypeCtor::Never), @@ -214,7 +212,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let substs = ty.substs().unwrap_or_else(Substs::empty); let field_types = def_id.map(|it| self.db.field_types(it)).unwrap_or_default(); - let variant_data = def_id.map(|it| variant_data(self.db, it)); + let variant_data = def_id.map(|it| variant_data(self.db.upcast(), it)); for (field_idx, field) in fields.iter().enumerate() { let field_def = variant_data.as_ref().and_then(|it| match it.field(&field.name) { @@ -579,7 +577,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let receiver_ty = self.infer_expr(receiver, &Expectation::none()); let canonicalized_receiver = self.canonicalizer().canonicalize_ty(receiver_ty.clone()); - let traits_in_scope = self.resolver.traits_in_scope(self.db); + let traits_in_scope = self.resolver.traits_in_scope(self.db.upcast()); let resolved = self.resolver.krate().and_then(|krate| { method_resolution::lookup_method( @@ -595,7 +593,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { Some((ty, func)) => { let ty = canonicalized_receiver.decanonicalize_ty(ty); self.write_method_resolution(tgt_expr, func); - (ty, self.db.value_ty(func.into()), Some(generics(self.db, func.into()))) + (ty, self.db.value_ty(func.into()), Some(generics(self.db.upcast(), func.into()))) } None => (receiver_ty, Binders::new(0, Ty::Unknown), None), }; @@ -703,10 +701,13 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { // add obligation for trait implementation, if this is a trait method match def { CallableDef::FunctionId(f) => { - if let AssocContainerId::TraitId(trait_) = f.lookup(self.db).container { + if let AssocContainerId::TraitId(trait_) = + f.lookup(self.db.upcast()).container + { // construct a TraitDef - let substs = - a_ty.parameters.prefix(generics(self.db, trait_.into()).len()); + let substs = a_ty + .parameters + .prefix(generics(self.db.upcast(), trait_.into()).len()); self.obligations.push(Obligation::Trait(TraitRef { trait_, substs })); } } diff --git a/crates/ra_hir_ty/src/infer/pat.rs b/crates/ra_hir_ty/src/infer/pat.rs index 7a84e47f8..baed6225b 100644 --- a/crates/ra_hir_ty/src/infer/pat.rs +++ b/crates/ra_hir_ty/src/infer/pat.rs @@ -12,9 +12,9 @@ use hir_expand::name::Name; use test_utils::tested_by; use super::{BindingMode, InferenceContext}; -use crate::{db::HirDatabase, utils::variant_data, Substs, Ty, TypeCtor}; +use crate::{utils::variant_data, Substs, Ty, TypeCtor}; -impl<'a, D: HirDatabase> InferenceContext<'a, D> { +impl<'a> InferenceContext<'a> { fn infer_tuple_struct_pat( &mut self, path: Option<&Path>, @@ -23,7 +23,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { default_bm: BindingMode, ) -> Ty { let (ty, def) = self.resolve_variant(path); - let var_data = def.map(|it| variant_data(self.db, it)); + let var_data = def.map(|it| variant_data(self.db.upcast(), it)); self.unify(&ty, expected); let substs = ty.substs().unwrap_or_else(Substs::empty); @@ -51,7 +51,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { id: PatId, ) -> Ty { let (ty, def) = self.resolve_variant(path); - let var_data = def.map(|it| variant_data(self.db, it)); + let var_data = def.map(|it| variant_data(self.db.upcast(), it)); if let Some(variant) = def { self.write_variant_resolution(id.into(), variant); } diff --git a/crates/ra_hir_ty/src/infer/path.rs b/crates/ra_hir_ty/src/infer/path.rs index c733b9e1d..318652c61 100644 --- a/crates/ra_hir_ty/src/infer/path.rs +++ b/crates/ra_hir_ty/src/infer/path.rs @@ -9,11 +9,11 @@ use hir_def::{ }; use hir_expand::name::Name; -use crate::{db::HirDatabase, method_resolution, Substs, Ty, ValueTyDefId}; +use crate::{method_resolution, Substs, Ty, ValueTyDefId}; use super::{ExprOrPatId, InferenceContext, TraitRef}; -impl<'a, D: HirDatabase> InferenceContext<'a, D> { +impl<'a> InferenceContext<'a> { pub(super) fn infer_path( &mut self, resolver: &Resolver, @@ -47,7 +47,8 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { id, )? } else { - let value_or_partial = resolver.resolve_path_in_value_ns(self.db, path.mod_path())?; + let value_or_partial = + resolver.resolve_path_in_value_ns(self.db.upcast(), path.mod_path())?; match value_or_partial { ResolveValueResult::ValueNs(it) => (it, None), @@ -192,7 +193,7 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { let canonical_ty = self.canonicalizer().canonicalize_ty(ty.clone()); let krate = self.resolver.krate()?; - let traits_in_scope = self.resolver.traits_in_scope(self.db); + let traits_in_scope = self.resolver.traits_in_scope(self.db.upcast()); method_resolution::iterate_method_candidates( &canonical_ty.value, @@ -205,9 +206,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { move |_ty, item| { let (def, container) = match item { AssocItemId::FunctionId(f) => { - (ValueNs::FunctionId(f), f.lookup(self.db).container) + (ValueNs::FunctionId(f), f.lookup(self.db.upcast()).container) + } + AssocItemId::ConstId(c) => { + (ValueNs::ConstId(c), c.lookup(self.db.upcast()).container) } - AssocItemId::ConstId(c) => (ValueNs::ConstId(c), c.lookup(self.db).container), AssocItemId::TypeAliasId(_) => unreachable!(), }; let substs = match container { diff --git a/crates/ra_hir_ty/src/infer/unify.rs b/crates/ra_hir_ty/src/infer/unify.rs index 82b85d570..0bf8fbd63 100644 --- a/crates/ra_hir_ty/src/infer/unify.rs +++ b/crates/ra_hir_ty/src/infer/unify.rs @@ -7,10 +7,10 @@ use ena::unify::{InPlaceUnificationTable, NoError, UnifyKey, UnifyValue}; use test_utils::tested_by; use super::{InferenceContext, Obligation}; -use crate::{db::HirDatabase, Canonical, InEnvironment, InferTy, Substs, Ty, TypeCtor, TypeWalk}; +use crate::{Canonical, InEnvironment, InferTy, Substs, Ty, TypeCtor, TypeWalk}; -impl<'a, D: HirDatabase> InferenceContext<'a, D> { - pub(super) fn canonicalizer<'b>(&'b mut self) -> Canonicalizer<'a, 'b, D> +impl<'a> InferenceContext<'a> { + pub(super) fn canonicalizer<'b>(&'b mut self) -> Canonicalizer<'a, 'b> where 'a: 'b, { @@ -18,11 +18,11 @@ impl<'a, D: HirDatabase> InferenceContext<'a, D> { } } -pub(super) struct Canonicalizer<'a, 'b, D: HirDatabase> +pub(super) struct Canonicalizer<'a, 'b> where 'a: 'b, { - ctx: &'b mut InferenceContext<'a, D>, + ctx: &'b mut InferenceContext<'a>, free_vars: Vec, /// A stack of type variables that is used to detect recursive types (which /// are an error, but we need to protect against them to avoid stack @@ -35,7 +35,7 @@ pub(super) struct Canonicalized { free_vars: Vec, } -impl<'a, 'b, D: HirDatabase> Canonicalizer<'a, 'b, D> +impl<'a, 'b> Canonicalizer<'a, 'b> where 'a: 'b, { @@ -123,11 +123,7 @@ impl Canonicalized { ty } - pub fn apply_solution( - &self, - ctx: &mut InferenceContext<'_, impl HirDatabase>, - solution: Canonical>, - ) { + pub fn apply_solution(&self, ctx: &mut InferenceContext<'_>, solution: Canonical>) { // the solution may contain new variables, which we need to convert to new inference vars let new_vars = Substs((0..solution.num_vars).map(|_| ctx.table.new_type_var()).collect()); for (i, ty) in solution.value.into_iter().enumerate() { diff --git a/crates/ra_hir_ty/src/lib.rs b/crates/ra_hir_ty/src/lib.rs index 4127f1a8d..6c5469ecd 100644 --- a/crates/ra_hir_ty/src/lib.rs +++ b/crates/ra_hir_ty/src/lib.rs @@ -152,7 +152,7 @@ pub struct TypeCtorId(salsa::InternId); impl_intern_key!(TypeCtorId); impl TypeCtor { - pub fn num_ty_params(self, db: &impl HirDatabase) -> usize { + pub fn num_ty_params(self, db: &dyn HirDatabase) -> usize { match self { TypeCtor::Bool | TypeCtor::Char @@ -167,15 +167,15 @@ impl TypeCtor { | TypeCtor::Closure { .. } // 1 param representing the signature of the closure => 1, TypeCtor::Adt(adt) => { - let generic_params = generics(db, adt.into()); + let generic_params = generics(db.upcast(), adt.into()); generic_params.len() } TypeCtor::FnDef(callable) => { - let generic_params = generics(db, callable.into()); + let generic_params = generics(db.upcast(), callable.into()); generic_params.len() } TypeCtor::AssociatedType(type_alias) => { - let generic_params = generics(db, type_alias.into()); + let generic_params = generics(db.upcast(), type_alias.into()); generic_params.len() } TypeCtor::FnPtr { num_args } => num_args as usize + 1, @@ -183,7 +183,7 @@ impl TypeCtor { } } - pub fn krate(self, db: &impl HirDatabase) -> Option { + pub fn krate(self, db: &dyn HirDatabase) -> Option { match self { TypeCtor::Bool | TypeCtor::Char @@ -199,9 +199,11 @@ impl TypeCtor { | TypeCtor::Tuple { .. } => None, // Closure's krate is irrelevant for coherence I would think? TypeCtor::Closure { .. } => None, - TypeCtor::Adt(adt) => Some(adt.module(db).krate), + TypeCtor::Adt(adt) => Some(adt.module(db.upcast()).krate), TypeCtor::FnDef(callable) => Some(callable.krate(db)), - TypeCtor::AssociatedType(type_alias) => Some(type_alias.lookup(db).module(db).krate), + TypeCtor::AssociatedType(type_alias) => { + Some(type_alias.lookup(db.upcast()).module(db.upcast()).krate) + } } } @@ -246,12 +248,12 @@ pub struct ProjectionTy { } impl ProjectionTy { - pub fn trait_ref(&self, db: &impl HirDatabase) -> TraitRef { + pub fn trait_ref(&self, db: &dyn HirDatabase) -> TraitRef { TraitRef { trait_: self.trait_(db), substs: self.parameters.clone() } } - fn trait_(&self, db: &impl HirDatabase) -> TraitId { - match self.associated_ty.lookup(db).container { + fn trait_(&self, db: &dyn HirDatabase) -> TraitId { + match self.associated_ty.lookup(db.upcast()).container { AssocContainerId::TraitId(it) => it, _ => panic!("projection ty without parent trait"), } @@ -372,8 +374,8 @@ impl Substs { } /// Return Substs that replace each parameter by itself (i.e. `Ty::Param`). - pub fn type_params(db: &impl HirDatabase, def: impl Into) -> Substs { - let params = generics(db, def.into()); + pub fn type_params(db: &dyn HirDatabase, def: impl Into) -> Substs { + let params = generics(db.upcast(), def.into()); Substs::type_params_for_generics(¶ms) } @@ -382,9 +384,9 @@ impl Substs { Substs(generic_params.iter().enumerate().map(|(idx, _)| Ty::Bound(idx as u32)).collect()) } - pub fn build_for_def(db: &impl HirDatabase, def: impl Into) -> SubstsBuilder { + pub fn build_for_def(db: &dyn HirDatabase, def: impl Into) -> SubstsBuilder { let def = def.into(); - let params = generics(db, def); + let params = generics(db.upcast(), def); let param_count = params.len(); Substs::builder(param_count) } @@ -393,7 +395,7 @@ impl Substs { Substs::builder(generic_params.len()) } - pub fn build_for_type_ctor(db: &impl HirDatabase, type_ctor: TypeCtor) -> SubstsBuilder { + pub fn build_for_type_ctor(db: &dyn HirDatabase, type_ctor: TypeCtor) -> SubstsBuilder { Substs::builder(type_ctor.num_ty_params(db)) } @@ -538,7 +540,7 @@ impl GenericPredicate { } } - pub fn trait_ref(&self, db: &impl HirDatabase) -> Option { + pub fn trait_ref(&self, db: &dyn HirDatabase) -> Option { match self { GenericPredicate::Implemented(tr) => Some(tr.clone()), GenericPredicate::Projection(proj) => Some(proj.projection_ty.trait_ref(db)), @@ -693,7 +695,7 @@ impl Ty { } } - fn callable_sig(&self, db: &impl HirDatabase) -> Option { + fn callable_sig(&self, db: &dyn HirDatabase) -> Option { match self { Ty::Apply(a_ty) => match a_ty.ctor { TypeCtor::FnPtr { .. } => Some(FnSig::from_fn_ptr_substs(&a_ty.parameters)), diff --git a/crates/ra_hir_ty/src/lower.rs b/crates/ra_hir_ty/src/lower.rs index b96dc126c..d7f250783 100644 --- a/crates/ra_hir_ty/src/lower.rs +++ b/crates/ra_hir_ty/src/lower.rs @@ -34,8 +34,8 @@ use crate::{ }; #[derive(Debug)] -pub struct TyLoweringContext<'a, DB: HirDatabase> { - pub db: &'a DB, +pub struct TyLoweringContext<'a> { + pub db: &'a dyn HirDatabase, pub resolver: &'a Resolver, /// Note: Conceptually, it's thinkable that we could be in a location where /// some type params should be represented as placeholders, and others @@ -46,8 +46,8 @@ pub struct TyLoweringContext<'a, DB: HirDatabase> { pub impl_trait_counter: std::cell::Cell, } -impl<'a, DB: HirDatabase> TyLoweringContext<'a, DB> { - pub fn new(db: &'a DB, resolver: &'a Resolver) -> Self { +impl<'a> TyLoweringContext<'a> { + pub fn new(db: &'a dyn HirDatabase, resolver: &'a Resolver) -> Self { let impl_trait_counter = std::cell::Cell::new(0); let impl_trait_mode = ImplTraitLoweringMode::Disallowed; let type_param_mode = TypeParamLoweringMode::Placeholder; @@ -90,13 +90,10 @@ pub enum TypeParamLoweringMode { } impl Ty { - pub fn from_hir(ctx: &TyLoweringContext<'_, impl HirDatabase>, type_ref: &TypeRef) -> Self { + pub fn from_hir(ctx: &TyLoweringContext<'_>, type_ref: &TypeRef) -> Self { Ty::from_hir_ext(ctx, type_ref).0 } - pub fn from_hir_ext( - ctx: &TyLoweringContext<'_, impl HirDatabase>, - type_ref: &TypeRef, - ) -> (Self, Option) { + pub fn from_hir_ext(ctx: &TyLoweringContext<'_>, type_ref: &TypeRef) -> (Self, Option) { let mut res = None; let ty = match type_ref { TypeRef::Never => Ty::simple(TypeCtor::Never), @@ -157,7 +154,7 @@ impl Ty { let idx = ctx.impl_trait_counter.get(); ctx.impl_trait_counter.set(idx + 1); if let Some(def) = ctx.resolver.generic_def() { - let generics = generics(ctx.db, def); + let generics = generics(ctx.db.upcast(), def); let param = generics .iter() .filter(|(_, data)| { @@ -175,7 +172,7 @@ impl Ty { ctx.impl_trait_counter.set(idx + 1); let (parent_params, self_params, list_params, _impl_trait_params) = if let Some(def) = ctx.resolver.generic_def() { - let generics = generics(ctx.db, def); + let generics = generics(ctx.db.upcast(), def); generics.provenance_split() } else { (0, 0, 0, 0) @@ -201,10 +198,7 @@ impl Ty { /// This is only for `generic_predicates_for_param`, where we can't just /// lower the self types of the predicates since that could lead to cycles. /// So we just check here if the `type_ref` resolves to a generic param, and which. - fn from_hir_only_param( - ctx: &TyLoweringContext<'_, impl HirDatabase>, - type_ref: &TypeRef, - ) -> Option { + fn from_hir_only_param(ctx: &TyLoweringContext<'_>, type_ref: &TypeRef) -> Option { let path = match type_ref { TypeRef::Path(path) => path, _ => return None, @@ -215,10 +209,11 @@ impl Ty { if path.segments().len() > 1 { return None; } - let resolution = match ctx.resolver.resolve_path_in_type_ns(ctx.db, path.mod_path()) { - Some((it, None)) => it, - _ => return None, - }; + let resolution = + match ctx.resolver.resolve_path_in_type_ns(ctx.db.upcast(), path.mod_path()) { + Some((it, None)) => it, + _ => return None, + }; if let TypeNs::GenericParam(param_id) = resolution { Some(param_id) } else { @@ -227,7 +222,7 @@ impl Ty { } pub(crate) fn from_type_relative_path( - ctx: &TyLoweringContext<'_, impl HirDatabase>, + ctx: &TyLoweringContext<'_>, ty: Ty, // We need the original resolution to lower `Self::AssocTy` correctly res: Option, @@ -246,7 +241,7 @@ impl Ty { } pub(crate) fn from_partly_resolved_hir_path( - ctx: &TyLoweringContext<'_, impl HirDatabase>, + ctx: &TyLoweringContext<'_>, resolution: TypeNs, resolved_segment: PathSegment<'_>, remaining_segments: PathSegments<'_>, @@ -260,7 +255,7 @@ impl Ty { let ty = if remaining_segments.len() == 1 { let segment = remaining_segments.first().unwrap(); let associated_ty = associated_type_by_name_including_super_traits( - ctx.db, + ctx.db.upcast(), trait_ref.trait_, &segment.name, ); @@ -286,8 +281,10 @@ impl Ty { return (ty, None); } TypeNs::GenericParam(param_id) => { - let generics = - generics(ctx.db, ctx.resolver.generic_def().expect("generics in scope")); + let generics = generics( + ctx.db.upcast(), + ctx.resolver.generic_def().expect("generics in scope"), + ); match ctx.type_param_mode { TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), TypeParamLoweringMode::Variable => { @@ -297,7 +294,7 @@ impl Ty { } } TypeNs::SelfType(impl_id) => { - let generics = generics(ctx.db, impl_id.into()); + let generics = generics(ctx.db.upcast(), impl_id.into()); let substs = match ctx.type_param_mode { TypeParamLoweringMode::Placeholder => { Substs::type_params_for_generics(&generics) @@ -307,7 +304,7 @@ impl Ty { ctx.db.impl_self_ty(impl_id).subst(&substs) } TypeNs::AdtSelfType(adt) => { - let generics = generics(ctx.db, adt.into()); + let generics = generics(ctx.db.upcast(), adt.into()); let substs = match ctx.type_param_mode { TypeParamLoweringMode::Placeholder => { Substs::type_params_for_generics(&generics) @@ -327,17 +324,14 @@ impl Ty { Ty::from_type_relative_path(ctx, ty, Some(resolution), remaining_segments) } - pub(crate) fn from_hir_path( - ctx: &TyLoweringContext<'_, impl HirDatabase>, - path: &Path, - ) -> (Ty, Option) { + pub(crate) fn from_hir_path(ctx: &TyLoweringContext<'_>, path: &Path) -> (Ty, Option) { // Resolve the path (in type namespace) if let Some(type_ref) = path.type_anchor() { let (ty, res) = Ty::from_hir_ext(ctx, &type_ref); return Ty::from_type_relative_path(ctx, ty, res, path.segments()); } let (resolution, remaining_index) = - match ctx.resolver.resolve_path_in_type_ns(ctx.db, path.mod_path()) { + match ctx.resolver.resolve_path_in_type_ns(ctx.db.upcast(), path.mod_path()) { Some(it) => it, None => return (Ty::Unknown, None), }; @@ -352,7 +346,7 @@ impl Ty { } fn select_associated_type( - ctx: &TyLoweringContext<'_, impl HirDatabase>, + ctx: &TyLoweringContext<'_>, self_ty: Ty, res: Option, segment: PathSegment<'_>, @@ -374,7 +368,7 @@ impl Ty { } _ => return Ty::Unknown, }; - let traits = traits_from_env.into_iter().flat_map(|t| all_super_traits(ctx.db, t)); + let traits = traits_from_env.into_iter().flat_map(|t| all_super_traits(ctx.db.upcast(), t)); for t in traits { if let Some(associated_ty) = ctx.db.trait_data(t).associated_type_by_name(&segment.name) { @@ -388,7 +382,7 @@ impl Ty { } fn from_hir_path_inner( - ctx: &TyLoweringContext<'_, impl HirDatabase>, + ctx: &TyLoweringContext<'_>, segment: PathSegment<'_>, typable: TyDefId, ) -> Ty { @@ -404,7 +398,7 @@ impl Ty { /// Collect generic arguments from a path into a `Substs`. See also /// `create_substs_for_ast_path` and `def_to_ty` in rustc. pub(super) fn substs_from_path( - ctx: &TyLoweringContext<'_, impl HirDatabase>, + ctx: &TyLoweringContext<'_>, path: &Path, // Note that we don't call `db.value_type(resolved)` here, // `ValueTyDefId` is just a convenient way to pass generics and @@ -437,13 +431,13 @@ impl Ty { } pub(super) fn substs_from_path_segment( - ctx: &TyLoweringContext<'_, impl HirDatabase>, + ctx: &TyLoweringContext<'_>, segment: PathSegment<'_>, def_generic: Option, _add_self_param: bool, ) -> Substs { let mut substs = Vec::new(); - let def_generics = def_generic.map(|def| generics(ctx.db, def)); + let def_generics = def_generic.map(|def| generics(ctx.db.upcast(), def)); let (parent_params, self_params, type_params, impl_trait_params) = def_generics.map_or((0, 0, 0, 0), |g| g.provenance_split()); @@ -489,20 +483,21 @@ pub(super) fn substs_from_path_segment( impl TraitRef { fn from_path( - ctx: &TyLoweringContext<'_, impl HirDatabase>, + ctx: &TyLoweringContext<'_>, path: &Path, explicit_self_ty: Option, ) -> Option { - let resolved = match ctx.resolver.resolve_path_in_type_ns_fully(ctx.db, path.mod_path())? { - TypeNs::TraitId(tr) => tr, - _ => return None, - }; + let resolved = + match ctx.resolver.resolve_path_in_type_ns_fully(ctx.db.upcast(), path.mod_path())? { + TypeNs::TraitId(tr) => tr, + _ => return None, + }; let segment = path.segments().last().expect("path should have at least one segment"); Some(TraitRef::from_resolved_path(ctx, resolved, segment, explicit_self_ty)) } pub(crate) fn from_resolved_path( - ctx: &TyLoweringContext<'_, impl HirDatabase>, + ctx: &TyLoweringContext<'_>, resolved: TraitId, segment: PathSegment<'_>, explicit_self_ty: Option, @@ -515,7 +510,7 @@ impl TraitRef { } fn from_hir( - ctx: &TyLoweringContext<'_, impl HirDatabase>, + ctx: &TyLoweringContext<'_>, type_ref: &TypeRef, explicit_self_ty: Option, ) -> Option { @@ -527,7 +522,7 @@ impl TraitRef { } fn substs_from_path( - ctx: &TyLoweringContext<'_, impl HirDatabase>, + ctx: &TyLoweringContext<'_>, segment: PathSegment<'_>, resolved: TraitId, ) -> Substs { @@ -537,7 +532,7 @@ impl TraitRef { } pub(crate) fn from_type_bound( - ctx: &TyLoweringContext<'_, impl HirDatabase>, + ctx: &TyLoweringContext<'_>, bound: &TypeBound, self_ty: Ty, ) -> Option { @@ -550,14 +545,14 @@ impl TraitRef { impl GenericPredicate { pub(crate) fn from_where_predicate<'a>( - ctx: &'a TyLoweringContext<'a, impl HirDatabase>, + ctx: &'a TyLoweringContext<'a>, where_predicate: &'a WherePredicate, ) -> impl Iterator + 'a { let self_ty = match &where_predicate.target { WherePredicateTarget::TypeRef(type_ref) => Ty::from_hir(ctx, type_ref), WherePredicateTarget::TypeParam(param_id) => { let generic_def = ctx.resolver.generic_def().expect("generics in scope"); - let generics = generics(ctx.db, generic_def); + let generics = generics(ctx.db.upcast(), generic_def); let param_id = hir_def::TypeParamId { parent: generic_def, local_id: *param_id }; match ctx.type_param_mode { TypeParamLoweringMode::Placeholder => Ty::Placeholder(param_id), @@ -572,7 +567,7 @@ impl GenericPredicate { } pub(crate) fn from_type_bound<'a>( - ctx: &'a TyLoweringContext<'a, impl HirDatabase>, + ctx: &'a TyLoweringContext<'a>, bound: &'a TypeBound, self_ty: Ty, ) -> impl Iterator + 'a { @@ -587,7 +582,7 @@ impl GenericPredicate { } fn assoc_type_bindings_from_type_bound<'a>( - ctx: &'a TyLoweringContext<'a, impl HirDatabase>, + ctx: &'a TyLoweringContext<'a>, bound: &'a TypeBound, trait_ref: TraitRef, ) -> impl Iterator + 'a { @@ -600,8 +595,11 @@ fn assoc_type_bindings_from_type_bound<'a>( .flat_map(|segment| segment.args_and_bindings.into_iter()) .flat_map(|args_and_bindings| args_and_bindings.bindings.iter()) .map(move |(name, type_ref)| { - let associated_ty = - associated_type_by_name_including_super_traits(ctx.db, trait_ref.trait_, &name); + let associated_ty = associated_type_by_name_including_super_traits( + ctx.db.upcast(), + trait_ref.trait_, + &name, + ); let associated_ty = match associated_ty { None => return GenericPredicate::Error, Some(t) => t, @@ -615,7 +613,7 @@ fn assoc_type_bindings_from_type_bound<'a>( } /// Build the signature of a callable item (function, struct or enum variant). -pub fn callable_item_sig(db: &impl HirDatabase, def: CallableDef) -> PolyFnSig { +pub fn callable_item_sig(db: &dyn HirDatabase, def: CallableDef) -> PolyFnSig { match def { CallableDef::FunctionId(f) => fn_sig_for_fn(db, f), CallableDef::StructId(s) => fn_sig_for_struct_constructor(db, s), @@ -625,16 +623,16 @@ pub fn callable_item_sig(db: &impl HirDatabase, def: CallableDef) -> PolyFnSig { /// Build the type of all specific fields of a struct or enum variant. pub(crate) fn field_types_query( - db: &impl HirDatabase, + db: &dyn HirDatabase, variant_id: VariantId, ) -> Arc>> { - let var_data = variant_data(db, variant_id); + let var_data = variant_data(db.upcast(), variant_id); let (resolver, def): (_, GenericDefId) = match variant_id { - VariantId::StructId(it) => (it.resolver(db), it.into()), - VariantId::UnionId(it) => (it.resolver(db), it.into()), - VariantId::EnumVariantId(it) => (it.parent.resolver(db), it.parent.into()), + VariantId::StructId(it) => (it.resolver(db.upcast()), it.into()), + VariantId::UnionId(it) => (it.resolver(db.upcast()), it.into()), + VariantId::EnumVariantId(it) => (it.parent.resolver(db.upcast()), it.parent.into()), }; - let generics = generics(db, def); + let generics = generics(db.upcast(), def); let mut res = ArenaMap::default(); let ctx = TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); @@ -653,13 +651,13 @@ pub(crate) fn field_types_query( /// following bounds are disallowed: `T: Foo, U: Foo`, but /// these are fine: `T: Foo, U: Foo<()>`. pub(crate) fn generic_predicates_for_param_query( - db: &impl HirDatabase, + db: &dyn HirDatabase, param_id: TypeParamId, ) -> Arc<[Binders]> { - let resolver = param_id.parent.resolver(db); + let resolver = param_id.parent.resolver(db.upcast()); let ctx = TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); - let generics = generics(db, param_id.parent); + let generics = generics(db.upcast(), param_id.parent); resolver .where_predicates_in_scope() // we have to filter out all other predicates *first*, before attempting to lower them @@ -677,7 +675,7 @@ pub(crate) fn generic_predicates_for_param_query( } pub(crate) fn generic_predicates_for_param_recover( - _db: &impl HirDatabase, + _db: &dyn HirDatabase, _cycle: &[String], _param_id: &TypeParamId, ) -> Arc<[Binders]> { @@ -685,7 +683,7 @@ pub(crate) fn generic_predicates_for_param_recover( } impl TraitEnvironment { - pub fn lower(db: &impl HirDatabase, resolver: &Resolver) -> Arc { + pub fn lower(db: &dyn HirDatabase, resolver: &Resolver) -> Arc { let ctx = TyLoweringContext::new(db, &resolver) .with_type_param_mode(TypeParamLoweringMode::Placeholder); let mut predicates = resolver @@ -696,13 +694,13 @@ impl TraitEnvironment { if let Some(def) = resolver.generic_def() { let container: Option = match def { // FIXME: is there a function for this? - GenericDefId::FunctionId(f) => Some(f.lookup(db).container), + GenericDefId::FunctionId(f) => Some(f.lookup(db.upcast()).container), GenericDefId::AdtId(_) => None, GenericDefId::TraitId(_) => None, - GenericDefId::TypeAliasId(t) => Some(t.lookup(db).container), + GenericDefId::TypeAliasId(t) => Some(t.lookup(db.upcast()).container), GenericDefId::ImplId(_) => None, GenericDefId::EnumVariantId(_) => None, - GenericDefId::ConstId(c) => Some(c.lookup(db).container), + GenericDefId::ConstId(c) => Some(c.lookup(db.upcast()).container), }; if let Some(AssocContainerId::TraitId(trait_id)) = container { // add `Self: Trait` to the environment in trait @@ -723,13 +721,13 @@ impl TraitEnvironment { /// Resolve the where clause(s) of an item with generics. pub(crate) fn generic_predicates_query( - db: &impl HirDatabase, + db: &dyn HirDatabase, def: GenericDefId, ) -> Arc<[Binders]> { - let resolver = def.resolver(db); + let resolver = def.resolver(db.upcast()); let ctx = TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); - let generics = generics(db, def); + let generics = generics(db.upcast(), def); resolver .where_predicates_in_scope() .flat_map(|pred| { @@ -740,10 +738,10 @@ pub(crate) fn generic_predicates_query( } /// Resolve the default type params from generics -pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) -> Substs { - let resolver = def.resolver(db); +pub(crate) fn generic_defaults_query(db: &dyn HirDatabase, def: GenericDefId) -> Substs { + let resolver = def.resolver(db.upcast()); let ctx = TyLoweringContext::new(db, &resolver); - let generic_params = generics(db, def); + let generic_params = generics(db.upcast(), def); let defaults = generic_params .iter() @@ -753,33 +751,33 @@ pub(crate) fn generic_defaults_query(db: &impl HirDatabase, def: GenericDefId) - Substs(defaults) } -fn fn_sig_for_fn(db: &impl HirDatabase, def: FunctionId) -> PolyFnSig { +fn fn_sig_for_fn(db: &dyn HirDatabase, def: FunctionId) -> PolyFnSig { let data = db.function_data(def); - let resolver = def.resolver(db); + let resolver = def.resolver(db.upcast()); let ctx_params = TyLoweringContext::new(db, &resolver) .with_impl_trait_mode(ImplTraitLoweringMode::Variable) .with_type_param_mode(TypeParamLoweringMode::Variable); let params = data.params.iter().map(|tr| Ty::from_hir(&ctx_params, tr)).collect::>(); let ctx_ret = ctx_params.with_impl_trait_mode(ImplTraitLoweringMode::Opaque); let ret = Ty::from_hir(&ctx_ret, &data.ret_type); - let generics = generics(db, def.into()); + let generics = generics(db.upcast(), def.into()); let num_binders = generics.len(); Binders::new(num_binders, FnSig::from_params_and_return(params, ret)) } /// Build the declared type of a function. This should not need to look at the /// function body. -fn type_for_fn(db: &impl HirDatabase, def: FunctionId) -> Binders { - let generics = generics(db, def.into()); +fn type_for_fn(db: &dyn HirDatabase, def: FunctionId) -> Binders { + let generics = generics(db.upcast(), def.into()); let substs = Substs::bound_vars(&generics); Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs)) } /// Build the declared type of a const. -fn type_for_const(db: &impl HirDatabase, def: ConstId) -> Binders { +fn type_for_const(db: &dyn HirDatabase, def: ConstId) -> Binders { let data = db.const_data(def); - let generics = generics(db, def.into()); - let resolver = def.resolver(db); + let generics = generics(db.upcast(), def.into()); + let resolver = def.resolver(db.upcast()); let ctx = TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); @@ -787,9 +785,9 @@ fn type_for_const(db: &impl HirDatabase, def: ConstId) -> Binders { } /// Build the declared type of a static. -fn type_for_static(db: &impl HirDatabase, def: StaticId) -> Binders { +fn type_for_static(db: &dyn HirDatabase, def: StaticId) -> Binders { let data = db.static_data(def); - let resolver = def.resolver(db); + let resolver = def.resolver(db.upcast()); let ctx = TyLoweringContext::new(db, &resolver); Binders::new(0, Ty::from_hir(&ctx, &data.type_ref)) @@ -806,10 +804,10 @@ fn type_for_builtin(def: BuiltinType) -> Ty { }) } -fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFnSig { +fn fn_sig_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> PolyFnSig { let struct_data = db.struct_data(def); let fields = struct_data.variant_data.fields(); - let resolver = def.resolver(db); + let resolver = def.resolver(db.upcast()); let ctx = TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); let params = @@ -819,21 +817,21 @@ fn fn_sig_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> PolyFn } /// Build the type of a tuple struct constructor. -fn type_for_struct_constructor(db: &impl HirDatabase, def: StructId) -> Binders { +fn type_for_struct_constructor(db: &dyn HirDatabase, def: StructId) -> Binders { let struct_data = db.struct_data(def); if let StructKind::Unit = struct_data.variant_data.kind() { return type_for_adt(db, def.into()); } - let generics = generics(db, def.into()); + let generics = generics(db.upcast(), def.into()); let substs = Substs::bound_vars(&generics); Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs)) } -fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) -> PolyFnSig { +fn fn_sig_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -> PolyFnSig { let enum_data = db.enum_data(def.parent); let var_data = &enum_data.variants[def.local_id]; let fields = var_data.variant_data.fields(); - let resolver = def.parent.resolver(db); + let resolver = def.parent.resolver(db.upcast()); let ctx = TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); let params = @@ -843,26 +841,26 @@ fn fn_sig_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId } /// Build the type of a tuple enum variant constructor. -fn type_for_enum_variant_constructor(db: &impl HirDatabase, def: EnumVariantId) -> Binders { +fn type_for_enum_variant_constructor(db: &dyn HirDatabase, def: EnumVariantId) -> Binders { let enum_data = db.enum_data(def.parent); let var_data = &enum_data.variants[def.local_id].variant_data; if let StructKind::Unit = var_data.kind() { return type_for_adt(db, def.parent.into()); } - let generics = generics(db, def.parent.into()); + let generics = generics(db.upcast(), def.parent.into()); let substs = Substs::bound_vars(&generics); Binders::new(substs.len(), Ty::apply(TypeCtor::FnDef(def.into()), substs)) } -fn type_for_adt(db: &impl HirDatabase, adt: AdtId) -> Binders { - let generics = generics(db, adt.into()); +fn type_for_adt(db: &dyn HirDatabase, adt: AdtId) -> Binders { + let generics = generics(db.upcast(), adt.into()); let substs = Substs::bound_vars(&generics); Binders::new(substs.len(), Ty::apply(TypeCtor::Adt(adt), substs)) } -fn type_for_type_alias(db: &impl HirDatabase, t: TypeAliasId) -> Binders { - let generics = generics(db, t.into()); - let resolver = t.resolver(db); +fn type_for_type_alias(db: &dyn HirDatabase, t: TypeAliasId) -> Binders { + let generics = generics(db.upcast(), t.into()); + let resolver = t.resolver(db.upcast()); let ctx = TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); let type_ref = &db.type_alias_data(t).type_ref; @@ -880,7 +878,8 @@ pub enum CallableDef { impl_froms!(CallableDef: FunctionId, StructId, EnumVariantId); impl CallableDef { - pub fn krate(self, db: &impl HirDatabase) -> CrateId { + pub fn krate(self, db: &dyn HirDatabase) -> CrateId { + let db = db.upcast(); match self { CallableDef::FunctionId(f) => f.lookup(db).module(db), CallableDef::StructId(s) => s.lookup(db).container.module(db), @@ -922,7 +921,7 @@ impl_froms!(ValueTyDefId: FunctionId, StructId, EnumVariantId, ConstId, StaticId /// `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: &impl HirDatabase, def: TyDefId) -> Binders { +pub(crate) fn ty_query(db: &dyn HirDatabase, def: TyDefId) -> Binders { match def { TyDefId::BuiltinType(it) => Binders::new(0, type_for_builtin(it)), TyDefId::AdtId(it) => type_for_adt(db, it), @@ -930,16 +929,16 @@ pub(crate) fn ty_query(db: &impl HirDatabase, def: TyDefId) -> Binders { } } -pub(crate) fn ty_recover(db: &impl HirDatabase, _cycle: &[String], def: &TyDefId) -> Binders { +pub(crate) fn ty_recover(db: &dyn HirDatabase, _cycle: &[String], def: &TyDefId) -> Binders { let num_binders = match *def { TyDefId::BuiltinType(_) => 0, - TyDefId::AdtId(it) => generics(db, it.into()).len(), - TyDefId::TypeAliasId(it) => generics(db, it.into()).len(), + TyDefId::AdtId(it) => generics(db.upcast(), it.into()).len(), + TyDefId::TypeAliasId(it) => generics(db.upcast(), it.into()).len(), }; Binders::new(num_binders, Ty::Unknown) } -pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Binders { +pub(crate) fn value_ty_query(db: &dyn HirDatabase, def: ValueTyDefId) -> Binders { match def { ValueTyDefId::FunctionId(it) => type_for_fn(db, it), ValueTyDefId::StructId(it) => type_for_struct_constructor(db, it), @@ -949,30 +948,27 @@ pub(crate) fn value_ty_query(db: &impl HirDatabase, def: ValueTyDefId) -> Binder } } -pub(crate) fn impl_self_ty_query(db: &impl HirDatabase, impl_id: ImplId) -> Binders { +pub(crate) fn impl_self_ty_query(db: &dyn HirDatabase, impl_id: ImplId) -> Binders { let impl_data = db.impl_data(impl_id); - let resolver = impl_id.resolver(db); - let generics = generics(db, impl_id.into()); + let resolver = impl_id.resolver(db.upcast()); + let generics = generics(db.upcast(), impl_id.into()); let ctx = TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); Binders::new(generics.len(), Ty::from_hir(&ctx, &impl_data.target_type)) } pub(crate) fn impl_self_ty_recover( - db: &impl HirDatabase, + db: &dyn HirDatabase, _cycle: &[String], impl_id: &ImplId, ) -> Binders { - let generics = generics(db, (*impl_id).into()); + let generics = generics(db.upcast(), (*impl_id).into()); Binders::new(generics.len(), Ty::Unknown) } -pub(crate) fn impl_trait_query( - db: &impl HirDatabase, - impl_id: ImplId, -) -> Option> { +pub(crate) fn impl_trait_query(db: &dyn HirDatabase, impl_id: ImplId) -> Option> { let impl_data = db.impl_data(impl_id); - let resolver = impl_id.resolver(db); + let resolver = impl_id.resolver(db.upcast()); let ctx = TyLoweringContext::new(db, &resolver).with_type_param_mode(TypeParamLoweringMode::Variable); let self_ty = db.impl_self_ty(impl_id); diff --git a/crates/ra_hir_ty/src/method_resolution.rs b/crates/ra_hir_ty/src/method_resolution.rs index 7f5e1469e..69c059ac8 100644 --- a/crates/ra_hir_ty/src/method_resolution.rs +++ b/crates/ra_hir_ty/src/method_resolution.rs @@ -48,10 +48,7 @@ pub struct CrateImplDefs { } impl CrateImplDefs { - pub(crate) fn impls_in_crate_query( - db: &impl HirDatabase, - krate: CrateId, - ) -> Arc { + pub(crate) fn impls_in_crate_query(db: &dyn HirDatabase, krate: CrateId) -> Arc { let _p = profile("impls_in_crate_query"); let mut res = CrateImplDefs { impls: FxHashMap::default(), impls_by_trait: FxHashMap::default() }; @@ -92,7 +89,7 @@ impl CrateImplDefs { impl Ty { pub fn def_crates( &self, - db: &impl HirDatabase, + db: &dyn HirDatabase, cur_crate: CrateId, ) -> Option> { // Types like slice can have inherent impls in several crates, (core and alloc). @@ -110,7 +107,7 @@ impl Ty { let lang_item_targets = match self { Ty::Apply(a_ty) => match a_ty.ctor { TypeCtor::Adt(def_id) => { - return Some(std::iter::once(def_id.module(db).krate).collect()) + return Some(std::iter::once(def_id.module(db.upcast()).krate).collect()) } TypeCtor::Bool => lang_item_crate!("bool"), TypeCtor::Char => lang_item_crate!("char"), @@ -134,7 +131,7 @@ impl Ty { LangItemTarget::ImplDefId(it) => Some(it), _ => None, }) - .map(|it| it.lookup(db).container.module(db).krate) + .map(|it| it.lookup(db.upcast()).container.module(db.upcast()).krate) .collect(); Some(res) } @@ -143,7 +140,7 @@ impl Ty { /// receiver type (but without autoref applied yet). pub(crate) fn lookup_method( ty: &Canonical, - db: &impl HirDatabase, + db: &dyn HirDatabase, env: Arc, krate: CrateId, traits_in_scope: &FxHashSet, @@ -181,7 +178,7 @@ pub enum LookupMode { // FIXME add a context type here? pub fn iterate_method_candidates( ty: &Canonical, - db: &impl HirDatabase, + db: &dyn HirDatabase, env: Arc, krate: CrateId, traits_in_scope: &FxHashSet, @@ -247,7 +244,7 @@ pub fn iterate_method_candidates( fn iterate_method_candidates_with_autoref( deref_chain: &[Canonical], - db: &impl HirDatabase, + db: &dyn HirDatabase, env: Arc, krate: CrateId, traits_in_scope: &FxHashSet, @@ -304,7 +301,7 @@ fn iterate_method_candidates_with_autoref( fn iterate_method_candidates_by_receiver( receiver_ty: &Canonical, rest_of_deref_chain: &[Canonical], - db: &impl HirDatabase, + db: &dyn HirDatabase, env: Arc, krate: CrateId, traits_in_scope: &FxHashSet, @@ -340,7 +337,7 @@ fn iterate_method_candidates_by_receiver( fn iterate_method_candidates_for_self_ty( self_ty: &Canonical, - db: &impl HirDatabase, + db: &dyn HirDatabase, env: Arc, krate: CrateId, traits_in_scope: &FxHashSet, @@ -367,7 +364,7 @@ fn iterate_method_candidates_for_self_ty( fn iterate_trait_method_candidates( self_ty: &Canonical, - db: &impl HirDatabase, + db: &dyn HirDatabase, env: Arc, krate: CrateId, traits_in_scope: &FxHashSet, @@ -381,7 +378,7 @@ fn iterate_trait_method_candidates( // if we have `T: Trait` in the param env, the trait doesn't need to be in scope env.trait_predicates_for_self_ty(&self_ty.value) .map(|tr| tr.trait_) - .flat_map(|t| all_super_traits(db, t)) + .flat_map(|t| all_super_traits(db.upcast(), t)) .collect() } else { Vec::new() @@ -416,7 +413,7 @@ fn iterate_trait_method_candidates( fn iterate_inherent_methods( self_ty: &Canonical, - db: &impl HirDatabase, + db: &dyn HirDatabase, name: Option<&Name>, receiver_ty: Option<&Canonical>, krate: CrateId, @@ -449,7 +446,7 @@ fn iterate_inherent_methods( /// Returns the self type for the index trait call. pub fn resolve_indexing_op( - db: &impl HirDatabase, + db: &dyn HirDatabase, ty: &Canonical, env: Arc, krate: CrateId, @@ -467,7 +464,7 @@ pub fn resolve_indexing_op( } fn is_valid_candidate( - db: &impl HirDatabase, + db: &dyn HirDatabase, name: Option<&Name>, receiver_ty: Option<&Canonical>, item: AssocItemId, @@ -504,7 +501,7 @@ fn is_valid_candidate( } pub(crate) fn inherent_impl_substs( - db: &impl HirDatabase, + db: &dyn HirDatabase, impl_id: ImplId, self_ty: &Canonical, ) -> Option { @@ -544,11 +541,11 @@ fn fallback_bound_vars(s: Substs, num_vars_to_keep: usize) -> Substs { } fn transform_receiver_ty( - db: &impl HirDatabase, + db: &dyn HirDatabase, function_id: FunctionId, self_ty: &Canonical, ) -> Option { - let substs = match function_id.lookup(db).container { + let substs = match function_id.lookup(db.upcast()).container { AssocContainerId::TraitId(_) => Substs::build_for_def(db, function_id) .push(self_ty.value.clone()) .fill_with_unknown() @@ -562,7 +559,7 @@ fn transform_receiver_ty( pub fn implements_trait( ty: &Canonical, - db: &impl HirDatabase, + db: &dyn HirDatabase, env: Arc, krate: CrateId, trait_: TraitId, @@ -581,7 +578,7 @@ pub fn implements_trait( /// This creates Substs for a trait with the given Self type and type variables /// for all other parameters, to query Chalk with it. fn generic_implements_goal( - db: &impl HirDatabase, + db: &dyn HirDatabase, env: Arc, trait_: TraitId, self_ty: Canonical, @@ -598,7 +595,7 @@ fn generic_implements_goal( } fn autoderef_method_receiver( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, ty: InEnvironment>, ) -> Vec> { diff --git a/crates/ra_hir_ty/src/test_db.rs b/crates/ra_hir_ty/src/test_db.rs index 0be2fea4b..5bbeabf51 100644 --- a/crates/ra_hir_ty/src/test_db.rs +++ b/crates/ra_hir_ty/src/test_db.rs @@ -6,8 +6,10 @@ use std::{ }; use hir_def::{db::DefDatabase, AssocItemId, ModuleDefId, ModuleId}; -use hir_expand::diagnostics::DiagnosticSink; -use ra_db::{salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase}; +use hir_expand::{db::AstDatabase, diagnostics::DiagnosticSink}; +use ra_db::{ + salsa, CrateId, FileId, FileLoader, FileLoaderDelegate, RelativePath, SourceDatabase, Upcast, +}; use crate::{db::HirDatabase, expr::ExprValidator}; @@ -25,6 +27,18 @@ pub struct TestDB { runtime: salsa::Runtime, } +impl Upcast for TestDB { + fn upcast(&self) -> &(dyn AstDatabase + 'static) { + &*self + } +} + +impl Upcast for TestDB { + fn upcast(&self) -> &(dyn DefDatabase + 'static) { + &*self + } +} + impl salsa::Database for TestDB { fn salsa_runtime(&self) -> &salsa::Runtime { &self.runtime diff --git a/crates/ra_hir_ty/src/traits.rs b/crates/ra_hir_ty/src/traits.rs index 6e1c8e42a..a1ca33c98 100644 --- a/crates/ra_hir_ty/src/traits.rs +++ b/crates/ra_hir_ty/src/traits.rs @@ -24,8 +24,8 @@ const CHALK_SOLVER_MAX_SIZE: usize = 10; const CHALK_SOLVER_FUEL: i32 = 100; #[derive(Debug, Copy, Clone)] -struct ChalkContext<'a, DB> { - db: &'a DB, +struct ChalkContext<'a> { + db: &'a dyn HirDatabase, krate: CrateId, } @@ -37,7 +37,7 @@ fn create_chalk_solver() -> chalk_solve::Solver { /// Collects impls for the given trait in the whole dependency tree of `krate`. pub(crate) fn impls_for_trait_query( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, trait_: TraitId, ) -> Arc<[ImplId]> { @@ -136,7 +136,7 @@ impl TypeWalk for ProjectionPredicate { /// Solve a trait goal using Chalk. pub(crate) fn trait_solve_query( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, goal: Canonical>, ) -> Option { @@ -163,7 +163,7 @@ pub(crate) fn trait_solve_query( } fn solve( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, goal: &chalk_ir::UCanonical>>, ) -> Option> { @@ -188,7 +188,7 @@ fn solve( } fn solution_from_chalk( - db: &impl HirDatabase, + db: &dyn HirDatabase, solution: chalk_solve::Solution, ) -> Solution { let convert_subst = |subst: chalk_ir::Canonical>| { diff --git a/crates/ra_hir_ty/src/traits/builtin.rs b/crates/ra_hir_ty/src/traits/builtin.rs index 03f9b4e27..73e3c5c78 100644 --- a/crates/ra_hir_ty/src/traits/builtin.rs +++ b/crates/ra_hir_ty/src/traits/builtin.rs @@ -26,7 +26,7 @@ pub(super) struct BuiltinImplAssocTyValueData { } pub(super) fn get_builtin_impls( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, ty: &Ty, // The first argument for the trait, if present @@ -59,7 +59,7 @@ pub(super) fn get_builtin_impls( } fn get_builtin_unsize_impls( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, ty: &Ty, // The first argument for the trait, if present @@ -79,7 +79,7 @@ fn get_builtin_unsize_impls( // FIXME what about more complicated dyn tys with marker traits? if let Some(trait_ref) = ty.dyn_trait_ref() { if trait_ref.trait_ != target_trait.trait_ { - let super_traits = all_super_traits(db, trait_ref.trait_); + let super_traits = all_super_traits(db.upcast(), trait_ref.trait_); if super_traits.contains(&target_trait.trait_) { callback(Impl::UnsizeToSuperTraitObject(UnsizeToSuperTraitObjectData { trait_: trait_ref.trait_, @@ -94,7 +94,7 @@ fn get_builtin_unsize_impls( } } -pub(super) fn impl_datum(db: &impl HirDatabase, krate: CrateId, impl_: Impl) -> BuiltinImplData { +pub(super) fn impl_datum(db: &dyn HirDatabase, krate: CrateId, impl_: Impl) -> BuiltinImplData { match impl_ { Impl::ImplDef(_) => unreachable!(), Impl::ClosureFnTraitImpl(data) => closure_fn_trait_impl_datum(db, krate, data), @@ -107,7 +107,7 @@ pub(super) fn impl_datum(db: &impl HirDatabase, krate: CrateId, impl_: Impl) -> } pub(super) fn associated_ty_value( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, data: AssocTyValue, ) -> BuiltinImplAssocTyValueData { @@ -122,7 +122,7 @@ pub(super) fn associated_ty_value( // Closure Fn trait impls fn check_closure_fn_trait_impl_prerequisites( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, data: super::ClosureFnTraitImplData, ) -> bool { @@ -143,7 +143,7 @@ fn check_closure_fn_trait_impl_prerequisites( } fn closure_fn_trait_impl_datum( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, data: super::ClosureFnTraitImplData, ) -> BuiltinImplData { @@ -189,7 +189,7 @@ fn closure_fn_trait_impl_datum( } fn closure_fn_trait_output_assoc_ty_value( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, data: super::ClosureFnTraitImplData, ) -> BuiltinImplAssocTyValueData { @@ -223,17 +223,17 @@ fn closure_fn_trait_output_assoc_ty_value( // Array unsizing -fn check_unsize_impl_prerequisites(db: &impl HirDatabase, krate: CrateId) -> bool { +fn check_unsize_impl_prerequisites(db: &dyn HirDatabase, krate: CrateId) -> bool { // the Unsize trait needs to exist and have two type parameters (Self and T) let unsize_trait = match get_unsize_trait(db, krate) { Some(t) => t, None => return false, }; - let generic_params = generics(db, unsize_trait.into()); + let generic_params = generics(db.upcast(), unsize_trait.into()); generic_params.len() == 2 } -fn array_unsize_impl_datum(db: &impl HirDatabase, krate: CrateId) -> BuiltinImplData { +fn array_unsize_impl_datum(db: &dyn HirDatabase, krate: CrateId) -> BuiltinImplData { // impl Unsize<[T]> for [T; _] // (this can be a single impl because we don't distinguish array sizes currently) @@ -260,7 +260,7 @@ fn array_unsize_impl_datum(db: &impl HirDatabase, krate: CrateId) -> BuiltinImpl // Trait object unsizing fn trait_object_unsize_impl_datum( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, trait_: TraitId, ) -> BuiltinImplData { @@ -295,7 +295,7 @@ fn trait_object_unsize_impl_datum( } fn super_trait_object_unsize_impl_datum( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, data: UnsizeToSuperTraitObjectData, ) -> BuiltinImplData { @@ -313,7 +313,7 @@ fn super_trait_object_unsize_impl_datum( let self_bounds = vec![GenericPredicate::Implemented(self_trait_ref.clone())]; // we need to go from our trait to the super trait, substituting type parameters - let path = crate::utils::find_super_trait_path(db, data.trait_, data.super_trait); + let path = crate::utils::find_super_trait_path(db.upcast(), data.trait_, data.super_trait); let mut current_trait_ref = self_trait_ref; for t in path.into_iter().skip(1) { @@ -344,11 +344,7 @@ fn super_trait_object_unsize_impl_datum( BuiltinImplData { num_vars, trait_ref, where_clauses: Vec::new(), assoc_ty_values: Vec::new() } } -fn get_fn_trait( - db: &impl HirDatabase, - krate: CrateId, - fn_trait: super::FnTrait, -) -> Option { +fn get_fn_trait(db: &dyn HirDatabase, krate: CrateId, fn_trait: super::FnTrait) -> Option { let target = db.lang_item(krate, fn_trait.lang_item_name().into())?; match target { LangItemTarget::TraitId(t) => Some(t), @@ -356,7 +352,7 @@ fn get_fn_trait( } } -fn get_unsize_trait(db: &impl HirDatabase, krate: CrateId) -> Option { +fn get_unsize_trait(db: &dyn HirDatabase, krate: CrateId) -> Option { let target = db.lang_item(krate, "unsize".into())?; match target { LangItemTarget::TraitId(t) => Some(t), diff --git a/crates/ra_hir_ty/src/traits/chalk.rs b/crates/ra_hir_ty/src/traits/chalk.rs index 62509bc29..943d5f125 100644 --- a/crates/ra_hir_ty/src/traits/chalk.rs +++ b/crates/ra_hir_ty/src/traits/chalk.rs @@ -127,11 +127,11 @@ pub type AssociatedTyValue = chalk_rust_ir::AssociatedTyValue; pub(super) trait ToChalk { type Chalk; - fn to_chalk(self, db: &impl HirDatabase) -> Self::Chalk; - fn from_chalk(db: &impl HirDatabase, chalk: Self::Chalk) -> Self; + fn to_chalk(self, db: &dyn HirDatabase) -> Self::Chalk; + fn from_chalk(db: &dyn HirDatabase, chalk: Self::Chalk) -> Self; } -pub(super) fn from_chalk(db: &impl HirDatabase, chalk: ChalkT) -> T +pub(super) fn from_chalk(db: &dyn HirDatabase, chalk: ChalkT) -> T where T: ToChalk, { @@ -140,7 +140,7 @@ where impl ToChalk for Ty { type Chalk = chalk_ir::Ty; - fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Ty { + fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Ty { match self { Ty::Apply(apply_ty) => { let name = apply_ty.ctor.to_chalk(db); @@ -179,7 +179,7 @@ impl ToChalk for Ty { } } } - fn from_chalk(db: &impl HirDatabase, chalk: chalk_ir::Ty) -> Self { + fn from_chalk(db: &dyn HirDatabase, chalk: chalk_ir::Ty) -> Self { match chalk.data().clone() { chalk_ir::TyData::Apply(apply_ty) => match apply_ty.name { TypeName::Error => Ty::Unknown, @@ -217,11 +217,11 @@ impl ToChalk for Ty { impl ToChalk for Substs { type Chalk = chalk_ir::Substitution; - fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Substitution { + fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Substitution { chalk_ir::Substitution::from(self.iter().map(|ty| ty.clone().to_chalk(db))) } - fn from_chalk(db: &impl HirDatabase, parameters: chalk_ir::Substitution) -> Substs { + fn from_chalk(db: &dyn HirDatabase, parameters: chalk_ir::Substitution) -> Substs { let tys = parameters .into_iter() .map(|p| match p.ty() { @@ -236,13 +236,13 @@ impl ToChalk for Substs { impl ToChalk for TraitRef { type Chalk = chalk_ir::TraitRef; - fn to_chalk(self: TraitRef, db: &impl HirDatabase) -> chalk_ir::TraitRef { + fn to_chalk(self: TraitRef, db: &dyn HirDatabase) -> chalk_ir::TraitRef { let trait_id = self.trait_.to_chalk(db); let substitution = self.substs.to_chalk(db); chalk_ir::TraitRef { trait_id, substitution } } - fn from_chalk(db: &impl HirDatabase, trait_ref: chalk_ir::TraitRef) -> Self { + fn from_chalk(db: &dyn HirDatabase, trait_ref: chalk_ir::TraitRef) -> Self { let trait_ = from_chalk(db, trait_ref.trait_id); let substs = from_chalk(db, trait_ref.substitution); TraitRef { trait_, substs } @@ -252,11 +252,11 @@ impl ToChalk for TraitRef { impl ToChalk for hir_def::TraitId { type Chalk = TraitId; - fn to_chalk(self, _db: &impl HirDatabase) -> TraitId { + fn to_chalk(self, _db: &dyn HirDatabase) -> TraitId { chalk_ir::TraitId(self.as_intern_id()) } - fn from_chalk(_db: &impl HirDatabase, trait_id: TraitId) -> hir_def::TraitId { + fn from_chalk(_db: &dyn HirDatabase, trait_id: TraitId) -> hir_def::TraitId { InternKey::from_intern_id(trait_id.0) } } @@ -264,7 +264,7 @@ impl ToChalk for hir_def::TraitId { impl ToChalk for TypeCtor { type Chalk = TypeName; - fn to_chalk(self, db: &impl HirDatabase) -> TypeName { + fn to_chalk(self, db: &dyn HirDatabase) -> TypeName { match self { TypeCtor::AssociatedType(type_alias) => { let type_id = type_alias.to_chalk(db); @@ -278,7 +278,7 @@ impl ToChalk for TypeCtor { } } - fn from_chalk(db: &impl HirDatabase, type_name: TypeName) -> TypeCtor { + fn from_chalk(db: &dyn HirDatabase, type_name: TypeName) -> TypeCtor { match type_name { TypeName::Struct(struct_id) => db.lookup_intern_type_ctor(struct_id.into()), TypeName::AssociatedType(type_id) => TypeCtor::AssociatedType(from_chalk(db, type_id)), @@ -293,11 +293,11 @@ impl ToChalk for TypeCtor { impl ToChalk for Impl { type Chalk = ImplId; - fn to_chalk(self, db: &impl HirDatabase) -> ImplId { + fn to_chalk(self, db: &dyn HirDatabase) -> ImplId { db.intern_chalk_impl(self).into() } - fn from_chalk(db: &impl HirDatabase, impl_id: ImplId) -> Impl { + fn from_chalk(db: &dyn HirDatabase, impl_id: ImplId) -> Impl { db.lookup_intern_chalk_impl(impl_id.into()) } } @@ -305,11 +305,11 @@ impl ToChalk for Impl { impl ToChalk for TypeAliasId { type Chalk = AssocTypeId; - fn to_chalk(self, _db: &impl HirDatabase) -> AssocTypeId { + fn to_chalk(self, _db: &dyn HirDatabase) -> AssocTypeId { chalk_ir::AssocTypeId(self.as_intern_id()) } - fn from_chalk(_db: &impl HirDatabase, type_alias_id: AssocTypeId) -> TypeAliasId { + fn from_chalk(_db: &dyn HirDatabase, type_alias_id: AssocTypeId) -> TypeAliasId { InternKey::from_intern_id(type_alias_id.0) } } @@ -317,11 +317,11 @@ impl ToChalk for TypeAliasId { impl ToChalk for AssocTyValue { type Chalk = AssociatedTyValueId; - fn to_chalk(self, db: &impl HirDatabase) -> AssociatedTyValueId { + fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValueId { db.intern_assoc_ty_value(self).into() } - fn from_chalk(db: &impl HirDatabase, assoc_ty_value_id: AssociatedTyValueId) -> AssocTyValue { + fn from_chalk(db: &dyn HirDatabase, assoc_ty_value_id: AssociatedTyValueId) -> AssocTyValue { db.lookup_intern_assoc_ty_value(assoc_ty_value_id.into()) } } @@ -329,7 +329,7 @@ impl ToChalk for AssocTyValue { impl ToChalk for GenericPredicate { type Chalk = chalk_ir::QuantifiedWhereClause; - fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::QuantifiedWhereClause { + fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::QuantifiedWhereClause { match self { GenericPredicate::Implemented(trait_ref) => { make_binders(chalk_ir::WhereClause::Implemented(trait_ref.to_chalk(db)), 0) @@ -346,7 +346,7 @@ impl ToChalk for GenericPredicate { } fn from_chalk( - db: &impl HirDatabase, + db: &dyn HirDatabase, where_clause: chalk_ir::QuantifiedWhereClause, ) -> GenericPredicate { match where_clause.value { @@ -365,7 +365,7 @@ impl ToChalk for GenericPredicate { impl ToChalk for ProjectionTy { type Chalk = chalk_ir::AliasTy; - fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::AliasTy { + fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::AliasTy { chalk_ir::AliasTy { associated_ty_id: self.associated_ty.to_chalk(db), substitution: self.parameters.to_chalk(db), @@ -373,7 +373,7 @@ impl ToChalk for ProjectionTy { } fn from_chalk( - db: &impl HirDatabase, + db: &dyn HirDatabase, projection_ty: chalk_ir::AliasTy, ) -> ProjectionTy { ProjectionTy { @@ -386,11 +386,11 @@ impl ToChalk for ProjectionTy { impl ToChalk for super::ProjectionPredicate { type Chalk = chalk_ir::Normalize; - fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Normalize { + fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Normalize { chalk_ir::Normalize { alias: self.projection_ty.to_chalk(db), ty: self.ty.to_chalk(db) } } - fn from_chalk(_db: &impl HirDatabase, _normalize: chalk_ir::Normalize) -> Self { + fn from_chalk(_db: &dyn HirDatabase, _normalize: chalk_ir::Normalize) -> Self { unimplemented!() } } @@ -398,14 +398,14 @@ impl ToChalk for super::ProjectionPredicate { impl ToChalk for Obligation { type Chalk = chalk_ir::DomainGoal; - fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::DomainGoal { + fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::DomainGoal { match self { Obligation::Trait(tr) => tr.to_chalk(db).cast(), Obligation::Projection(pr) => pr.to_chalk(db).cast(), } } - fn from_chalk(_db: &impl HirDatabase, _goal: chalk_ir::DomainGoal) -> Self { + fn from_chalk(_db: &dyn HirDatabase, _goal: chalk_ir::DomainGoal) -> Self { unimplemented!() } } @@ -416,13 +416,13 @@ where { type Chalk = chalk_ir::Canonical; - fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Canonical { + fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Canonical { let parameter = chalk_ir::ParameterKind::Ty(chalk_ir::UniverseIndex::ROOT); let value = self.value.to_chalk(db); chalk_ir::Canonical { value, binders: vec![parameter; self.num_vars] } } - fn from_chalk(db: &impl HirDatabase, canonical: chalk_ir::Canonical) -> Canonical { + fn from_chalk(db: &dyn HirDatabase, canonical: chalk_ir::Canonical) -> Canonical { Canonical { num_vars: canonical.binders.len(), value: from_chalk(db, canonical.value) } } } @@ -430,7 +430,7 @@ where impl ToChalk for Arc { type Chalk = chalk_ir::Environment; - fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::Environment { + fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::Environment { let mut clauses = Vec::new(); for pred in &self.predicates { if pred.is_error() { @@ -445,7 +445,7 @@ impl ToChalk for Arc { } fn from_chalk( - _db: &impl HirDatabase, + _db: &dyn HirDatabase, _env: chalk_ir::Environment, ) -> Arc { unimplemented!() @@ -458,7 +458,7 @@ where { type Chalk = chalk_ir::InEnvironment; - fn to_chalk(self, db: &impl HirDatabase) -> chalk_ir::InEnvironment { + fn to_chalk(self, db: &dyn HirDatabase) -> chalk_ir::InEnvironment { chalk_ir::InEnvironment { environment: self.environment.to_chalk(db), goal: self.value.to_chalk(db), @@ -466,7 +466,7 @@ where } fn from_chalk( - db: &impl HirDatabase, + db: &dyn HirDatabase, in_env: chalk_ir::InEnvironment, ) -> super::InEnvironment { super::InEnvironment { @@ -479,7 +479,7 @@ where impl ToChalk for builtin::BuiltinImplData { type Chalk = ImplDatum; - fn to_chalk(self, db: &impl HirDatabase) -> ImplDatum { + fn to_chalk(self, db: &dyn HirDatabase) -> ImplDatum { let impl_type = chalk_rust_ir::ImplType::External; let where_clauses = self.where_clauses.into_iter().map(|w| w.to_chalk(db)).collect(); @@ -495,7 +495,7 @@ impl ToChalk for builtin::BuiltinImplData { } } - fn from_chalk(_db: &impl HirDatabase, _data: ImplDatum) -> Self { + fn from_chalk(_db: &dyn HirDatabase, _data: ImplDatum) -> Self { unimplemented!() } } @@ -503,7 +503,7 @@ impl ToChalk for builtin::BuiltinImplData { impl ToChalk for builtin::BuiltinImplAssocTyValueData { type Chalk = AssociatedTyValue; - fn to_chalk(self, db: &impl HirDatabase) -> AssociatedTyValue { + fn to_chalk(self, db: &dyn HirDatabase) -> AssociatedTyValue { let value_bound = chalk_rust_ir::AssociatedTyValueBound { ty: self.value.to_chalk(db) }; chalk_rust_ir::AssociatedTyValue { @@ -514,7 +514,7 @@ impl ToChalk for builtin::BuiltinImplAssocTyValueData { } fn from_chalk( - _db: &impl HirDatabase, + _db: &dyn HirDatabase, _data: AssociatedTyValue, ) -> builtin::BuiltinImplAssocTyValueData { unimplemented!() @@ -529,7 +529,7 @@ fn make_binders(value: T, num_vars: usize) -> chalk_ir::Binders { } fn convert_where_clauses( - db: &impl HirDatabase, + db: &dyn HirDatabase, def: GenericDefId, substs: &Substs, ) -> Vec> { @@ -545,10 +545,7 @@ fn convert_where_clauses( result } -impl<'a, DB> chalk_solve::RustIrDatabase for ChalkContext<'a, DB> -where - DB: HirDatabase, -{ +impl<'a> chalk_solve::RustIrDatabase for ChalkContext<'a> { fn associated_ty_data(&self, id: AssocTypeId) -> Arc { self.db.associated_ty_data(id) } @@ -618,16 +615,16 @@ where } pub(crate) fn associated_ty_data_query( - db: &impl HirDatabase, + db: &dyn HirDatabase, id: AssocTypeId, ) -> Arc { debug!("associated_ty_data {:?}", id); let type_alias: TypeAliasId = from_chalk(db, id); - let trait_ = match type_alias.lookup(db).container { + let trait_ = match type_alias.lookup(db.upcast()).container { AssocContainerId::TraitId(t) => t, _ => panic!("associated type not in trait"), }; - let generic_params = generics(db, type_alias.into()); + let generic_params = generics(db.upcast(), type_alias.into()); let bound_data = chalk_rust_ir::AssociatedTyDatumBound { // FIXME add bounds and where clauses bounds: vec![], @@ -643,7 +640,7 @@ pub(crate) fn associated_ty_data_query( } pub(crate) fn trait_datum_query( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, trait_id: TraitId, ) -> Arc { @@ -651,11 +648,11 @@ pub(crate) fn trait_datum_query( let trait_: hir_def::TraitId = from_chalk(db, trait_id); let trait_data = db.trait_data(trait_); debug!("trait {:?} = {:?}", trait_id, trait_data.name); - let generic_params = generics(db, trait_.into()); + let generic_params = generics(db.upcast(), trait_.into()); let bound_vars = Substs::bound_vars(&generic_params); let flags = chalk_rust_ir::TraitFlags { auto: trait_data.auto, - upstream: trait_.lookup(db).container.module(db).krate != krate, + upstream: trait_.lookup(db.upcast()).container.module(db.upcast()).krate != krate, non_enumerable: true, coinductive: false, // only relevant for Chalk testing // FIXME set these flags correctly @@ -676,7 +673,7 @@ pub(crate) fn trait_datum_query( } pub(crate) fn struct_datum_query( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, struct_id: StructId, ) -> Arc { @@ -688,7 +685,7 @@ pub(crate) fn struct_datum_query( let where_clauses = type_ctor .as_generic_def() .map(|generic_def| { - let generic_params = generics(db, generic_def); + let generic_params = generics(db.upcast(), generic_def); let bound_vars = Substs::bound_vars(&generic_params); convert_where_clauses(db, generic_def, &bound_vars) }) @@ -708,7 +705,7 @@ pub(crate) fn struct_datum_query( } pub(crate) fn impl_datum_query( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, impl_id: ImplId, ) -> Arc { @@ -722,7 +719,7 @@ pub(crate) fn impl_datum_query( } fn impl_def_datum( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, chalk_id: ImplId, impl_id: hir_def::ImplId, @@ -734,10 +731,10 @@ fn impl_def_datum( .value; let impl_data = db.impl_data(impl_id); - let generic_params = generics(db, impl_id.into()); + let generic_params = generics(db.upcast(), impl_id.into()); let bound_vars = Substs::bound_vars(&generic_params); let trait_ = trait_ref.trait_; - let impl_type = if impl_id.lookup(db).container.module(db).krate == krate { + let impl_type = if impl_id.lookup(db.upcast()).container.module(db.upcast()).krate == krate { chalk_rust_ir::ImplType::Local } else { chalk_rust_ir::ImplType::External @@ -786,7 +783,7 @@ fn impl_def_datum( } pub(crate) fn associated_ty_value_query( - db: &impl HirDatabase, + db: &dyn HirDatabase, krate: CrateId, id: AssociatedTyValueId, ) -> Arc { @@ -800,12 +797,12 @@ pub(crate) fn associated_ty_value_query( } fn type_alias_associated_ty_value( - db: &impl HirDatabase, + db: &dyn HirDatabase, _krate: CrateId, type_alias: TypeAliasId, ) -> Arc { let type_alias_data = db.type_alias_data(type_alias); - let impl_id = match type_alias.lookup(db).container { + let impl_id = match type_alias.lookup(db.upcast()).container { AssocContainerId::ImplId(it) => it, _ => panic!("assoc ty value should be in impl"), }; diff --git a/crates/ra_hir_ty/src/utils.rs b/crates/ra_hir_ty/src/utils.rs index 463fd65b4..b40d4eb73 100644 --- a/crates/ra_hir_ty/src/utils.rs +++ b/crates/ra_hir_ty/src/utils.rs @@ -14,7 +14,7 @@ use hir_def::{ }; use hir_expand::name::{name, Name}; -fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec { +fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec { let resolver = trait_.resolver(db); // returning the iterator directly doesn't easily work because of // lifetime problems, but since there usually shouldn't be more than a @@ -43,7 +43,7 @@ fn direct_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec { /// Returns an iterator over the whole super trait hierarchy (including the /// trait itself). -pub(super) fn all_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec { +pub(super) fn all_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec { // we need to take care a bit here to avoid infinite loops in case of cycles // (i.e. if we have `trait A: B; trait B: A;`) let mut result = vec![trait_]; @@ -65,7 +65,7 @@ pub(super) fn all_super_traits(db: &impl DefDatabase, trait_: TraitId) -> Vec Vec { @@ -73,7 +73,7 @@ pub(super) fn find_super_trait_path( result.push(trait_); return if go(db, super_trait, &mut result) { result } else { Vec::new() }; - fn go(db: &impl DefDatabase, super_trait: TraitId, path: &mut Vec) -> bool { + fn go(db: &dyn DefDatabase, super_trait: TraitId, path: &mut Vec) -> bool { let trait_ = *path.last().unwrap(); if trait_ == super_trait { return true; @@ -95,7 +95,7 @@ pub(super) fn find_super_trait_path( } pub(super) fn associated_type_by_name_including_super_traits( - db: &impl DefDatabase, + db: &dyn DefDatabase, trait_: TraitId, name: &Name, ) -> Option { @@ -104,7 +104,7 @@ pub(super) fn associated_type_by_name_including_super_traits( .find_map(|t| db.trait_data(t).associated_type_by_name(name)) } -pub(super) fn variant_data(db: &impl DefDatabase, var: VariantId) -> Arc { +pub(super) fn variant_data(db: &dyn DefDatabase, var: VariantId) -> Arc { match var { VariantId::StructId(it) => db.struct_data(it).variant_data.clone(), VariantId::UnionId(it) => db.union_data(it).variant_data.clone(), @@ -123,7 +123,7 @@ pub(crate) fn make_mut_slice(a: &mut Arc<[T]>) -> &mut [T] { Arc::get_mut(a).unwrap() } -pub(crate) fn generics(db: &impl DefDatabase, def: GenericDefId) -> Generics { +pub(crate) fn generics(db: &dyn DefDatabase, def: GenericDefId) -> Generics { let parent_generics = parent_generic_def(db, def).map(|def| Box::new(generics(db, def))); Generics { def, params: db.generic_params(def), parent_generics } } @@ -222,7 +222,7 @@ impl Generics { } } -fn parent_generic_def(db: &impl DefDatabase, def: GenericDefId) -> Option { +fn parent_generic_def(db: &dyn DefDatabase, def: GenericDefId) -> Option { let container = match def { GenericDefId::FunctionId(it) => it.lookup(db).container, GenericDefId::TypeAliasId(it) => it.lookup(db).container, -- cgit v1.2.3